-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.js
87 lines (76 loc) · 2.28 KB
/
domain.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
81
82
83
84
85
86
87
/*eslint no-process-env:0, new-cap:0*/
/*global require, exports*/
(function () {
'use strict';
var fs = require('fs');
var CoffeeScript = require('coffee-script');
var CoffeeLint = require('coffeelint/lib/coffeelint');
var Configfinder = require('coffeelint/lib/configfinder');
var currentConfig;
var currentProjectRoot;
var domainName = 'zaggino.brackets-coffeelint';
var domainManager = null;
var noop = function () {};
function _setProjectRoot(projectRoot) {
// set it to empty in case reading coffeelint.json fails
currentConfig = null;
// read coffeelint.json from current project
if (!projectRoot) { return; }
var configFilePath = projectRoot + 'coffeelint.json';
try {
if (fs.statSync(configFilePath).isFile()) {
currentConfig = JSON.parse(fs.readFileSync(configFilePath, {encoding: 'utf-8'}));
}
} catch (e) {
// no action required
noop(e);
}
}
require('enable-global-packages').on('ready', function () {
// global packages are available now
_setProjectRoot(currentProjectRoot);
});
function lintFile(fullPath, projectRoot) {
if (projectRoot !== currentProjectRoot) {
_setProjectRoot(projectRoot);
currentProjectRoot = projectRoot;
}
var errorReport = new CoffeeLint.getErrorReport();
var source = fs.readFileSync(fullPath, {encoding: 'utf-8'});
var config = currentConfig || Configfinder.getConfig(fullPath);
var literate = CoffeeScript.helpers.isLiterate(fullPath);
errorReport.lint(fullPath, source, config, literate);
return errorReport.getErrors(fullPath);
}
exports.init = function (_domainManager) {
domainManager = _domainManager;
if (!domainManager.hasDomain(domainName)) {
domainManager.registerDomain(domainName, {
major: 0,
minor: 1
});
}
domainManager.registerCommand(
domainName,
'lintFile', // command name
lintFile, // handler function
false, // is not async
'lint given file with eslint', // description
[
{
name: 'fullPath',
type: 'string'
},
{
name: 'projectRoot',
type: 'string'
}
], [
{
name: 'report',
type: 'object'
}
]
);
};
}());