This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (58 loc) · 2.34 KB
/
main.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
/*jslint vars: true, nomen: true, indent: 4*/
/*global define, brackets, console, $*/
define(function (require, exports, module) {
"use strict";
var _ = brackets.getModule('thirdparty/lodash'),
CodeInspection = brackets.getModule('language/CodeInspection'),
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
NodeDomain = brackets.getModule('utils/NodeDomain');
var PylintTypes = {
refactor: CodeInspection.Type.META,
convention: CodeInspection.Type.META,
error: CodeInspection.Type.ERROR,
fatal: CodeInspection.Type.ERROR,
warning: CodeInspection.Type.WARNING
};
var pylintDomain = new NodeDomain('bracketsPylint', ExtensionUtils.getModulePath(module, 'node/PylintDomain')),
runSettings = {
pylintPath: '/usr/local/bin/pylint', // TODO: Write a dynamic finding util
rcfilePath: '~/.pylintrc', // TODO: Support per-project rcfiles
filePath: null
};
function parseResult(data) {
console.log('Will parse data...', data);
/*jslint regexp: true*/
var lines = _.filter(data || [], function (line) {
return (/\b\d+:\d+:[a-z]+:.+$/).test(line);
});
/*jslint regexp: false*/
console.log('Filtered lines', lines);
var errors = _.map(lines || [], function (line) {
// pylint format = {line}:{column}:{category}:{msg}
var pieces = line.split(':');
return {
pos: {line: _.parseInt(pieces[0]), ch: _.parseInt(pieces[1])},
type: PylintTypes[pieces[2]],
message: pieces[3]
};
});
if (errors.length) {
return {errors: errors};
}
return null;
}
function handleLinterAsync(text, filePath) {
var deferred = $.Deferred(),
config = _.defaults({filePath: filePath}, runSettings);
pylintDomain.exec('run', config)
.done(function (pylintResult) {
deferred.resolve(parseResult(pylintResult));
});
return deferred.promise();
}
// Register a new async linter to `python` language
CodeInspection.register('python', {
name: 'Pylint',
scanFileAsync: handleLinterAsync
});
});