From a0021c5013877a447b89939bb5fcb14ba70d9efa Mon Sep 17 00:00:00 2001 From: Ian Black Date: Mon, 15 Aug 2016 19:52:26 +0100 Subject: [PATCH] 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 --- lib/run-compilation.js | 30 +++++++++++++++--------------- test/.stylelintrc | 3 ++- test/fixtures/test7/index.js | 2 +- test/fixtures/test8/index.js | 3 +++ test/fixtures/test8/test.scss | 3 +++ test/index.js | 19 ++++++++++++++++++- 6 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 test/fixtures/test8/index.js create mode 100644 test/fixtures/test8/test.scss diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 2dbf202..91eccbd 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -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) { @@ -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); }); }; diff --git a/test/.stylelintrc b/test/.stylelintrc index b6521d3..475a70d 100644 --- a/test/.stylelintrc +++ b/test/.stylelintrc @@ -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", { diff --git a/test/fixtures/test7/index.js b/test/fixtures/test7/index.js index aa35728..613dcda 100644 --- a/test/fixtures/test7/index.js +++ b/test/fixtures/test7/index.js @@ -1,3 +1,3 @@ require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss'); -console.log('test6'); +console.log('test7'); diff --git a/test/fixtures/test8/index.js b/test/fixtures/test8/index.js new file mode 100644 index 0000000..235570c --- /dev/null +++ b/test/fixtures/test8/index.js @@ -0,0 +1,3 @@ +require(getPath('./../../../node_modules/file-loader/index') + '!./test.scss'); + +console.log('test8'); diff --git a/test/fixtures/test8/test.scss b/test/fixtures/test8/test.scss new file mode 100644 index 0000000..140c401 --- /dev/null +++ b/test/fixtures/test8/test.scss @@ -0,0 +1,3 @@ +body { + color: #FFF; +} diff --git a/test/index.js b/test/index.js index 0885204..ada97f8 100644 --- a/test/index.js +++ b/test/index.js @@ -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); }); }); @@ -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); + }); + }); });