forked from ember-cli/ember-cli-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (43 loc) · 1.53 KB
/
index.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
'use strict';
var eslint = require('broccoli-lint-eslint');
var jsStringEscape = require('js-string-escape');
module.exports = {
name: 'ember-cli-eslint',
// instructs ember-cli-qunit and ember-cli-mocha to
// disable their lintTree implementations (which use JSHint)
isDefaultJSLinter: true,
included: function (app) {
this._super.included.apply(this, arguments);
this.jshintrc = app.options.jshintrc;
this.options = app.options.eslint || {};
},
lintTree: function(type, tree) {
var project = this.project;
return eslint(tree, {
testGenerator: this.options.testGenerator || function(relativePath, errors) {
if (!project.generateTestFile) {
// Empty test generator. The reason we do that is that `lintTree`
// will merge the returned tree with the `tests` directory anyway,
// so we minimize the damage by returning empty files instead of
// duplicating app tree.
return '';
}
var passed = !errors || errors.length === 0;
if (errors) {
errors = jsStringEscape('\n' + render(errors));
}
return project.generateTestFile('ESLint - ' + relativePath, [{
name: 'should pass ESLint',
passed: passed,
errorMessage: relativePath + ' should pass ESLint.' + errors
}]);
}
});
}
};
function render(errors) {
return errors.map(function(error) {
return error.line + ':' + error.column + ' ' +
' - ' + error.message + ' (' + error.ruleId +')';
}).join('\n');
}