Skip to content

Commit a15e54c

Browse files
authored
fix: remove duplicate error/warning logging (#130)
* style: correct td.verify calls to match documentation * style: use const/lets in lint-dirty-modules.test.js
1 parent ad3158d commit a15e54c

File tree

5 files changed

+36
-67
lines changed

5 files changed

+36
-67
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ See [stylelint options](http://stylelint.io/user-guide/node-api/#options) for th
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`
5151
* [`syntax`](https://stylelint.io/user-guide/node-api/#syntax): e.g. use `'scss'` to lint .scss files. Default: `undefined`
52-
* `quiet`: Prints `stylelint` output directly to the console if negated. Default: `true`.
5352

5453
## Errors
5554

lib/run-compilation.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ module.exports = function runCompilation (options, compiler, done) {
2727
errors = results.filter(fileHasErrors);
2828
}
2929

30-
if (options.quiet === false) {
31-
console.warn(options.formatter(results));
32-
}
33-
3430
if (options.failOnError && errors.length) {
3531
done(new Error(errorMessage));
3632
} else {

test/helpers/base-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var baseConfig = {
1212
},
1313
plugins: [
1414
new StyleLintPlugin({
15-
quiet: true,
1615
configFile: configFilePath
1716
})
1817
]

test/index.test.js

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ const configFilePath = getPath('./.stylelintrc');
1313
const errorMessage = require('../lib/constants').errorMessage;
1414

1515
describe('stylelint-webpack-plugin', function () {
16+
beforeEach(function () {
17+
td.replace(console, 'warn', td.function());
18+
});
19+
20+
afterEach(function () {
21+
// See https://github.com/JaKXz/stylelint-webpack-plugin/issues/61
22+
td.verify(console.warn(), { times: 0, ignoreExtraArgs: true });
23+
td.reset();
24+
});
25+
1626
it('works with a simple file', function () {
1727
return pack(assign({}, baseConfig, { context: path.resolve('./test/fixtures/lint-free') }))
1828
.then(function (stats) {
@@ -53,7 +63,6 @@ describe('stylelint-webpack-plugin', function () {
5363
plugins: [
5464
new StyleLintPlugin({
5565
configFile: configFilePath,
56-
quiet: true,
5766
failOnError: true
5867
})
5968
]
@@ -71,8 +80,7 @@ describe('stylelint-webpack-plugin', function () {
7180
context: path.resolve('./test/fixtures/single-error'),
7281
plugins: [
7382
new StyleLintPlugin({
74-
configFile: getPath('./.badstylelintrc'),
75-
quiet: true
83+
configFile: getPath('./.badstylelintrc')
7684
})
7785
]
7886
};
@@ -84,34 +92,6 @@ describe('stylelint-webpack-plugin', function () {
8492
});
8593
});
8694

87-
context('iff quiet is strictly false', function () {
88-
beforeEach(function () {
89-
td.replace(console, 'warn', td.function());
90-
});
91-
92-
afterEach(function () {
93-
td.reset();
94-
});
95-
96-
it('sends messages to the console', function () {
97-
const config = {
98-
context: path.resolve('./test/fixtures/syntax-error'),
99-
plugins: [
100-
new StyleLintPlugin({
101-
configFile: configFilePath,
102-
quiet: false
103-
})
104-
]
105-
};
106-
107-
return pack(assign({}, baseConfig, config))
108-
.then(function (stats) {
109-
expect(stats.compilation.errors).to.have.length(1);
110-
td.verify(console.warn(td.matchers.contains(/.*/i)));
111-
});
112-
});
113-
});
114-
11595
context('without StyleLintPlugin configuration', function () {
11696
const config = {
11797
plugins: [
@@ -141,8 +121,7 @@ describe('stylelint-webpack-plugin', function () {
141121
context: path.resolve('./test/fixtures/single-error'),
142122
plugins: [
143123
new StyleLintPlugin({
144-
configFile: configFilePath,
145-
quiet: true
124+
configFile: configFilePath
146125
}),
147126
new webpack.NoErrorsPlugin()
148127
]
@@ -159,7 +138,6 @@ describe('stylelint-webpack-plugin', function () {
159138
plugins: [
160139
new StyleLintPlugin({
161140
configFile: configFilePath,
162-
quiet: true,
163141
failOnError: true
164142
}),
165143
new webpack.NoErrorsPlugin()
@@ -188,7 +166,6 @@ describe('stylelint-webpack-plugin', function () {
188166
plugins: [
189167
new StyleLintPlugin({
190168
configFile: configFilePath,
191-
quiet: true,
192169
emitErrors: false
193170
})
194171
]
@@ -230,7 +207,6 @@ describe('stylelint-webpack-plugin', function () {
230207
plugins: [
231208
new StyleLintPlugin({
232209
configFile: configFilePath,
233-
quiet: true,
234210
lintDirtyModulesOnly: true
235211
})
236212
]
@@ -249,7 +225,6 @@ describe('stylelint-webpack-plugin', function () {
249225
plugins: [
250226
new StyleLintPlugin({
251227
configFile: configFilePath,
252-
quiet: true,
253228
lintDirtyModulesOnly: true,
254229
emitErrors: false
255230
})

test/lib/lint-dirty-modules-plugin.test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
'use strict';
22

3-
var td = require('testdouble');
4-
var formatter = require('stylelint').formatters.string;
3+
const td = require('testdouble');
4+
const formatter = require('stylelint').formatters.string;
55

6-
var runCompilation = td.replace('../../lib/run-compilation');
6+
const runCompilation = td.replace('../../lib/run-compilation');
77

8-
var LintDirtyModulesPlugin = require('../../lib/lint-dirty-modules-plugin');
8+
const LintDirtyModulesPlugin = require('../../lib/lint-dirty-modules-plugin');
99

10-
var configFilePath = getPath('./.stylelintrc');
11-
var glob = require('../../lib/constants').defaultFilesGlob;
10+
const configFilePath = getPath('./.stylelintrc');
11+
const glob = require('../../lib/constants').defaultFilesGlob;
1212

1313
describe('lint-dirty-modules-plugin', function () {
14-
var LintDirtyModulesPluginCloned;
15-
var compilerMock;
16-
var optionsMock;
14+
let LintDirtyModulesPluginCloned;
15+
let compilerMock;
16+
let optionsMock;
1717

1818
beforeEach(function () {
1919
LintDirtyModulesPluginCloned = function () {
@@ -38,15 +38,15 @@ describe('lint-dirty-modules-plugin', function () {
3838
});
3939

4040
it('lint is called on "emit"', function () {
41-
var lintStub = td.function();
42-
var doneStub = td.function();
41+
const lintStub = td.function();
42+
const doneStub = td.function();
4343
LintDirtyModulesPluginCloned.prototype.lint = lintStub;
44-
var compilationMock = {
44+
const compilationMock = {
4545
fileTimestamps: {
4646
'/updated.scss': 5
4747
}
4848
};
49-
var plugin = new LintDirtyModulesPluginCloned(compilerMock, optionsMock);
49+
const plugin = new LintDirtyModulesPluginCloned(compilerMock, optionsMock);
5050

5151
compilerMock.callback(compilationMock, doneStub);
5252

@@ -55,14 +55,14 @@ describe('lint-dirty-modules-plugin', function () {
5555
});
5656

5757
context('#lint()', function () {
58-
var getChangedFilesStub;
59-
var doneStub;
60-
var compilationMock;
61-
var fileTimestamps = {
58+
let getChangedFilesStub;
59+
let doneStub;
60+
let compilationMock;
61+
const fileTimestamps = {
6262
'/test/changed.scss': 5,
6363
'/test/newly-created.scss': 5
6464
};
65-
var pluginMock;
65+
let pluginMock;
6666
beforeEach(function () {
6767
getChangedFilesStub = td.function();
6868
doneStub = td.function();
@@ -86,8 +86,8 @@ describe('lint-dirty-modules-plugin', function () {
8686

8787
td.verify(doneStub());
8888
expect(pluginMock.isFirstRun).to.eql(false);
89-
td.verify(getChangedFilesStub, {times: 0, ignoreExtraArgs: true});
90-
td.verify(runCompilation, {times: 0, ignoreExtraArgs: true});
89+
td.verify(getChangedFilesStub(), { times: 0, ignoreExtraArgs: true });
90+
td.verify(runCompilation(), { times: 0, ignoreExtraArgs: true });
9191
});
9292

9393
it('runCompilation is not called if files are not changed', function () {
@@ -96,7 +96,7 @@ describe('lint-dirty-modules-plugin', function () {
9696
LintDirtyModulesPluginCloned.prototype.lint.call(pluginMock, compilationMock, doneStub);
9797

9898
td.verify(doneStub());
99-
td.verify(runCompilation, {times: 0, ignoreExtraArgs: true});
99+
td.verify(runCompilation(), { times: 0, ignoreExtraArgs: true });
100100
});
101101

102102
it('runCompilation is called if styles are changed', function () {
@@ -113,7 +113,7 @@ describe('lint-dirty-modules-plugin', function () {
113113
});
114114

115115
context('#getChangedFiles()', function () {
116-
var pluginMock;
116+
let pluginMock;
117117
before(function () {
118118
pluginMock = {
119119
compiler: compilerMock,
@@ -129,13 +129,13 @@ describe('lint-dirty-modules-plugin', function () {
129129
});
130130

131131
it('returns changed style files', function () {
132-
var fileTimestamps = {
132+
const fileTimestamps = {
133133
'/test/changed.scss': 20,
134134
'/test/changed.js': 20,
135135
'/test/newly-created.scss': 15
136136
};
137137

138-
var changedFiles = LintDirtyModulesPluginCloned.prototype.getChangedFiles.call(pluginMock, fileTimestamps, glob);
138+
const changedFiles = LintDirtyModulesPluginCloned.prototype.getChangedFiles.call(pluginMock, fileTimestamps, glob);
139139

140140
expect(changedFiles).to.eql([
141141
'/test/changed.scss',

0 commit comments

Comments
 (0)