Skip to content

Commit

Permalink
fix: warnings not being logged to console (#26)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iblack10 authored and joshwiens committed Mar 31, 2018
1 parent cf37818 commit a0021c5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
30 changes: 15 additions & 15 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ var linter = require('./linter');
*/
module.exports = function runCompilation(options, compilation, done) {
var errors = [];
var warnings = [];

linter(options)
.then(function (lint) {
if (lint.errored) {
errors = lint.results
.filter(function (f) {
return f.errored;
})
.map(function (f) {
return f.source; // send error instead
});

if (!options.quiet) {
console.log(chalk.yellow(options.formatter(lint.results)));
}
warnings = lint.results
.filter(function (f) {
return f.warnings && f.warnings.length;
});
errors = lint.results
.filter(function (f) {
return f.errored;
}).map(function (f) {
return f.source; // send error instead
});
if (!options.quiet) {
console.log(chalk.yellow(options.formatter(lint.results)));
}

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

// eslint-disable-next-line no-unused-expressions
compilation.plugin && compilation.plugin('compilation', function (compilation) {
errors.forEach(function (err) {
compilation.errors.push(err);
});
compilation.errors = compilation.errors.concat(errors);
compilation.warnings = compilation.warnings.concat(warnings);
});
};
3 changes: 2 additions & 1 deletion test/.stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"block-opening-brace-newline-after": "always-multi-line",
"block-opening-brace-space-after": "always-single-line",
"block-opening-brace-space-before": "always",
"color-hex-case": "lower",
"color-hex-case": [ "lower", { "severity": "warning" }
],
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test7/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss');

console.log('test6');
console.log('test7');
3 changes: 3 additions & 0 deletions test/fixtures/test8/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss');

console.log('test8');
3 changes: 3 additions & 0 deletions test/fixtures/test8/test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: #FFF;
}
19 changes: 18 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('stylelint-webpack-plugin', function () {
return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(0);
});
});

Expand Down Expand Up @@ -73,4 +72,22 @@ describe('stylelint-webpack-plugin', function () {
expect(stats.compilation.errors).to.have.length(2);
});
});

it('sends warnings properly', function () {
var config = {
context: './test/fixtures/test8',
entry: './index',
plugins: [
new StyleLintPlugin({
quiet: true,
configFile: configFilePath
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.warnings).to.have.length(1);
});
});
});

0 comments on commit a0021c5

Please sign in to comment.