Skip to content

Commit 24b581b

Browse files
nickgcattaneoJaKXz
authored andcommitted
feat: support webpack/webpack-dev-server from hard-failing on error messages (#112)
* changes to support webpack-dev-server Fixes #103 * addressed maintainer comments reverted javascript style-related preferences * readme updates to emitErrors and failOnError updates to address clarifying specific behavior of emitErrors and failOnError keys. * updated test cases, resolved cross-env issues
1 parent 16c3d41 commit 24b581b

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ See [stylelint options](http://stylelint.io/user-guide/node-api/#options) for th
4343

4444
* `configFile`: You can change the config file location. Default: (`undefined`), handled by [stylelint's cosmiconfig module](http://stylelint.io/user-guide/configuration/).
4545
* `context`: String indicating the root of your SCSS files. Default: inherits from webpack config.
46-
* `emitErrors`: Display Stylelint errors as actual errors, rather than just warnings. Default: `true`
47-
* `failOnError`: Have Webpack's build process die on error. Default: `false`
46+
* `emitErrors`: Pipe stylelint 'error' severity messages to the error message handler in webpack's current instance. Note when this property is disabled (false) all stylelint messages are piped to webpack's warning message handler. Default: `true`
47+
* `failOnError`: Throw a fatal error in the global build process (e.g. kill your entire build process on any stylelint 'error' severity message). Default: `false`
4848
* `files`: Change the glob pattern for finding files. Must be relative to `options.context`. Default: `['**/*.s?(a|c)ss']`
4949
* `formatter`: Use a custom formatter to print errors to the console. Default: `require('stylelint').formatters.string`
5050
* `lintDirtyModulesOnly`: Lint only changed files, skip lint on start. Default: `false`

lib/run-compilation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var errorMessage = require('./constants').errorMessage;
1414
module.exports = function runCompilation (options, compiler, done) {
1515
var errors = [];
1616
var warnings = [];
17+
var compilerMethod = options.emitErrors ? 'after-compile' : 'after-emit';
1718

1819
linter(options)
1920
.then(function linterSuccess (lint) {
@@ -38,7 +39,7 @@ module.exports = function runCompilation (options, compiler, done) {
3839
})
3940
.catch(done);
4041

41-
compiler.plugin('after-emit', function afterEmit (compilation, callback) {
42+
compiler.plugin(compilerMethod, function (compilation, next) {
4243
if (warnings.length) {
4344
compilation.warnings.push(new Error(options.formatter(warnings)));
4445
warnings = [];
@@ -49,7 +50,7 @@ module.exports = function runCompilation (options, compiler, done) {
4950
errors = [];
5051
}
5152

52-
callback();
53+
next();
5354
});
5455
};
5556

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"chai": "^4.0.2",
4444
"conventional-github-releaser": "^1.1.3",
4545
"coveralls": "^3.0.0",
46+
"cross-env": "^5.1.3",
4647
"dotenv": "^4.0.0",
4748
"memory-fs": "^0.4.1",
4849
"mocha": "^4.0.1",
@@ -55,8 +56,8 @@
5556
},
5657
"scripts": {
5758
"pretest": "semistandard",
58-
"test:webpack1": "WEBPACK_VERSION=1 nyc mocha",
59-
"test:webpack3": "WEBPACK_VERSION=3 nyc mocha",
59+
"test:webpack1": "cross-env WEBPACK_VERSION=1 nyc mocha",
60+
"test:webpack3": "cross-env WEBPACK_VERSION=3 nyc mocha",
6061
"test": "run-s test:*",
6162
"preversion": "npm run test",
6263
"version": "git add -A ."

test/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('stylelint-webpack-plugin', function () {
107107
return pack(assign({}, baseConfig, config))
108108
.then(function (stats) {
109109
expect(stats.compilation.errors).to.have.length(1);
110-
td.verify(console.warn(td.matchers.contains('✖')));
110+
td.verify(console.warn(td.matchers.contains(/.*/i)));
111111
});
112112
});
113113
});
@@ -208,7 +208,7 @@ describe('stylelint-webpack-plugin', function () {
208208
expect(stats.compilation.errors).to.have.length(0);
209209
expect(stats.compilation.warnings).to.have.length(1);
210210
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
211-
expect(stats.compilation.warnings[0].message).to.contain('✖');
211+
expect(stats.compilation.warnings[0].message.length > 0).to.equal(true);
212212
});
213213
});
214214

@@ -218,7 +218,7 @@ describe('stylelint-webpack-plugin', function () {
218218
expect(stats.compilation.errors).to.have.length(0);
219219
expect(stats.compilation.warnings).to.have.length(1);
220220
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
221-
expect(stats.compilation.warnings[0].message).to.contain('⚠');
221+
expect(stats.compilation.warnings[0].message.length > 0).to.equal(true);
222222
});
223223
});
224224
});

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ create-error-class@^3.0.0:
815815
dependencies:
816816
capture-stack-trace "^1.0.0"
817817

818+
cross-env@^5.1.3:
819+
version "5.1.3"
820+
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.3.tgz#f8ae18faac87692b0a8b4d2f7000d4ec3a85dfd7"
821+
dependencies:
822+
cross-spawn "^5.1.0"
823+
is-windows "^1.0.0"
824+
818825
cross-spawn@^4:
819826
version "4.0.2"
820827
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41"
@@ -2106,6 +2113,10 @@ is-utf8@^0.2.0:
21062113
version "0.2.1"
21072114
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
21082115

2116+
is-windows@^1.0.0:
2117+
version "1.0.1"
2118+
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9"
2119+
21092120
isarray@0.0.1:
21102121
version "0.0.1"
21112122
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"

0 commit comments

Comments
 (0)