-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (56 loc) · 1.86 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
/*global $, brackets, define*/
define(function (require, exports, module) {
'use strict';
// imports
var CodeInspection = brackets.getModule('language/CodeInspection');
var ProjectManager = brackets.getModule('project/ProjectManager');
var ExtensionUtils = brackets.getModule('utils/ExtensionUtils');
var NodeDomain = brackets.getModule('utils/NodeDomain');
// constants
var LINTER_NAME = 'CoffeeLint';
var nodeDomain = new NodeDomain('zaggino.brackets-coffeelint', ExtensionUtils.getModulePath(module, 'domain'));
// this will map ESLint output to match format expected by Brackets
function remapResults(results) {
return {
errors: results.map(function (result) {
var message = result.message;
if (result.context) {
message += ' (' + result.context + ')';
}
if (result.name) {
message += ' [' + result.name + ']';
}
return {
message: message,
pos: {
line: result.lineNumber - 1,
ch: result.column
},
type: result.rule
};
})
};
}
function handleLintSync(text, fullPath) {
throw new Error(LINTER_NAME + ' sync is not available, use async for ' + fullPath);
}
function handleLintAsync(text, fullPath) {
var deferred = new $.Deferred();
var projectRoot = ProjectManager.getProjectRoot().fullPath;
nodeDomain.exec('lintFile', fullPath, projectRoot)
.then(function (results) {
deferred.resolve(remapResults(results));
}, function (err) {
deferred.reject(err);
});
return deferred.promise();
}
// register a linter with CodeInspection
['coffeescript', 'coffeescriptimproved'].forEach(function (langId) {
CodeInspection.register(langId, {
name: LINTER_NAME,
scanFile: handleLintSync,
scanFileAsync: handleLintAsync
});
});
});