Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit bff6736

Browse files
authored
Merge pull request #272 from rwjblue/update-deps
Updatez!
2 parents 1ee47f0 + f5fbd83 commit bff6736

4 files changed

Lines changed: 694 additions & 814 deletions

File tree

broccoli-template-linter.js

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const projectLocalizationAddon = require('./lib/utils/project-localization-frame
1212
const testGenerators = require('aot-test-generators');
1313
const testGeneratorNames = Object.keys(testGenerators);
1414
const concat = require('broccoli-concat');
15+
const stripAnsi = require('strip-ansi');
1516

1617
function TemplateLinter(inputNode, _options) {
1718
if (!(this instanceof TemplateLinter)) { return new TemplateLinter(inputNode, _options); }
@@ -81,22 +82,6 @@ TemplateLinter.prototype.build = function () {
8182
});
8283
};
8384

84-
TemplateLinter.prototype.convertErrorToDisplayMessage = function(error) {
85-
let message = error.rule + ': ' + error.message + ' (' + error.moduleId;
86-
87-
if (error.line && error.column) {
88-
message = message + ' @ L' + error.line + ':C' + error.column;
89-
}
90-
91-
message = message + ')';
92-
93-
if (error.source) {
94-
message = message + ': \n`' + error.source + '`';
95-
}
96-
97-
return message;
98-
};
99-
10085
TemplateLinter.prototype.processString = function(contents, relativePath) {
10186
let errors = this.linter.verify({
10287
source: contents,
@@ -105,43 +90,38 @@ TemplateLinter.prototype.processString = function(contents, relativePath) {
10590
errors = errors.filter(function(error) {
10691
return error.severity > 1;
10792
});
93+
10894
let passed = errors.length === 0;
109-
let errorDisplay = errors.map(function(error) {
110-
return this.convertErrorToDisplayMessage(error);
111-
}, this)
112-
.join('\n');
95+
let consoleOutput = Linter.errorsToMessages(relativePath, errors);
96+
let testOutput = stripAnsi(consoleOutput);
11397

11498
let output = '';
11599
if (this._testGenerator) {
116100
if (this.options.groupName) {
117101
output = this._testGenerator.test(relativePath, passed,
118-
`${relativePath} should pass TemplateLint.\n\n${errorDisplay}`);
102+
`${relativePath} should pass TemplateLint.\n\n${testOutput}`);
119103

120104
} else {
121105
output = [
122106
this._testGenerator.suiteHeader(`TemplateLint | ${relativePath}`),
123107
this._testGenerator.test('should pass TemplateLint', passed,
124-
`${relativePath} should pass TemplateLint.\n\n${errorDisplay}`),
108+
`${relativePath} should pass TemplateLint.\n\n${testOutput}`),
125109
this._testGenerator.suiteFooter()
126110
].join('');
127111
}
128112
}
129113

130-
debug('Found %s errors for %s with \ncontents: \n%s\nerrors: \n%s', errors.length, relativePath, contents, errorDisplay);
114+
debug('Found %s errors for %s with \ncontents: \n%s\nerrors: \n%s', errors.length, relativePath, contents, consoleOutput);
131115

132116
return {
133-
errors: errors,
134-
output: output
117+
errors,
118+
consoleOutput,
119+
output
135120
};
136121
};
137122

138123
TemplateLinter.prototype.postProcess = function(results) {
139-
let errors = results.errors;
140-
141-
for (let i = 0; i < errors.length; i++) {
142-
let errorDisplay = this.convertErrorToDisplayMessage(errors[i]);
143-
this._errors.push(chalk.red(errorDisplay));
144-
}
124+
this._errors.push(results.consoleOutput);
145125

146126
return results;
147127
};

node-tests/acceptance/broccoli-test.js

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,7 @@ describe('broccoli-template-linter', function() {
5050
expect(result.templates).to.have.property('application.template.lint-test.js');
5151

5252
let contents = result.templates['application.template.lint-test.js'];
53-
expect(contents).to.equal([
54-
'QUnit.module(\'TemplateLint | templates/application.hbs\');',
55-
'QUnit.test(\'should pass TemplateLint\', function(assert) {',
56-
' assert.expect(1);',
57-
(
58-
' assert.ok(false, \'templates/application.hbs should pass TemplateLint.\\n\\n' +
59-
'block-indentation: Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. (templates/application @ L5:C9): \\n' +
60-
'`<div>\\n <p>\\n </p>\\n </div>`\\n' +
61-
'block-indentation: Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. (templates/application @ L4:C5): \\n' +
62-
'`<p>\\n </p>`\\n' +
63-
'html-comments: HTML comment detected (templates/application): \\n' +
64-
'`<!-- silly html comments -->`\');'
65-
),
66-
'});\n'
67-
].join('\n'));
53+
expect(contents).to.equal("QUnit.module('TemplateLint | templates/application.hbs');\nQUnit.test('should pass TemplateLint', function(assert) {\n assert.expect(1);\n assert.ok(false, 'templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n -:- error HTML comment detected html-comments\\n');\n});\n");
6854
}));
6955

