Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed warnings not being logged to console #26

Merged
merged 7 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ 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
});
warnings = lint.results
.filter(function (f) {
return f.warnings;
})
.map(function (f) {
return f.source; // send error instead
});
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.quiet) {
console.log(chalk.yellow(options.formatter(lint.results)));
}

if (options.failOnError && errors.length) {
Expand All @@ -49,5 +55,8 @@ module.exports = function runCompilation(options, compilation, done) {
errors.forEach(function (err) {
compilation.errors.push(err);
});
warnings.forEach(function (warning) {
compilation.warnings.push(warning);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the .concat method instead of going through each warning. I've been meaning to fix the original code as well so if you could change it that'd be great.

});
});
};
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
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;
}
20 changes: 19 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('stylelint-webpack-plugin', function () {
pack(assign({}, baseConfig, config), function (err, stats) {
expect(err).to.not.exist;
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(0);
done(err);
});
});
Expand Down Expand Up @@ -118,6 +117,25 @@ describe('stylelint-webpack-plugin', function () {
});
});

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

pack(assign({}, baseConfig, config), function (err, stats) {
expect(err).to.not.exist;
expect(stats.compilation.warnings).to.have.length(1);
done(err);
});
});

// it('should work with multiple context', function(done) {
// var config = {
// context: './test/fixtures/test5',
Expand Down