From 8be84f35cc03412784fe474da2c79d087b9e9abe Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 9 Dec 2016 16:24:47 +0100 Subject: [PATCH 01/10] Pass in compiler to 'watch-run' plugin --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d24365a..8892c28 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,9 @@ function apply(options, compiler) { var runner = runCompilation.bind(this, options); compiler.plugin('run', runner); - compiler.plugin('watch-run', runner); + compiler.plugin('watch-run', function (watcher, callback) { + runner(watcher.compiler, callback) + }); } /** From 4ce63b6a126176aac88256a69824322d08d1fd09 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 9 Dec 2016 16:26:34 +0100 Subject: [PATCH 02/10] Fix incorrect variable name --- lib/run-compilation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 91eccbd..43cee7e 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -7,10 +7,10 @@ var linter = require('./linter'); * Function bound to the plugin `apply` method to run the linter and report any * errors (and their source file locations) * @param options - from the apply method, the options passed in - * @param compilation - the compiler object + * @param compiler - the compiler object * @param done - webpack callback */ -module.exports = function runCompilation(options, compilation, done) { +module.exports = function runCompilation(options, compiler, done) { var errors = []; var warnings = []; @@ -46,7 +46,7 @@ module.exports = function runCompilation(options, compilation, done) { }); // eslint-disable-next-line no-unused-expressions - compilation.plugin && compilation.plugin('compilation', function (compilation) { + compiler.plugin('compilation', function (compilation) { compilation.errors = compilation.errors.concat(errors); compilation.warnings = compilation.warnings.concat(warnings); }); From 087f0c62f76c6f9a616c66e214aa471782ab01ee Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 9 Dec 2016 16:27:53 +0100 Subject: [PATCH 03/10] Display formatted warnings and errors --- lib/run-compilation.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 43cee7e..77987cd 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -23,12 +23,7 @@ module.exports = function runCompilation(options, compiler, done) { 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) { done(new Error('Failed because of a stylelint error.\n')); @@ -47,7 +42,14 @@ module.exports = function runCompilation(options, compiler, done) { // eslint-disable-next-line no-unused-expressions compiler.plugin('compilation', function (compilation) { - compilation.errors = compilation.errors.concat(errors); - compilation.warnings = compilation.warnings.concat(warnings); + if (warnings.length) { + compilation.warnings.push(chalk.yellow(options.formatter(warnings))); + warnings = []; + } + + if (errors.length) { + compilation.errors.push(chalk.red(options.formatter(errors))); + errors = []; + } }); }; From 18a6348821474f36316f76c99ee458ec0216087c Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 9 Dec 2016 18:18:01 +0100 Subject: [PATCH 04/10] Fix linting error --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8892c28..654049e 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,7 @@ function apply(options, compiler) { compiler.plugin('run', runner); compiler.plugin('watch-run', function (watcher, callback) { - runner(watcher.compiler, callback) + runner(watcher.compiler, callback); }); } From 69fc5c7b2543f14be0e67e6b22f347333e1ccaaf Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 9 Dec 2016 18:30:50 +0100 Subject: [PATCH 05/10] Fix test --- test/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index b338f20..402cbaa 100644 --- a/test/index.js +++ b/test/index.js @@ -70,7 +70,9 @@ describe('stylelint-webpack-plugin', function () { return pack(assign({}, baseConfig, config)) .then(function (stats) { - expect(stats.compilation.errors).to.have.length(2); + expect(stats.compilation.errors).to.have.length(1); + expect(stats.compilation.errors[0]).to.contain('test/fixtures/test7/_second.scss'); + expect(stats.compilation.errors[0]).to.contain('test/fixtures/test7/test.scss'); }); }); From 0eaa431fcfeb199aad1cf8e2552241985b3b48df Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Mon, 12 Dec 2016 13:23:39 +0100 Subject: [PATCH 06/10] Remove unnecessary eslint configuration --- lib/run-compilation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 77987cd..78293a2 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -40,7 +40,6 @@ module.exports = function runCompilation(options, compiler, done) { console.log(chalk.red(err)); }); - // eslint-disable-next-line no-unused-expressions compiler.plugin('compilation', function (compilation) { if (warnings.length) { compilation.warnings.push(chalk.yellow(options.formatter(warnings))); From 0980ebcf9cb2dd36c30620a93970f8c621ac3480 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Thu, 15 Dec 2016 14:53:37 +0100 Subject: [PATCH 07/10] Name anonymous functions --- index.js | 2 +- lib/run-compilation.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 654049e..273dfa7 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ function apply(options, compiler) { var runner = runCompilation.bind(this, options); compiler.plugin('run', runner); - compiler.plugin('watch-run', function (watcher, callback) { + compiler.plugin('watch-run', function onWatchRun (watcher, callback) { runner(watcher.compiler, callback); }); } diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 78293a2..734ff3d 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -40,7 +40,7 @@ module.exports = function runCompilation(options, compiler, done) { console.log(chalk.red(err)); }); - compiler.plugin('compilation', function (compilation) { + compiler.plugin('compilation', function onCompilation (compilation) { if (warnings.length) { compilation.warnings.push(chalk.yellow(options.formatter(warnings))); warnings = []; From 1e70f582d5b82705fa673f9561981a6e3002759d Mon Sep 17 00:00:00 2001 From: Jason Kurian Date: Fri, 16 Dec 2016 02:30:59 -0500 Subject: [PATCH 08/10] correct style nits --- lib/run-compilation.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index 734ff3d..acb42cb 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -15,15 +15,9 @@ module.exports = function runCompilation(options, compiler, done) { var warnings = []; linter(options) - .then(function (lint) { - warnings = lint.results - .filter(function (f) { - return f.warnings && f.warnings.length; - }); - errors = lint.results - .filter(function (f) { - return f.errored; - }); + .then(function linterSuccess(lint) { + warnings = lint.results.filter(function (f) { return f.warnings && f.warnings.length; }); + errors = lint.results.filter(function (f) { return f.errored; }); if (options.failOnError && errors.length) { done(new Error('Failed because of a stylelint error.\n')); @@ -31,7 +25,7 @@ module.exports = function runCompilation(options, compiler, done) { done(); } }) - .catch(function (err) { + .catch(function linterError(err) { if (options.failOnError && errors.length) { done(new Error('Failed because of a stylelint error.\n')); } else { @@ -40,7 +34,7 @@ module.exports = function runCompilation(options, compiler, done) { console.log(chalk.red(err)); }); - compiler.plugin('compilation', function onCompilation (compilation) { + compiler.plugin('compilation', function onCompilation(compilation) { if (warnings.length) { compilation.warnings.push(chalk.yellow(options.formatter(warnings))); warnings = []; From 359a6519d79c1019dbc36e4f1acc5bf7baa9367a Mon Sep 17 00:00:00 2001 From: Jason Kurian Date: Fri, 16 Dec 2016 02:33:28 -0500 Subject: [PATCH 09/10] fixes eslint nit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 273dfa7..1faaaf1 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ function apply(options, compiler) { var runner = runCompilation.bind(this, options); compiler.plugin('run', runner); - compiler.plugin('watch-run', function onWatchRun (watcher, callback) { + compiler.plugin('watch-run', function onWatchRun(watcher, callback) { runner(watcher.compiler, callback); }); } From b4e6f2b4b89f5c99af039878c86d0babde81c712 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Fri, 16 Dec 2016 10:12:09 +0100 Subject: [PATCH 10/10] Fix linting errors --- lib/run-compilation.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/run-compilation.js b/lib/run-compilation.js index acb42cb..40858db 100644 --- a/lib/run-compilation.js +++ b/lib/run-compilation.js @@ -16,8 +16,13 @@ module.exports = function runCompilation(options, compiler, done) { linter(options) .then(function linterSuccess(lint) { - warnings = lint.results.filter(function (f) { return f.warnings && f.warnings.length; }); - errors = lint.results.filter(function (f) { return f.errored; }); + warnings = lint.results.filter(function (f) { + return f.warnings && f.warnings.length; + }); + + errors = lint.results.filter(function (f) { + return f.errored; + }); if (options.failOnError && errors.length) { done(new Error('Failed because of a stylelint error.\n'));