-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
47 lines (39 loc) · 1.5 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
/*global define, $, brackets */
define(function (require, exports, module) {
'use strict'
console.log('Live!')
var CodeInspection = brackets.getModule('language/CodeInspection')
var LanguageManager = brackets.getModule('language/LanguageManager')
var NodeDomain = brackets.getModule('utils/NodeDomain')
var ExtensionUtils = brackets.getModule('utils/ExtensionUtils')
var ProjectManager = brackets.getModule('project/ProjectManager')
var semverGte = require('semver').gte
var JS_LANGUAGE = LanguageManager.getLanguageForExtension('js')
var standardDomain = new NodeDomain('brackets-standard', ExtensionUtils.getModulePath(module, 'domain'))
function scanFileAsync (textContent) {
var d = $.Deferred()
standardDomain.exec('lintText', [ProjectManager.getProjectRoot().fullPath, textContent])
.done(function (result) {
d.resolve({
errors: result.results[0].messages.map(function (msg) {
return {
pos: {
line: msg.line - 1,
ch: msg.column + (semverGte(result.version, '5.0.0') ? -1 : 0)
},
message: msg.message,
type: msg.severity === 1 ? CodeInspection.Type.WARNING
: CodeInspection.Type.ERROR
}
})})
})
.fail(function (error) {
d.reject(error.message)
})
return d.promise()
}
CodeInspection.register(JS_LANGUAGE.getId(), {
name: 'standard',
scanFileAsync: scanFileAsync
})
})