-
Notifications
You must be signed in to change notification settings - Fork 7
/
PyLint.js
80 lines (66 loc) · 2.71 KB
/
PyLint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* global define, brackets, $, window */
define(function (require, exports, module) {
"use strict";
var EXTENSION_NAME = require("constants").EXTENSION_NAME;
var Type = brackets.getModule("language/CodeInspection").Type,
getCurrentDocument = brackets.getModule("document/DocumentManager").getCurrentDocument,
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
preferences = PreferencesManager.getExtensionPrefs(EXTENSION_NAME);
var pythonDomain, flake8Available = true;
var WITH_GUTTERS = window.bracketsInspectionGutters;
if (!WITH_GUTTERS)
console.warn('No bracketsInspectionGutters found in window, gutters disabled.');
function _getErrorSeverity (errorCode) {
if (["E121", "E123", "E126", "E133", "E226", "E241",
"E303", "E242", "E501", "E704", "W293", "W503"].includes(errorCode))
return Type.META;
else if (/^(E(1|74|9)|F(6|7|8))/.test(errorCode))
return Type.ERROR;
else
return Type.WARNING;
}
function PyLint(pyDomain) {
pythonDomain = pyDomain;
}
PyLint.prototype.scanFileAsync = function(text, fullPath) {
if ((!flake8Available) || getCurrentDocument().isDirty) {
// flake8 cannot deal with unsaved files. Abort checks if file is unsaved
return {
aborted: true
};
}
var result = new $.Deferred();
pythonDomain.exec("Flake8",
preferences.get("pathToPython"),
fullPath,
preferences.get("maxLineLength"),
preferences.get("ignoredErrors"))
.done(function (data) {
var report = {
errors: data.map(function(error) {
return {
pos: {
line: error.row - 1,
ch: error.column - 1
},
message: error.code +': ' + error.text,
type: _getErrorSeverity(error.code)
}
}),
aborted: false
}
if (WITH_GUTTERS) {
window.bracketsInspectionGutters.set(
'bazitur.python-tools', fullPath, report, true
);
}
result.resolve(report);
})
.fail(function (error) {
flake8Available = false;
result.reject(error);
});
return result.promise();
};
module.exports = PyLint;
});