7056
it('generates a Mocha test file if "testGenerator: mocha" is provided', co.wrap(function *() {
@@ -83,24 +69,7 @@ describe('broccoli-template-linter', function() {
8369
expect(result.templates).to.have.property('application.template.lint-test.js');
8470

8571
let contents = result.templates['application.template.lint-test.js'];
86-
expect(contents).to.equal([
87-
'describe(\'TemplateLint | templates/application.hbs\', function() {',
88-
' it(\'should pass TemplateLint\', function() {',
89-
' // test failed',
90-
(
91-
' var error = new chai.AssertionError(\'templates/application.hbs should pass TemplateLint.\\n\\n' +
92-
'block-indentation: Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. (templates/application @ L5:C9): \\n' +
93-
'`<div>\\n <p>\\n </p>\\n </div>`\\n' +
94-
'block-indentation: Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. (templates/application @ L4:C5): \\n' +
95-
'`<p>\\n </p>`\\n' +
96-
'html-comments: HTML comment detected (templates/application): \\n' +
97-
'`<!-- silly html comments -->`\');'
98-
),
99-
' error.stack = undefined;',
100-
' throw error;',
101-
' });',
102-
'});\n'
103-
].join('\n'));
72+
expect(contents).to.equal("describe('TemplateLint | templates/application.hbs', function() {\n it('should pass TemplateLint', function() {\n // test failed\n var error = new chai.AssertionError('templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n -:- error HTML comment detected html-comments\\n');\n error.stack = undefined;\n throw error;\n });\n});\n");
10473
}));
10574

10675
it('generates a QUnit test file if "testGenerator: qunit" and "groupName: foo" are provided', co.wrap(function *() {
@@ -121,22 +90,7 @@ describe('broccoli-template-linter', function() {
12190
expect(result).to.have.property('foo.template.lint-test.js');
12291

12392
let contents = result['foo.template.lint-test.js'];
124-
expect(contents.trim()).to.equal([
125-
'QUnit.module(\'TemplateLint | foo\');',
126-
'',
127-
'QUnit.test(\'templates/application.hbs\', function(assert) {',
128-
' assert.expect(1);',
129-
(
130-
' assert.ok(false, \'templates/application.hbs should pass TemplateLint.\\n\\n' +
131-
'block-indentation: Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. (templates/application @ L5:C9): \\n' +
132-
'`<div>\\n <p>\\n </p>\\n </div>`\\n' +
133-
'block-indentation: Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. (templates/application @ L4:C5): \\n' +
134-
'`<p>\\n </p>`\\n' +
135-
'html-comments: HTML comment detected (templates/application): \\n' +
136-
'`<!-- silly html comments -->`\');'
137-
),
138-
'});'
139-
].join('\n'));
93+
expect(contents.trim()).to.equal("QUnit.module('TemplateLint | foo');\n\nQUnit.test('templates/application.hbs', function(assert) {\n assert.expect(1);\n assert.ok(false, 'templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n -:- error HTML comment detected html-comments\\n');\n});");
14094
}));
14195

14296
it('generates a Mocha test file if "testGenerator: mocha" and "groupName: foo" are provided', co.wrap(function *() {
@@ -155,26 +109,7 @@ describe('broccoli-template-linter', function() {
155109
expect(result).to.have.property('foo.template.lint-test.js');
156110

157111
let contents = result['foo.template.lint-test.js'];
158-
expect(contents.trim()).to.equal([
159-
'describe(\'TemplateLint | foo\', function() {',
160-
'',
161-
' it(\'templates/application.hbs\', function() {',
162-
' // test failed',
163-
(
164-
' var error = new chai.AssertionError(\'templates/application.hbs should pass TemplateLint.\\n\\n' +
165-
'block-indentation: Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. (templates/application @ L5:C9): \\n' +
166-
'`<div>\\n <p>\\n </p>\\n </div>`\\n' +
167-
'block-indentation: Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. (templates/application @ L4:C5): \\n' +
168-
'`<p>\\n </p>`\\n' +
169-
'html-comments: HTML comment detected (templates/application): \\n' +
170-
'`<!-- silly html comments -->`\');'
171-
),
172-
' error.stack = undefined;',
173-
' throw error;',
174-
' });',
175-
'',
176-
'});'
177-
].join('\n'));
112+
expect(contents.trim()).to.equal("describe('TemplateLint | foo', function() {\n\n it('templates/application.hbs', function() {\n // test failed\n var error = new chai.AssertionError('templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n -:- error HTML comment detected html-comments\\n');\n error.stack = undefined;\n throw error;\n });\n\n});");
178113
}));
179114

180115
it('generates empty test files if no "generateTestFile" option is provided', co.wrap(function *() {

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@
3030
"aot-test-generators": "^0.1.0",
3131
"broccoli-concat": "^3.2.2",
3232
"broccoli-persistent-filter": "^1.2.0",
33-
"chalk": "^1.1.1",
33+
"chalk": "^2.0.1",
3434
"debug": "^2.6.8",
3535
"ember-cli-version-checker": "^2.0.0",
36-
"ember-template-lint": "^0.7.2",
36+
"ember-template-lint": "^0.8.0",
3737
"json-stable-stringify": "^1.0.1",
3838
"md5-hex": "^2.0.0",
39+
"strip-ansi": "^4.0.0",
3940
"walk-sync": "^0.3.2"
4041
},
4142
"devDependencies": {
4243
"broccoli-asset-rev": "^2.4.2",
4344
"broccoli-test-helper": "^1.1.0",
4445
"chai": "^4.0.0",
46+
"chai-as-promised": "^7.1.1",
4547
"co": "^4.6.0",
46-
"ember-cli": "2.13.2",
48+
"ember-cli": "2.14.1",
4749
"ember-cli-babel": "^6.4.1",
4850
"ember-cli-blueprint-test-helpers": "^0.17.2",
4951
"ember-cli-dependency-checker": "^2.0.0",
@@ -56,7 +58,7 @@
5658
"ember-resolver": "^4.1.0",
5759
"loader.js": "^4.5.0",
5860
"mocha": "^3.4.2",
59-
"mocha-eslint": "^3.0.1",
61+
"mocha-eslint": "^4.1.0",
6062
"mocha-only-detector": "^0.1.0"
6163
},
6264
"engines": {

0 commit comments

Comments
 (0)