Skip to content

Commit

Permalink
Use built-in "broccoli-lint-eslint" test generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed May 1, 2017
1 parent 88469ed commit 61fdfbc
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions index.js
Expand Up @@ -14,56 +14,35 @@ module.exports = {
// disable their lintTree implementations (which use JSHint)
isDefaultJSLinter: true,

init() {
this._super.init && this._super.init.apply(this, arguments);

var VersionChecker = require('ember-cli-version-checker');
var checker = new VersionChecker(this);

if (checker.for('ember-cli-qunit', 'npm').satisfies('*')) {
this._testGenerator = 'qunit';
} else if (checker.for('ember-cli-mocha', 'npm').satisfies('*')) {
this._testGenerator = 'mocha';
}
},

included: function (app) {
this._super.included.apply(this, arguments);
this.options = app.options.eslint || {};
},

lintTree: function(type, tree) {
var project = this.project;
var ui = this.ui;

if (type === 'templates') {
return undefined;
}

var eslint = require('broccoli-lint-eslint');
var jsStringEscape = require('js-string-escape');

return eslint(tree, {
testGenerator: this.options.testGenerator || function(relativePath, errors, results) {
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, messages;
if (results) {
passed = !results.errorCount || results.errorCount.length === 0;

messages = '';
if (results.messages) {
messages = jsStringEscape('\n' + render(results.messages));
}
} else {
// backwards compat support for broccoli-lint-eslint versions
// 2.3.0 and older...
passed = !errors || errors.length === 0;

if (errors) {
messages = jsStringEscape('\n' + render(errors));
}
}

return project.generateTestFile('ESLint - ' + relativePath, [{
name: 'should pass ESLint',
passed: passed,
errorMessage: relativePath + ' should pass ESLint.' + messages
}]);
},
testGenerator: this.options.testGenerator || this._testGenerator,

console: {
log: function(message) {
Expand All @@ -77,10 +56,3 @@ module.exports = {
});
}
};

function render(errors) {
return errors.map(function(error) {
return error.line + ':' + error.column + ' ' +
' - ' + error.message + ' (' + error.ruleId +')';
}).join('\n');
}

0 comments on commit 61fdfbc

Please sign in to comment.