Skip to content

Commit 759e6c1

Browse files
iblack10JaKXz
authored andcommitted
fix: warnings not being logged to console (#26)
* Fixed warnings not being logged to console Warnings were not being logged unless there was an error in the css linting. * Corrected number of warnings returned
1 parent 5ea295d commit 759e6c1

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

lib/run-compilation.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ var linter = require('./linter');
1212
*/
1313
module.exports = function runCompilation(options, compilation, done) {
1414
var errors = [];
15+
var warnings = [];
1516

1617
linter(options)
1718
.then(function (lint) {
18-
if (lint.errored) {
19-
errors = lint.results
20-
.filter(function (f) {
21-
return f.errored;
22-
})
23-
.map(function (f) {
24-
return f.source; // send error instead
25-
});
26-
27-
if (!options.quiet) {
28-
console.log(chalk.yellow(options.formatter(lint.results)));
29-
}
19+
warnings = lint.results
20+
.filter(function (f) {
21+
return f.warnings && f.warnings.length;
22+
});
23+
errors = lint.results
24+
.filter(function (f) {
25+
return f.errored;
26+
}).map(function (f) {
27+
return f.source; // send error instead
28+
});
29+
if (!options.quiet) {
30+
console.log(chalk.yellow(options.formatter(lint.results)));
3031
}
3132

3233
if (options.failOnError && errors.length) {
@@ -46,8 +47,7 @@ module.exports = function runCompilation(options, compilation, done) {
4647

4748
// eslint-disable-next-line no-unused-expressions
4849
compilation.plugin && compilation.plugin('compilation', function (compilation) {
49-
errors.forEach(function (err) {
50-
compilation.errors.push(err);
51-
});
50+
compilation.errors = compilation.errors.concat(errors);
51+
compilation.warnings = compilation.warnings.concat(warnings);
5252
});
5353
};

test/.stylelintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"block-opening-brace-newline-after": "always-multi-line",
1212
"block-opening-brace-space-after": "always-single-line",
1313
"block-opening-brace-space-before": "always",
14-
"color-hex-case": "lower",
14+
"color-hex-case": [ "lower", { "severity": "warning" }
15+
],
1516
"color-hex-length": "short",
1617
"color-no-invalid-hex": true,
1718
"comment-empty-line-before": [ "always", {

test/fixtures/test7/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss');
22

3-
console.log('test6');
3+
console.log('test7');

test/fixtures/test8/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss');
2+
3+
console.log('test8');

test/fixtures/test8/test.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: #FFF;
3+
}

test/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe('stylelint-webpack-plugin', function () {
2929
return pack(assign({}, baseConfig, config))
3030
.then(function (stats) {
3131
expect(stats.compilation.errors).to.have.length(0);
32-
expect(stats.compilation.warnings).to.have.length(0);
3332
});
3433
});
3534

@@ -73,4 +72,22 @@ describe('stylelint-webpack-plugin', function () {
7372
expect(stats.compilation.errors).to.have.length(2);
7473
});
7574
});
75+
76+
it('sends warnings properly', function () {
77+
var config = {
78+
context: './test/fixtures/test8',
79+
entry: './index',
80+
plugins: [
81+
new StyleLintPlugin({
82+
quiet: true,
83+
configFile: configFilePath
84+
})
85+
]
86+
};
87+
88+
return pack(assign({}, baseConfig, config))
89+
.then(function (stats) {
90+
expect(stats.compilation.warnings).to.have.length(1);
91+
});
92+
});
7693
});

0 commit comments

Comments
 (0)