Skip to content

Commit

Permalink
Use project.generateTestFile() if available
Browse files Browse the repository at this point in the history
project.generateTestFile() is set by the test framework addon and will automatically generate the right kind of tests for qunit/mocha
  • Loading branch information
Turbo87 committed Feb 26, 2016
1 parent 2b5c5c5 commit 87761c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var eslint = require('broccoli-lint-eslint');
var jsStringEscape = require('js-string-escape');

module.exports = {
name: 'ember-cli-eslint',
Expand All @@ -15,16 +16,37 @@ module.exports = {
},

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

return eslint(tree, {
testGenerator: this.options.testGenerator || generateEmptyTest
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
}]);
}
});
}
};

// 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.
function generateEmptyTest() {
return '';
function render(errors) {
return errors.map(function(error) {
return error.line + ':' + error.column + ' ' +
' - ' + error.message + ' (' + error.ruleId +')';
}).join('\n');
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"ember-try": "0.0.8",
"eslint-config-ember": "^0.1.1",
"express": "^4.12.3",
"js-string-escape": "^1.0.0",
"phantomjs": "^1.9.16"
},
"keywords": [
Expand All @@ -60,6 +59,7 @@
"defaultBlueprint": "ember-cli-eslint"
},
"dependencies": {
"broccoli-lint-eslint": "^1.1.1"
"broccoli-lint-eslint": "^1.1.1",
"js-string-escape": "^1.0.0"
}
}

0 comments on commit 87761c7

Please sign in to comment.