Skip to content

Commit

Permalink
Merge pull request #176 from Turbo87/group-option
Browse files Browse the repository at this point in the history
Use new "group" option of "broccoli-lint-eslint" by default
  • Loading branch information
Turbo87 committed May 1, 2017
2 parents 433791a + 4abd4c1 commit 41962c4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 72 deletions.
12 changes: 9 additions & 3 deletions ember-cli-build.js
Expand Up @@ -6,9 +6,15 @@ var path = require('path');
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function (defaults) {
var app = new EmberAddon(defaults, {
// Add options here
});
let options = {
eslint: {},
};

if (process.env['NO_GROUPING']) {
options.eslint.group = false;
}

var app = new EmberAddon(defaults, options);

// Use `app.import` to add additional libraries to the generated
// output files.
Expand Down
61 changes: 17 additions & 44 deletions index.js
Expand Up @@ -14,56 +14,36 @@ 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;
var ESLint = require('broccoli-lint-eslint');

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

return project.generateTestFile('ESLint - ' + relativePath, [{
name: 'should pass ESLint',
passed: passed,
errorMessage: relativePath + ' should pass ESLint.' + messages
}]);
},
return ESLint.create(tree, {
testGenerator: this.options.testGenerator || this._testGenerator,
group: (this.options.group !== false) ? type : undefined,

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

function render(errors) {
return errors.map(function(error) {
return error.line + ':' + error.column + ' ' +
' - ' + error.message + ' (' + error.ruleId +')';
}).join('\n');
}
96 changes: 73 additions & 23 deletions node-tests/test.js
Expand Up @@ -14,47 +14,97 @@ describe('ember-cli-eslint', function() {
});

it('passes if ESLint tests pass', function() {
process.env['NO_GROUPING'] = true;

return emberTest().then(function(result) {
expect(result.error).to.not.exist;
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 1 PhantomJS 2.1 - ESLint - app.js: should pass ESLint')
.to.contain('ok 2 PhantomJS 2.1 - ESLint - controllers/thing.js: should pass ESLint')
.to.contain('ok 3 PhantomJS 2.1 - ESLint - helpers/destroy-app.js: should pass ESLint')
.to.contain('ok 4 PhantomJS 2.1 - ESLint - helpers/module-for-acceptance.js: should pass ESLint')
.to.contain('ok 5 PhantomJS 2.1 - ESLint - helpers/resolver.js: should pass ESLint')
.to.contain('ok 6 PhantomJS 2.1 - ESLint - helpers/start-app.js: should pass ESLint')
.to.contain('ok 7 PhantomJS 2.1 - ESLint - models/thing.js: should pass ESLint')
.to.contain('ok 8 PhantomJS 2.1 - ESLint - resolver.js: should pass ESLint')
.to.contain('ok 9 PhantomJS 2.1 - ESLint - router.js: should pass ESLint')
.to.contain('ok 10 PhantomJS 2.1 - ESLint - test-helper.js: should pass ESLint')
.to.not.contain('not ok 11 PhantomJS 2.1 - ESLint - unused.js: should pass ESLint');
.to.contain('ok 1 PhantomJS 2.1 - ESLint | app.js: should pass ESLint')
.to.contain('ok 2 PhantomJS 2.1 - ESLint | controllers/thing.js: should pass ESLint')
.to.contain('ok 3 PhantomJS 2.1 - ESLint | helpers/destroy-app.js: should pass ESLint')
.to.contain('ok 4 PhantomJS 2.1 - ESLint | helpers/module-for-acceptance.js: should pass ESLint')
.to.contain('ok 5 PhantomJS 2.1 - ESLint | helpers/resolver.js: should pass ESLint')
.to.contain('ok 6 PhantomJS 2.1 - ESLint | helpers/start-app.js: should pass ESLint')
.to.contain('ok 7 PhantomJS 2.1 - ESLint | models/thing.js: should pass ESLint')
.to.contain('ok 8 PhantomJS 2.1 - ESLint | resolver.js: should pass ESLint')
.to.contain('ok 9 PhantomJS 2.1 - ESLint | router.js: should pass ESLint')
.to.contain('ok 10 PhantomJS 2.1 - ESLint | test-helper.js: should pass ESLint')
.to.not.contain('not ok 11 PhantomJS 2.1 - ESLint | unused.js: should pass ESLint');
})
});

it('fails if a ESLint tests fails', function() {
process.env['NO_GROUPING'] = true;

fs.outputFileSync(FAILING_FILE, 'let unused = 6;\n');

return emberTest({ NO_GROUPING: true }).then(function(result) {
expect(result.error).to.exist;
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 1 PhantomJS 2.1 - ESLint | app.js: should pass ESLint')
.to.contain('ok 2 PhantomJS 2.1 - ESLint | controllers/thing.js: should pass ESLint')
.to.contain('ok 3 PhantomJS 2.1 - ESLint | helpers/destroy-app.js: should pass ESLint')
.to.contain('ok 4 PhantomJS 2.1 - ESLint | helpers/module-for-acceptance.js: should pass ESLint')
.to.contain('ok 5 PhantomJS 2.1 - ESLint | helpers/resolver.js: should pass ESLint')
.to.contain('ok 6 PhantomJS 2.1 - ESLint | helpers/start-app.js: should pass ESLint')
.to.contain('ok 7 PhantomJS 2.1 - ESLint | models/thing.js: should pass ESLint')
.to.contain('ok 8 PhantomJS 2.1 - ESLint | resolver.js: should pass ESLint')
.to.contain('ok 9 PhantomJS 2.1 - ESLint | router.js: should pass ESLint')
.to.contain('ok 10 PhantomJS 2.1 - ESLint | test-helper.js: should pass ESLint')
.to.contain('not ok 11 PhantomJS 2.1 - ESLint | unused.js: should pass ESLint');
})
});

it('passes if ESLint tests pass (grouped)', function() {
delete process.env['NO_GROUPING'];

return emberTest().then(function(result) {
expect(result.error).to.not.exist;
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 1 PhantomJS 2.1 - ESLint | app: app.js')
.to.contain('ok 2 PhantomJS 2.1 - ESLint | app: controllers/thing.js')
.to.contain('ok 3 PhantomJS 2.1 - ESLint | app: models/thing.js')
.to.contain('ok 4 PhantomJS 2.1 - ESLint | app: resolver.js')
.to.contain('ok 5 PhantomJS 2.1 - ESLint | app: router.js')
.to.not.contain('not ok 6 PhantomJS 2.1 - ESLint | app: unused.js');

expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 6 PhantomJS 2.1 - ESLint | tests: helpers/destroy-app.js')
.to.contain('ok 7 PhantomJS 2.1 - ESLint | tests: helpers/module-for-acceptance.js')
.to.contain('ok 8 PhantomJS 2.1 - ESLint | tests: helpers/resolver.js')
.to.contain('ok 9 PhantomJS 2.1 - ESLint | tests: helpers/start-app.js')
.to.contain('ok 10 PhantomJS 2.1 - ESLint | tests: test-helper.js');
})
});

it('fails if a ESLint tests fails (grouped)', function() {
delete process.env['NO_GROUPING'];

fs.outputFileSync(FAILING_FILE, 'let unused = 6;\n');

return emberTest().then(function(result) {
expect(result.error).to.exist;
expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 1 PhantomJS 2.1 - ESLint - app.js: should pass ESLint')
.to.contain('ok 2 PhantomJS 2.1 - ESLint - controllers/thing.js: should pass ESLint')
.to.contain('ok 3 PhantomJS 2.1 - ESLint - helpers/destroy-app.js: should pass ESLint')
.to.contain('ok 4 PhantomJS 2.1 - ESLint - helpers/module-for-acceptance.js: should pass ESLint')
.to.contain('ok 5 PhantomJS 2.1 - ESLint - helpers/resolver.js: should pass ESLint')
.to.contain('ok 6 PhantomJS 2.1 - ESLint - helpers/start-app.js: should pass ESLint')
.to.contain('ok 7 PhantomJS 2.1 - ESLint - models/thing.js: should pass ESLint')
.to.contain('ok 8 PhantomJS 2.1 - ESLint - resolver.js: should pass ESLint')
.to.contain('ok 9 PhantomJS 2.1 - ESLint - router.js: should pass ESLint')
.to.contain('ok 10 PhantomJS 2.1 - ESLint - test-helper.js: should pass ESLint')
.to.contain('not ok 11 PhantomJS 2.1 - ESLint - unused.js: should pass ESLint');
.to.contain('ok 1 PhantomJS 2.1 - ESLint | app: app.js')
.to.contain('ok 2 PhantomJS 2.1 - ESLint | app: controllers/thing.js')
.to.contain('ok 3 PhantomJS 2.1 - ESLint | app: models/thing.js')
.to.contain('ok 4 PhantomJS 2.1 - ESLint | app: resolver.js')
.to.contain('ok 5 PhantomJS 2.1 - ESLint | app: router.js')
.to.contain('not ok 6 PhantomJS 2.1 - ESLint | app: unused.js');

expect(result.stdout.match(/[^\r\n]+/g))
.to.contain('ok 7 PhantomJS 2.1 - ESLint | tests: helpers/destroy-app.js')
.to.contain('ok 8 PhantomJS 2.1 - ESLint | tests: helpers/module-for-acceptance.js')
.to.contain('ok 9 PhantomJS 2.1 - ESLint | tests: helpers/resolver.js')
.to.contain('ok 10 PhantomJS 2.1 - ESLint | tests: helpers/start-app.js')
.to.contain('ok 11 PhantomJS 2.1 - ESLint | tests: test-helper.js');
})
});
});

function emberTest() {
return new Promise(function(resolve) {
exec('node_modules/.bin/ember test', { cwd: __dirname + '/..' }, function (error, stdout, stderr) {
exec('node_modules/.bin/ember test', { cwd: __dirname + '/..', env: process.env }, function (error, stdout, stderr) {
resolve({
error: error,
stdout: stdout,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -35,8 +35,8 @@
"test": "mocha node-tests --recursive"
},
"dependencies": {
"broccoli-lint-eslint": "^3.1.0",
"js-string-escape": "^1.0.0",
"broccoli-lint-eslint": "^3.3.0",
"ember-cli-version-checker": "^1.3.1",
"rsvp": "^3.2.1",
"walk-sync": "^0.3.0"
},
Expand Down

0 comments on commit 41962c4

Please sign in to comment.