stylelint-webpack-plugin 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +199 -199
- package/dist/StylelintError.js +4 -10
- package/dist/getStylelint.js +47 -40
- package/dist/index.js +90 -71
- package/dist/linter.js +67 -61
- package/dist/options.js +40 -41
- package/dist/options.json +80 -80
- package/dist/utils.js +33 -40
- package/dist/worker.js +5 -5
- package/package.json +23 -23
- package/types/StylelintError.d.ts +8 -0
- package/{declarations → types}/getStylelint.d.ts +35 -13
- package/{declarations → types}/index.d.ts +22 -11
- package/{declarations → types}/linter.d.ts +44 -15
- package/{declarations → types}/options.d.ts +47 -38
- package/{declarations → types}/utils.d.ts +5 -0
- package/{declarations → types}/worker.d.ts +9 -0
- package/declarations/StylelintError.d.ts +0 -2
- package/declarations/cjs.d.ts +0 -3
- package/dist/cjs.js +0 -5
package/dist/index.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const {
|
|
4
|
+
isAbsolute,
|
|
5
|
+
join
|
|
6
|
+
} = require('path');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const arrify = require('arrify');
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const globby = require('globby');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const {
|
|
13
|
+
isMatch
|
|
14
|
+
} = require('micromatch');
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
const {
|
|
17
|
+
getOptions
|
|
18
|
+
} = require('./options');
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _linter = _interopRequireDefault(require("./linter"));
|
|
19
|
-
|
|
20
|
-
var _utils = require("./utils");
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
// @ts-ignore
|
|
20
|
+
const linter = require('./linter');
|
|
26
21
|
|
|
22
|
+
const {
|
|
23
|
+
parseFiles,
|
|
24
|
+
parseFoldersToGlobs
|
|
25
|
+
} = require('./utils');
|
|
27
26
|
/** @typedef {import('webpack').Compiler} Compiler */
|
|
28
27
|
|
|
29
28
|
/** @typedef {import('webpack').Module} Module */
|
|
@@ -31,36 +30,48 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
31
30
|
/** @typedef {import('./options').Options} Options */
|
|
32
31
|
|
|
33
32
|
/** @typedef {Partial<{timestamp:number} | number>} FileSystemInfoEntry */
|
|
33
|
+
|
|
34
|
+
|
|
34
35
|
const STYLELINT_PLUGIN = 'StylelintWebpackPlugin';
|
|
35
36
|
let counter = 0;
|
|
36
37
|
|
|
37
38
|
class StylelintWebpackPlugin {
|
|
38
|
-
/**
|
|
39
|
-
* @param {Options} options
|
|
39
|
+
/**
|
|
40
|
+
* @param {Options} options
|
|
40
41
|
*/
|
|
41
42
|
constructor(options = {}) {
|
|
42
43
|
this.key = STYLELINT_PLUGIN;
|
|
43
|
-
this.options =
|
|
44
|
+
this.options = getOptions(options);
|
|
44
45
|
this.run = this.run.bind(this);
|
|
45
46
|
this.startTime = Date.now();
|
|
46
47
|
/** @type {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} */
|
|
47
48
|
|
|
48
49
|
this.prevTimestamps = new Map();
|
|
49
50
|
}
|
|
50
|
-
/**
|
|
51
|
-
* @param {Compiler} compiler
|
|
52
|
-
* @returns {void}
|
|
51
|
+
/**
|
|
52
|
+
* @param {Compiler} compiler
|
|
53
|
+
* @returns {void}
|
|
53
54
|
*/
|
|
54
55
|
|
|
55
56
|
|
|
56
57
|
apply(compiler) {
|
|
57
58
|
// Generate key for each compilation,
|
|
58
59
|
// this differentiates one from the other when being cached.
|
|
59
|
-
this.key = compiler.name || `${this.key}_${counter += 1}`;
|
|
60
|
+
this.key = compiler.name || `${this.key}_${counter += 1}`;
|
|
61
|
+
const context = this.getContext(compiler);
|
|
62
|
+
const excludeDefault = ['**/node_modules/**', String(compiler.options.output.path)];
|
|
63
|
+
const options = { ...this.options,
|
|
64
|
+
context,
|
|
65
|
+
exclude: parseFiles(this.options.exclude || excludeDefault, context),
|
|
66
|
+
extensions: arrify(this.options.extensions),
|
|
67
|
+
files: parseFiles(this.options.files || '', context)
|
|
68
|
+
};
|
|
69
|
+
const wanted = parseFoldersToGlobs(options.files, options.extensions);
|
|
70
|
+
const exclude = parseFoldersToGlobs(options.exclude); // If `lintDirtyModulesOnly` is disabled,
|
|
60
71
|
// execute the linter on the build
|
|
61
72
|
|
|
62
73
|
if (!this.options.lintDirtyModulesOnly) {
|
|
63
|
-
compiler.hooks.run.tapPromise(this.key, this.run);
|
|
74
|
+
compiler.hooks.run.tapPromise(this.key, c => this.run(c, options, wanted, exclude));
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
let isFirstRun = this.options.lintDirtyModulesOnly;
|
|
@@ -70,15 +81,18 @@ class StylelintWebpackPlugin {
|
|
|
70
81
|
return Promise.resolve();
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
return this.run(c);
|
|
84
|
+
return this.run(c, options, wanted, exclude);
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
|
-
/**
|
|
77
|
-
* @param {Compiler} compiler
|
|
87
|
+
/**
|
|
88
|
+
* @param {Compiler} compiler
|
|
89
|
+
* @param {Options} options
|
|
90
|
+
* @param {string[]} wanted
|
|
91
|
+
* @param {string[]} exclude
|
|
78
92
|
*/
|
|
79
93
|
|
|
80
94
|
|
|
81
|
-
async run(compiler) {
|
|
95
|
+
async run(compiler, options, wanted, exclude) {
|
|
82
96
|
// Do not re-hook
|
|
83
97
|
|
|
84
98
|
/* istanbul ignore if */
|
|
@@ -89,17 +103,12 @@ class StylelintWebpackPlugin {
|
|
|
89
103
|
return;
|
|
90
104
|
}
|
|
91
105
|
|
|
92
|
-
const context = this.getContext(compiler);
|
|
93
|
-
const options = { ...this.options,
|
|
94
|
-
exclude: (0, _utils.parseFiles)(this.options.exclude || ['**/node_modules/**', compiler.options.output.path], context),
|
|
95
|
-
extensions: (0, _arrify.default)(this.options.extensions),
|
|
96
|
-
files: (0, _utils.parseFiles)(this.options.files || '', context)
|
|
97
|
-
};
|
|
98
|
-
const wanted = (0, _utils.parseFoldersToGlobs)(options.files, options.extensions);
|
|
99
|
-
const exclude = (0, _utils.parseFoldersToGlobs)(options.exclude);
|
|
100
106
|
compiler.hooks.thisCompilation.tap(this.key, compilation => {
|
|
101
107
|
/** @type {import('./linter').Linter} */
|
|
102
108
|
let lint;
|
|
109
|
+
/** @type {import('stylelint').InternalApi} */
|
|
110
|
+
|
|
111
|
+
let api;
|
|
103
112
|
/** @type {import('./linter').Reporter} */
|
|
104
113
|
|
|
105
114
|
let report;
|
|
@@ -110,23 +119,34 @@ class StylelintWebpackPlugin {
|
|
|
110
119
|
try {
|
|
111
120
|
({
|
|
112
121
|
lint,
|
|
122
|
+
api,
|
|
113
123
|
report,
|
|
114
124
|
threads
|
|
115
|
-
} = (
|
|
125
|
+
} = linter(this.key, options, compilation));
|
|
116
126
|
} catch (e) {
|
|
117
127
|
compilation.errors.push(e);
|
|
118
128
|
return;
|
|
119
129
|
}
|
|
120
130
|
|
|
121
|
-
compilation.hooks.finishModules.
|
|
122
|
-
|
|
131
|
+
compilation.hooks.finishModules.tapPromise(this.key, async () => {
|
|
132
|
+
/** @type {string[]} */
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
const files = (await Promise.all(this.getFiles(compiler, wanted, exclude).map(async (
|
|
135
|
+
/** @type {string | undefined} */
|
|
136
|
+
file) => {
|
|
137
|
+
try {
|
|
138
|
+
return (await api.isPathIgnored(file)) ? false : file;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
return file;
|
|
141
|
+
}
|
|
142
|
+
}))).filter(file => file !== false);
|
|
123
143
|
|
|
124
144
|
if (threads > 1) {
|
|
125
145
|
for (const file of files) {
|
|
126
|
-
lint(
|
|
146
|
+
lint(parseFiles(file, options.context || ''));
|
|
127
147
|
}
|
|
128
148
|
} else if (files.length > 0) {
|
|
129
|
-
lint(
|
|
149
|
+
lint(parseFiles(files, options.context || ''));
|
|
130
150
|
}
|
|
131
151
|
}); // await and interpret results
|
|
132
152
|
|
|
@@ -161,10 +181,10 @@ class StylelintWebpackPlugin {
|
|
|
161
181
|
}
|
|
162
182
|
});
|
|
163
183
|
}
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {Compiler} compiler
|
|
167
|
-
* @returns {string}
|
|
184
|
+
/**
|
|
185
|
+
*
|
|
186
|
+
* @param {Compiler} compiler
|
|
187
|
+
* @returns {string}
|
|
168
188
|
*/
|
|
169
189
|
|
|
170
190
|
|
|
@@ -173,17 +193,17 @@ class StylelintWebpackPlugin {
|
|
|
173
193
|
return String(compiler.options.context);
|
|
174
194
|
}
|
|
175
195
|
|
|
176
|
-
if (!
|
|
177
|
-
return
|
|
196
|
+
if (!isAbsolute(this.options.context)) {
|
|
197
|
+
return join(String(compiler.options.context), this.options.context);
|
|
178
198
|
}
|
|
179
199
|
|
|
180
200
|
return this.options.context;
|
|
181
201
|
}
|
|
182
|
-
/**
|
|
183
|
-
* @param {Compiler} compiler
|
|
184
|
-
* @param {string[]} wanted
|
|
185
|
-
* @param {string[]} exclude
|
|
186
|
-
* @returns {string[]}
|
|
202
|
+
/**
|
|
203
|
+
* @param {Compiler} compiler
|
|
204
|
+
* @param {string[]} wanted
|
|
205
|
+
* @param {string[]} exclude
|
|
206
|
+
* @returns {string[]}
|
|
187
207
|
*/
|
|
188
208
|
// eslint-disable-next-line no-unused-vars
|
|
189
209
|
|
|
@@ -191,9 +211,9 @@ class StylelintWebpackPlugin {
|
|
|
191
211
|
getFiles(compiler, wanted, exclude) {
|
|
192
212
|
// webpack 5
|
|
193
213
|
if (compiler.modifiedFiles) {
|
|
194
|
-
return Array.from(compiler.modifiedFiles).filter(file =>
|
|
214
|
+
return Array.from(compiler.modifiedFiles).filter(file => isMatch(file, wanted, {
|
|
195
215
|
dot: true
|
|
196
|
-
}) && !
|
|
216
|
+
}) && !isMatch(file, exclude, {
|
|
197
217
|
dot: true
|
|
198
218
|
}));
|
|
199
219
|
} // webpack 4
|
|
@@ -202,30 +222,30 @@ class StylelintWebpackPlugin {
|
|
|
202
222
|
|
|
203
223
|
|
|
204
224
|
if (compiler.fileTimestamps && compiler.fileTimestamps.size > 0) {
|
|
205
|
-
return this.getChangedFiles(compiler.fileTimestamps).filter(file =>
|
|
225
|
+
return this.getChangedFiles(compiler.fileTimestamps).filter(file => isMatch(file, wanted, {
|
|
206
226
|
dot: true
|
|
207
|
-
}) && !
|
|
227
|
+
}) && !isMatch(file, exclude, {
|
|
208
228
|
dot: true
|
|
209
229
|
}));
|
|
210
230
|
}
|
|
211
231
|
|
|
212
|
-
return
|
|
232
|
+
return globby.sync(wanted, {
|
|
213
233
|
dot: true,
|
|
214
234
|
ignore: exclude
|
|
215
235
|
});
|
|
216
236
|
}
|
|
217
|
-
/**
|
|
218
|
-
* @param {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} fileTimestamps
|
|
219
|
-
* @returns {string[]}
|
|
237
|
+
/**
|
|
238
|
+
* @param {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} fileTimestamps
|
|
239
|
+
* @returns {string[]}
|
|
220
240
|
*/
|
|
221
241
|
|
|
222
242
|
/* istanbul ignore next */
|
|
223
243
|
|
|
224
244
|
|
|
225
245
|
getChangedFiles(fileTimestamps) {
|
|
226
|
-
/**
|
|
227
|
-
* @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
|
|
228
|
-
* @returns {Partial<number>}
|
|
246
|
+
/**
|
|
247
|
+
* @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
|
|
248
|
+
* @returns {Partial<number>}
|
|
229
249
|
*/
|
|
230
250
|
const getTimestamps = fileSystemInfoEntry => {
|
|
231
251
|
// @ts-ignore
|
|
@@ -237,10 +257,10 @@ class StylelintWebpackPlugin {
|
|
|
237
257
|
|
|
238
258
|
return fileSystemInfoEntry;
|
|
239
259
|
};
|
|
240
|
-
/**
|
|
241
|
-
* @param {string} filename
|
|
242
|
-
* @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
|
|
243
|
-
* @returns {boolean}
|
|
260
|
+
/**
|
|
261
|
+
* @param {string} filename
|
|
262
|
+
* @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
|
|
263
|
+
* @returns {boolean}
|
|
244
264
|
*/
|
|
245
265
|
|
|
246
266
|
|
|
@@ -264,5 +284,4 @@ class StylelintWebpackPlugin {
|
|
|
264
284
|
|
|
265
285
|
}
|
|
266
286
|
|
|
267
|
-
|
|
268
|
-
exports.default = _default;
|
|
287
|
+
module.exports = StylelintWebpackPlugin;
|
package/dist/linter.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const {
|
|
4
|
+
dirname,
|
|
5
|
+
isAbsolute,
|
|
6
|
+
join
|
|
7
|
+
} = require('path');
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const arrify = require('arrify');
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _StylelintError = _interopRequireDefault(require("./StylelintError"));
|
|
13
|
-
|
|
14
|
-
var _getStylelint = _interopRequireDefault(require("./getStylelint"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
// @ts-ignore
|
|
11
|
+
const StylelintError = require('./StylelintError');
|
|
19
12
|
|
|
13
|
+
const getStylelint = require('./getStylelint');
|
|
20
14
|
/** @typedef {import('stylelint')} Stylelint */
|
|
21
15
|
|
|
22
16
|
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
23
17
|
|
|
18
|
+
/** @typedef {import('stylelint').InternalApi} InternalApi */
|
|
19
|
+
|
|
24
20
|
/** @typedef {import('webpack').Compiler} Compiler */
|
|
25
21
|
|
|
26
22
|
/** @typedef {import('webpack').Compilation} Compilation */
|
|
@@ -42,17 +38,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
42
38
|
/** @typedef {{[files: string]: LintResult}} LintResultMap */
|
|
43
39
|
|
|
44
40
|
/** @type {WeakMap<Compiler, LintResultMap>} */
|
|
41
|
+
|
|
42
|
+
|
|
45
43
|
const resultStorage = new WeakMap();
|
|
46
|
-
/**
|
|
47
|
-
* @param {string|undefined} key
|
|
48
|
-
* @param {Options} options
|
|
49
|
-
* @param {Compilation} compilation
|
|
50
|
-
* @returns {{lint: Linter, report: Reporter, threads: number}}
|
|
44
|
+
/**
|
|
45
|
+
* @param {string|undefined} key
|
|
46
|
+
* @param {Options} options
|
|
47
|
+
* @param {Compilation} compilation
|
|
48
|
+
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
|
|
51
49
|
*/
|
|
52
50
|
|
|
53
51
|
function linter(key, options, compilation) {
|
|
54
52
|
/** @type {Stylelint} */
|
|
55
53
|
let stylelint;
|
|
54
|
+
/** @type {InternalApi} */
|
|
55
|
+
|
|
56
|
+
let api;
|
|
56
57
|
/** @type {(files: string|string[]) => Promise<LintResult[]>} */
|
|
57
58
|
|
|
58
59
|
let lintFiles;
|
|
@@ -70,30 +71,33 @@ function linter(key, options, compilation) {
|
|
|
70
71
|
try {
|
|
71
72
|
({
|
|
72
73
|
stylelint,
|
|
74
|
+
api,
|
|
73
75
|
lintFiles,
|
|
74
76
|
cleanup,
|
|
75
77
|
threads
|
|
76
|
-
} = (
|
|
78
|
+
} = getStylelint(key, options));
|
|
77
79
|
} catch (e) {
|
|
78
|
-
throw new
|
|
80
|
+
throw new StylelintError(e.message);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
return {
|
|
82
84
|
lint,
|
|
85
|
+
api,
|
|
83
86
|
report,
|
|
84
87
|
threads
|
|
85
88
|
};
|
|
86
|
-
/**
|
|
87
|
-
* @param {string | string[]} files
|
|
89
|
+
/**
|
|
90
|
+
* @param {string | string[]} files
|
|
88
91
|
*/
|
|
89
92
|
|
|
90
93
|
function lint(files) {
|
|
91
|
-
for (const file of (
|
|
94
|
+
for (const file of arrify(files)) {
|
|
92
95
|
delete crossRunResultStorage[file];
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
rawResults.push(lintFiles(files).catch(e => {
|
|
96
|
-
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
compilation.errors.push(new StylelintError(e.message));
|
|
97
101
|
return [];
|
|
98
102
|
}));
|
|
99
103
|
}
|
|
@@ -124,9 +128,9 @@ function linter(key, options, compilation) {
|
|
|
124
128
|
warnings,
|
|
125
129
|
generateReportAsset
|
|
126
130
|
};
|
|
127
|
-
/**
|
|
128
|
-
* @param {Compilation} compilation
|
|
129
|
-
* @returns {Promise<void>}
|
|
131
|
+
/**
|
|
132
|
+
* @param {Compilation} compilation
|
|
133
|
+
* @returns {Promise<void>}
|
|
130
134
|
*/
|
|
131
135
|
|
|
132
136
|
async function generateReportAsset({
|
|
@@ -135,9 +139,9 @@ function linter(key, options, compilation) {
|
|
|
135
139
|
const {
|
|
136
140
|
outputReport
|
|
137
141
|
} = options;
|
|
138
|
-
/**
|
|
139
|
-
* @param {string} name
|
|
140
|
-
* @param {string | Buffer} content
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} name
|
|
144
|
+
* @param {string | Buffer} content
|
|
141
145
|
*/
|
|
142
146
|
|
|
143
147
|
const save = (name, content) =>
|
|
@@ -149,7 +153,7 @@ function linter(key, options, compilation) {
|
|
|
149
153
|
} = compiler.outputFileSystem; // ensure directory exists
|
|
150
154
|
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
|
|
151
155
|
|
|
152
|
-
mkdir(
|
|
156
|
+
mkdir(dirname(name), {
|
|
153
157
|
recursive: true
|
|
154
158
|
}, err => {
|
|
155
159
|
/* istanbul ignore if */
|
|
@@ -169,18 +173,18 @@ function linter(key, options, compilation) {
|
|
|
169
173
|
filePath
|
|
170
174
|
} = outputReport;
|
|
171
175
|
|
|
172
|
-
if (!
|
|
173
|
-
filePath =
|
|
176
|
+
if (!isAbsolute(filePath)) {
|
|
177
|
+
filePath = join(compiler.outputPath, filePath);
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
await save(filePath, content);
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
|
-
/**
|
|
181
|
-
* @param {FormatterFunction} formatter
|
|
182
|
-
* @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
|
|
183
|
-
* @returns {{errors?: StylelintError, warnings?: StylelintError}}
|
|
184
|
+
/**
|
|
185
|
+
* @param {FormatterFunction} formatter
|
|
186
|
+
* @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
|
|
187
|
+
* @returns {{errors?: StylelintError, warnings?: StylelintError}}
|
|
184
188
|
*/
|
|
185
189
|
|
|
186
190
|
|
|
@@ -189,11 +193,11 @@ function formatResults(formatter, results) {
|
|
|
189
193
|
let warnings;
|
|
190
194
|
|
|
191
195
|
if (results.warnings.length > 0) {
|
|
192
|
-
warnings = new
|
|
196
|
+
warnings = new StylelintError(formatter(results.warnings));
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
if (results.errors.length > 0) {
|
|
196
|
-
errors = new
|
|
200
|
+
errors = new StylelintError(formatter(results.errors));
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
return {
|
|
@@ -201,10 +205,10 @@ function formatResults(formatter, results) {
|
|
|
201
205
|
warnings
|
|
202
206
|
};
|
|
203
207
|
}
|
|
204
|
-
/**
|
|
205
|
-
* @param {Options} options
|
|
206
|
-
* @param {LintResult[]} results
|
|
207
|
-
* @returns {{errors: LintResult[], warnings: LintResult[]}}
|
|
208
|
+
/**
|
|
209
|
+
* @param {Options} options
|
|
210
|
+
* @param {LintResult[]} results
|
|
211
|
+
* @returns {{errors: LintResult[], warnings: LintResult[]}}
|
|
208
212
|
*/
|
|
209
213
|
|
|
210
214
|
|
|
@@ -236,10 +240,10 @@ function parseResults(options, results) {
|
|
|
236
240
|
warnings
|
|
237
241
|
};
|
|
238
242
|
}
|
|
239
|
-
/**
|
|
240
|
-
* @param {Stylelint} stylelint
|
|
241
|
-
* @param {FormatterType=} formatter
|
|
242
|
-
* @returns {FormatterFunction}
|
|
243
|
+
/**
|
|
244
|
+
* @param {Stylelint} stylelint
|
|
245
|
+
* @param {FormatterType=} formatter
|
|
246
|
+
* @returns {FormatterFunction}
|
|
243
247
|
*/
|
|
244
248
|
|
|
245
249
|
|
|
@@ -257,33 +261,33 @@ function loadFormatter(stylelint, formatter) {
|
|
|
257
261
|
|
|
258
262
|
return stylelint.formatters.string;
|
|
259
263
|
}
|
|
260
|
-
/**
|
|
261
|
-
* @param {LintResult[]} results
|
|
262
|
-
* @returns {LintResult[]}
|
|
264
|
+
/**
|
|
265
|
+
* @param {LintResult[]} results
|
|
266
|
+
* @returns {LintResult[]}
|
|
263
267
|
*/
|
|
264
268
|
|
|
265
269
|
|
|
266
270
|
function removeIgnoredWarnings(results) {
|
|
267
271
|
return results.filter(result => !result.ignored);
|
|
268
272
|
}
|
|
269
|
-
/**
|
|
270
|
-
* @param {Promise<LintResult[]>[]} results
|
|
271
|
-
* @returns {Promise<LintResult[]>}
|
|
273
|
+
/**
|
|
274
|
+
* @param {Promise<LintResult[]>[]} results
|
|
275
|
+
* @returns {Promise<LintResult[]>}
|
|
272
276
|
*/
|
|
273
277
|
|
|
274
278
|
|
|
275
279
|
async function flatten(results) {
|
|
276
|
-
/**
|
|
277
|
-
* @param {LintResult[]} acc
|
|
278
|
-
* @param {LintResult[]} list
|
|
280
|
+
/**
|
|
281
|
+
* @param {LintResult[]} acc
|
|
282
|
+
* @param {LintResult[]} list
|
|
279
283
|
*/
|
|
280
284
|
const flat = (acc, list) => [...acc, ...list];
|
|
281
285
|
|
|
282
286
|
return (await Promise.all(results)).reduce(flat, []);
|
|
283
287
|
}
|
|
284
|
-
/**
|
|
285
|
-
* @param {Compilation} compilation
|
|
286
|
-
* @returns {LintResultMap}
|
|
288
|
+
/**
|
|
289
|
+
* @param {Compilation} compilation
|
|
290
|
+
* @returns {LintResultMap}
|
|
287
291
|
*/
|
|
288
292
|
|
|
289
293
|
|
|
@@ -297,4 +301,6 @@ function getResultStorage({
|
|
|
297
301
|
}
|
|
298
302
|
|
|
299
303
|
return storage;
|
|
300
|
-
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
module.exports = linter;
|
package/dist/options.js
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.getOptions = getOptions;
|
|
7
|
-
exports.getStylelintOptions = getStylelintOptions;
|
|
3
|
+
const {
|
|
4
|
+
validate
|
|
5
|
+
} = require('schema-utils'); // @ts-ignore
|
|
8
6
|
|
|
9
|
-
var _schemaUtils = require("schema-utils");
|
|
10
|
-
|
|
11
|
-
var _options = _interopRequireDefault(require("./options.json"));
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
// @ts-ignore
|
|
16
7
|
|
|
8
|
+
const schema = require('./options.json');
|
|
17
9
|
/** @typedef {import("stylelint")} stylelint */
|
|
18
10
|
|
|
19
11
|
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
|
|
20
12
|
|
|
21
13
|
/** @typedef {import("stylelint").FormatterType} FormatterType */
|
|
22
14
|
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {Object} OutputReport
|
|
25
|
-
* @property {string=} filePath
|
|
26
|
-
* @property {FormatterType=} formatter
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} OutputReport
|
|
17
|
+
* @property {string=} filePath
|
|
18
|
+
* @property {FormatterType=} formatter
|
|
27
19
|
*/
|
|
28
20
|
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {Object} PluginOptions
|
|
31
|
-
* @property {string} context
|
|
32
|
-
* @property {boolean} emitError
|
|
33
|
-
* @property {boolean} emitWarning
|
|
34
|
-
* @property {string|string[]=} exclude
|
|
35
|
-
* @property {string|string[]} extensions
|
|
36
|
-
* @property {boolean} failOnError
|
|
37
|
-
* @property {boolean} failOnWarning
|
|
38
|
-
* @property {string|string[]} files
|
|
39
|
-
* @property {FormatterType} formatter
|
|
40
|
-
* @property {boolean} lintDirtyModulesOnly
|
|
41
|
-
* @property {boolean} quiet
|
|
42
|
-
* @property {string} stylelintPath
|
|
43
|
-
* @property {OutputReport} outputReport
|
|
44
|
-
* @property {number|boolean=} threads
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} PluginOptions
|
|
23
|
+
* @property {string} context
|
|
24
|
+
* @property {boolean} emitError
|
|
25
|
+
* @property {boolean} emitWarning
|
|
26
|
+
* @property {string|string[]=} exclude
|
|
27
|
+
* @property {string|string[]} extensions
|
|
28
|
+
* @property {boolean} failOnError
|
|
29
|
+
* @property {boolean} failOnWarning
|
|
30
|
+
* @property {string|string[]} files
|
|
31
|
+
* @property {FormatterType} formatter
|
|
32
|
+
* @property {boolean} lintDirtyModulesOnly
|
|
33
|
+
* @property {boolean} quiet
|
|
34
|
+
* @property {string} stylelintPath
|
|
35
|
+
* @property {OutputReport} outputReport
|
|
36
|
+
* @property {number|boolean=} threads
|
|
45
37
|
*/
|
|
46
38
|
|
|
47
39
|
/** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
|
|
48
40
|
|
|
49
|
-
/**
|
|
50
|
-
* @param {Options} pluginOptions
|
|
51
|
-
* @returns {Partial<PluginOptions>}
|
|
41
|
+
/**
|
|
42
|
+
* @param {Options} pluginOptions
|
|
43
|
+
* @returns {Partial<PluginOptions>}
|
|
52
44
|
*/
|
|
45
|
+
|
|
46
|
+
|
|
53
47
|
function getOptions(pluginOptions) {
|
|
54
48
|
const options = {
|
|
55
49
|
extensions: ['css', 'scss', 'sass'],
|
|
@@ -63,15 +57,15 @@ function getOptions(pluginOptions) {
|
|
|
63
57
|
} : {})
|
|
64
58
|
}; // @ts-ignore
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
validate(schema, options, {
|
|
67
61
|
name: 'Stylelint Webpack Plugin',
|
|
68
62
|
baseDataPath: 'options'
|
|
69
63
|
});
|
|
70
64
|
return options;
|
|
71
65
|
}
|
|
72
|
-
/**
|
|
73
|
-
* @param {Options} pluginOptions
|
|
74
|
-
* @returns {Partial<StylelintOptions>}
|
|
66
|
+
/**
|
|
67
|
+
* @param {Options} pluginOptions
|
|
68
|
+
* @returns {Partial<StylelintOptions>}
|
|
75
69
|
*/
|
|
76
70
|
|
|
77
71
|
|
|
@@ -83,7 +77,7 @@ function getStylelintOptions(pluginOptions) {
|
|
|
83
77
|
files,
|
|
84
78
|
formatter,
|
|
85
79
|
...stylelintOnlyOptions
|
|
86
|
-
} =
|
|
80
|
+
} = schema.properties; // No need to guard the for-in because schema.properties has hardcoded keys.
|
|
87
81
|
// eslint-disable-next-line guard-for-in
|
|
88
82
|
|
|
89
83
|
for (const option in stylelintOnlyOptions) {
|
|
@@ -92,4 +86,9 @@ function getStylelintOptions(pluginOptions) {
|
|
|
92
86
|
}
|
|
93
87
|
|
|
94
88
|
return stylelintOptions;
|
|
95
|
-
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = {
|
|
92
|
+
getOptions,
|
|
93
|
+
getStylelintOptions
|
|
94
|
+
};
|