stylelint-webpack-plugin 2.2.1 → 2.3.2

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.
@@ -1,3 +1,49 @@
1
- export type Stylelint = typeof import('stylelint');
1
+ /// <reference types="stylelint" />
2
+ export type Stylelint = import('postcss').PluginCreator<
3
+ import('stylelint').PostcssPluginOptions
4
+ > & {
5
+ lint: (
6
+ options: import('stylelint').LinterOptions
7
+ ) => Promise<import('stylelint').LinterResult>;
8
+ rules: {
9
+ [k: string]: import('stylelint').Rule<any, any>;
10
+ };
11
+ formatters: {
12
+ [k: string]: import('stylelint').Formatter;
13
+ };
14
+ createPlugin: (
15
+ ruleName: string,
16
+ plugin: import('stylelint').Plugin<any, any>
17
+ ) => {
18
+ ruleName: string;
19
+ rule: import('stylelint').Rule<any, any>;
20
+ };
21
+ createLinter: (
22
+ options: import('stylelint').LinterOptions
23
+ ) => import('stylelint').InternalApi;
24
+ utils: {
25
+ report: (problem: import('stylelint').Problem) => void;
26
+ ruleMessages: <
27
+ T extends import('stylelint').RuleMessages,
28
+ R extends { [K in keyof T]: T[K] }
29
+ >(
30
+ ruleName: string,
31
+ messages: T
32
+ ) => R;
33
+ validateOptions: (
34
+ result: import('stylelint').PostcssResult,
35
+ ruleName: string,
36
+ ...optionDescriptions: import('stylelint').RuleOptions[]
37
+ ) => boolean;
38
+ checkAgainstRule: <T_1, O extends Object>(
39
+ options: {
40
+ ruleName: string;
41
+ ruleSettings: import('stylelint').ConfigRuleSettings<T_1, O>;
42
+ root: import('postcss').Root;
43
+ },
44
+ callback: (warning: import('postcss').Warning) => void
45
+ ) => void;
46
+ };
47
+ };
2
48
  export type StylelintOptions = import('stylelint').LinterOptions;
3
49
  export type Options = import('./options').Options;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  class StylelintError extends Error {
9
- /**
10
- * @param {string=} messages
9
+ /**
10
+ * @param {string=} messages
11
11
  */
12
12
  constructor(messages) {
13
13
  super(messages);
@@ -33,9 +33,9 @@ const cache = {};
33
33
 
34
34
  /** @typedef {{stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
35
35
 
36
- /**
37
- * @param {Options} options
38
- * @returns {Linter}
36
+ /**
37
+ * @param {Options} options
38
+ * @returns {Linter}
39
39
  */
40
40
 
41
41
  function loadStylelint(options) {
@@ -47,11 +47,11 @@ function loadStylelint(options) {
47
47
  threads: 1
48
48
  };
49
49
  }
50
- /**
51
- * @param {string|undefined} key
52
- * @param {number} poolSize
53
- * @param {Options} options
54
- * @returns {Linter}
50
+ /**
51
+ * @param {string|undefined} key
52
+ * @param {number} poolSize
53
+ * @param {Options} options
54
+ * @returns {Linter}
55
55
  */
56
56
 
57
57
 
@@ -94,10 +94,10 @@ function loadStylelintThreaded(key, poolSize, options) {
94
94
  };
95
95
  return context;
96
96
  }
97
- /**
98
- * @param {string|undefined} key
99
- * @param {Options} options
100
- * @returns {Linter}
97
+ /**
98
+ * @param {string|undefined} key
99
+ * @param {Options} options
100
+ * @returns {Linter}
101
101
  */
102
102
 
103
103
 
@@ -117,10 +117,10 @@ function getStylelint(key, {
117
117
 
118
118
  return cache[cacheKey];
119
119
  }
120
- /**
121
- * @param {string|undefined} key
122
- * @param {Options} options
123
- * @returns {string}
120
+ /**
121
+ * @param {string|undefined} key
122
+ * @param {Options} options
123
+ * @returns {string}
124
124
  */
125
125
 
126
126
 
package/dist/index.js CHANGED
@@ -35,19 +35,21 @@ const STYLELINT_PLUGIN = 'StylelintWebpackPlugin';
35
35
  let counter = 0;
36
36
 
37
37
  class StylelintWebpackPlugin {
38
- /**
39
- * @param {Options} options
38
+ /**
39
+ * @param {Options} options
40
40
  */
41
41
  constructor(options = {}) {
42
42
  this.key = STYLELINT_PLUGIN;
43
43
  this.options = (0, _options.getOptions)(options);
44
44
  this.run = this.run.bind(this);
45
45
  this.startTime = Date.now();
46
+ /** @type {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} */
47
+
46
48
  this.prevTimestamps = new Map();
47
49
  }
48
- /**
49
- * @param {Compiler} compiler
50
- * @returns {void}
50
+ /**
51
+ * @param {Compiler} compiler
52
+ * @returns {void}
51
53
  */
52
54
 
53
55
 
@@ -71,8 +73,8 @@ class StylelintWebpackPlugin {
71
73
  return this.run(c);
72
74
  });
73
75
  }
74
- /**
75
- * @param {Compiler} compiler
76
+ /**
77
+ * @param {Compiler} compiler
76
78
  */
77
79
 
78
80
 
@@ -159,10 +161,10 @@ class StylelintWebpackPlugin {
159
161
  }
160
162
  });
161
163
  }
162
- /**
163
- *
164
- * @param {Compiler} compiler
165
- * @returns {string}
164
+ /**
165
+ *
166
+ * @param {Compiler} compiler
167
+ * @returns {string}
166
168
  */
167
169
 
168
170
 
@@ -177,11 +179,11 @@ class StylelintWebpackPlugin {
177
179
 
178
180
  return this.options.context;
179
181
  }
180
- /**
181
- * @param {Compiler} compiler
182
- * @param {string[]} wanted
183
- * @param {string[]} exclude
184
- * @returns {string[]}
182
+ /**
183
+ * @param {Compiler} compiler
184
+ * @param {string[]} wanted
185
+ * @param {string[]} exclude
186
+ * @returns {string[]}
185
187
  */
186
188
  // eslint-disable-next-line no-unused-vars
187
189
 
@@ -212,18 +214,18 @@ class StylelintWebpackPlugin {
212
214
  ignore: exclude
213
215
  });
214
216
  }
215
- /**
216
- * @param {Map<string, null | FileSystemInfoEntry | "ignore">} fileTimestamps
217
- * @returns {string[]}
217
+ /**
218
+ * @param {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} fileTimestamps
219
+ * @returns {string[]}
218
220
  */
219
221
 
220
222
  /* istanbul ignore next */
221
223
 
222
224
 
223
225
  getChangedFiles(fileTimestamps) {
224
- /**
225
- * @param {null | FileSystemInfoEntry | "ignore"} fileSystemInfoEntry
226
- * @returns {Partial<number>}
226
+ /**
227
+ * @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
228
+ * @returns {Partial<number>}
227
229
  */
228
230
  const getTimestamps = fileSystemInfoEntry => {
229
231
  // @ts-ignore
@@ -235,10 +237,10 @@ class StylelintWebpackPlugin {
235
237
 
236
238
  return fileSystemInfoEntry;
237
239
  };
238
- /**
239
- * @param {string} filename
240
- * @param {null | FileSystemInfoEntry | "ignore"} fileSystemInfoEntry
241
- * @returns {boolean}
240
+ /**
241
+ * @param {string} filename
242
+ * @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
243
+ * @returns {boolean}
242
244
  */
243
245
 
244
246
 
package/dist/linter.js CHANGED
@@ -43,11 +43,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
43
 
44
44
  /** @type {WeakMap<Compiler, LintResultMap>} */
45
45
  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}}
46
+ /**
47
+ * @param {string|undefined} key
48
+ * @param {Options} options
49
+ * @param {Compilation} compilation
50
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
51
51
  */
52
52
 
53
53
  function linter(key, options, compilation) {
@@ -83,8 +83,8 @@ function linter(key, options, compilation) {
83
83
  report,
84
84
  threads
85
85
  };
86
- /**
87
- * @param {string | string[]} files
86
+ /**
87
+ * @param {string | string[]} files
88
88
  */
89
89
 
90
90
  function lint(files) {
@@ -105,7 +105,7 @@ function linter(key, options, compilation) {
105
105
  await cleanup();
106
106
 
107
107
  for (const result of results) {
108
- crossRunResultStorage[result.source] = result;
108
+ crossRunResultStorage[String(result.source)] = result;
109
109
  }
110
110
 
111
111
  results = Object.values(crossRunResultStorage); // do not analyze if there are no results or stylelint config
@@ -124,9 +124,9 @@ function linter(key, options, compilation) {
124
124
  warnings,
125
125
  generateReportAsset
126
126
  };
127
- /**
128
- * @param {Compilation} compilation
129
- * @returns {Promise<void>}
127
+ /**
128
+ * @param {Compilation} compilation
129
+ * @returns {Promise<void>}
130
130
  */
131
131
 
132
132
  async function generateReportAsset({
@@ -135,9 +135,9 @@ function linter(key, options, compilation) {
135
135
  const {
136
136
  outputReport
137
137
  } = options;
138
- /**
139
- * @param {string} name
140
- * @param {string | Buffer} content
138
+ /**
139
+ * @param {string} name
140
+ * @param {string | Buffer} content
141
141
  */
142
142
 
143
143
  const save = (name, content) =>
@@ -177,10 +177,10 @@ function linter(key, options, compilation) {
177
177
  }
178
178
  }
179
179
  }
180
- /**
181
- * @param {FormatterFunction} formatter
182
- * @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
183
- * @returns {{errors?: StylelintError, warnings?: StylelintError}}
180
+ /**
181
+ * @param {FormatterFunction} formatter
182
+ * @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
183
+ * @returns {{errors?: StylelintError, warnings?: StylelintError}}
184
184
  */
185
185
 
186
186
 
@@ -201,10 +201,10 @@ function formatResults(formatter, results) {
201
201
  warnings
202
202
  };
203
203
  }
204
- /**
205
- * @param {Options} options
206
- * @param {LintResult[]} results
207
- * @returns {{errors: LintResult[], warnings: LintResult[]}}
204
+ /**
205
+ * @param {Options} options
206
+ * @param {LintResult[]} results
207
+ * @returns {{errors: LintResult[], warnings: LintResult[]}}
208
208
  */
209
209
 
210
210
 
@@ -215,24 +215,20 @@ function parseResults(options, results) {
215
215
 
216
216
  const warnings = [];
217
217
  results.forEach(file => {
218
- if (fileHasErrors(file)) {
219
- const messages = file.warnings.filter(message => options.emitError && message.severity === 'error');
218
+ const fileErrors = file.warnings.filter(message => options.emitError && message.severity === 'error');
220
219
 
221
- if (messages.length > 0) {
222
- errors.push({ ...file,
223
- warnings: messages
224
- });
225
- }
220
+ if (fileErrors.length > 0) {
221
+ errors.push({ ...file,
222
+ warnings: fileErrors
223
+ });
226
224
  }
227
225
 
228
- if (fileHasWarnings(file)) {
229
- const messages = file.warnings.filter(message => options.emitWarning && message.severity === 'warning');
226
+ const fileWarnings = file.warnings.filter(message => options.emitWarning && message.severity === 'warning');
230
227
 
231
- if (messages.length > 0) {
232
- warnings.push({ ...file,
233
- warnings: messages
234
- });
235
- }
228
+ if (fileWarnings.length > 0) {
229
+ warnings.push({ ...file,
230
+ warnings: fileWarnings
231
+ });
236
232
  }
237
233
  });
238
234
  return {
@@ -240,28 +236,10 @@ function parseResults(options, results) {
240
236
  warnings
241
237
  };
242
238
  }
243
- /**
244
- * @param {LintResult} file
245
- * @returns {boolean}
246
- */
247
-
248
-
249
- function fileHasErrors(file) {
250
- return !!file.errored;
251
- }
252
- /**
253
- * @param {LintResult} file
254
- * @returns {boolean}
255
- */
256
-
257
-
258
- function fileHasWarnings(file) {
259
- return file.warnings && file.warnings.length > 0;
260
- }
261
- /**
262
- * @param {Stylelint} stylelint
263
- * @param {FormatterType=} formatter
264
- * @returns {FormatterFunction}
239
+ /**
240
+ * @param {Stylelint} stylelint
241
+ * @param {FormatterType=} formatter
242
+ * @returns {FormatterFunction}
265
243
  */
266
244
 
267
245
 
@@ -279,33 +257,33 @@ function loadFormatter(stylelint, formatter) {
279
257
 
280
258
  return stylelint.formatters.string;
281
259
  }
282
- /**
283
- * @param {LintResult[]} results
284
- * @returns {LintResult[]}
260
+ /**
261
+ * @param {LintResult[]} results
262
+ * @returns {LintResult[]}
285
263
  */
286
264
 
287
265
 
288
266
  function removeIgnoredWarnings(results) {
289
267
  return results.filter(result => !result.ignored);
290
268
  }
291
- /**
292
- * @param {Promise<LintResult[]>[]} results
293
- * @returns {Promise<LintResult[]>}
269
+ /**
270
+ * @param {Promise<LintResult[]>[]} results
271
+ * @returns {Promise<LintResult[]>}
294
272
  */
295
273
 
296
274
 
297
275
  async function flatten(results) {
298
- /**
299
- * @param {LintResult[]} acc
300
- * @param {LintResult[]} list
276
+ /**
277
+ * @param {LintResult[]} acc
278
+ * @param {LintResult[]} list
301
279
  */
302
280
  const flat = (acc, list) => [...acc, ...list];
303
281
 
304
282
  return (await Promise.all(results)).reduce(flat, []);
305
283
  }
306
- /**
307
- * @param {Compilation} compilation
308
- * @returns {LintResultMap}
284
+ /**
285
+ * @param {Compilation} compilation
286
+ * @returns {LintResultMap}
309
287
  */
310
288
 
311
289
 
package/dist/options.js CHANGED
@@ -20,35 +20,35 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
20
20
 
21
21
  /** @typedef {import("stylelint").FormatterType} FormatterType */
22
22
 
23
- /**
24
- * @typedef {Object} OutputReport
25
- * @property {string=} filePath
26
- * @property {FormatterType=} formatter
23
+ /**
24
+ * @typedef {Object} OutputReport
25
+ * @property {string=} filePath
26
+ * @property {FormatterType=} formatter
27
27
  */
28
28
 
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
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
45
45
  */
46
46
 
47
47
  /** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
48
48
 
49
- /**
50
- * @param {Options} pluginOptions
51
- * @returns {Partial<PluginOptions>}
49
+ /**
50
+ * @param {Options} pluginOptions
51
+ * @returns {Partial<PluginOptions>}
52
52
  */
53
53
  function getOptions(pluginOptions) {
54
54
  const options = {
@@ -69,9 +69,9 @@ function getOptions(pluginOptions) {
69
69
  });
70
70
  return options;
71
71
  }
72
- /**
73
- * @param {Options} pluginOptions
74
- * @returns {Partial<StylelintOptions>}
72
+ /**
73
+ * @param {Options} pluginOptions
74
+ * @returns {Partial<StylelintOptions>}
75
75
  */
76
76
 
77
77
 
package/dist/options.json CHANGED
@@ -1,80 +1,80 @@
1
- {
2
- "type": "object",
3
- "additionalProperties": true,
4
- "properties": {
5
- "context": {
6
- "description": "A string indicating the root of your files.",
7
- "type": "string"
8
- },
9
- "emitError": {
10
- "description": "The errors found will always be emitted, to disable set to `false`.",
11
- "type": "boolean"
12
- },
13
- "emitWarning": {
14
- "description": "The warnings found will always be emitted, to disable set to `false`.",
15
- "type": "boolean"
16
- },
17
- "exclude": {
18
- "description": "Specify the files and/or directories to exclude. Must be relative to `options.context`.",
19
- "anyOf": [{ "type": "string" }, { "type": "array" }]
20
- },
21
- "extensions": {
22
- "description": "Specify extensions that should be checked.",
23
- "anyOf": [{ "type": "string" }, { "type": "array" }]
24
- },
25
- "failOnError": {
26
- "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",
27
- "type": "boolean"
28
- },
29
- "failOnWarning": {
30
- "description": "Will cause the module build to fail if there are any warnings, if set to `true`.",
31
- "type": "boolean"
32
- },
33
- "files": {
34
- "description": "Specify directories, files, or globs. Must be relative to `options.context`. Directories are traveresed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.",
35
- "anyOf": [{ "type": "string" }, { "type": "array" }]
36
- },
37
- "formatter": {
38
- "description": "Specify the formatter that you would like to use to format your results.",
39
- "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
40
- },
41
- "lintDirtyModulesOnly": {
42
- "description": "Lint only changed files, skip lint on start.",
43
- "type": "boolean"
44
- },
45
- "quiet": {
46
- "description": "Will process and report errors only and ignore warnings, if set to `true`.",
47
- "type": "boolean"
48
- },
49
- "stylelintPath": {
50
- "description": "Path to `stylelint` instance that will be used for linting.",
51
- "type": "string"
52
- },
53
- "outputReport": {
54
- "description": "Write the output of the errors to a file, for example a `json` file for use for reporting.",
55
- "anyOf": [
56
- {
57
- "type": "boolean"
58
- },
59
- {
60
- "type": "object",
61
- "additionalProperties": false,
62
- "properties": {
63
- "filePath": {
64
- "description": "The `filePath` is relative to the webpack config: `output.path`.",
65
- "anyOf": [{ "type": "string" }]
66
- },
67
- "formatter": {
68
- "description": "You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.",
69
- "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
70
- }
71
- }
72
- }
73
- ]
74
- },
75
- "threads": {
76
- "description": "Set to true for an auto-selected pool size based on number of cpus. Set to a number greater than 1 to set an explicit pool size. Set to false, 1, or less to disable and only run in main process.",
77
- "anyOf": [{ "type": "number" }, { "type": "boolean" }]
78
- }
79
- }
80
- }
1
+ {
2
+ "type": "object",
3
+ "additionalProperties": true,
4
+ "properties": {
5
+ "context": {
6
+ "description": "A string indicating the root of your files.",
7
+ "type": "string"
8
+ },
9
+ "emitError": {
10
+ "description": "The errors found will always be emitted, to disable set to `false`.",
11
+ "type": "boolean"
12
+ },
13
+ "emitWarning": {
14
+ "description": "The warnings found will always be emitted, to disable set to `false`.",
15
+ "type": "boolean"
16
+ },
17
+ "exclude": {
18
+ "description": "Specify the files and/or directories to exclude. Must be relative to `options.context`.",
19
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
20
+ },
21
+ "extensions": {
22
+ "description": "Specify extensions that should be checked.",
23
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
24
+ },
25
+ "failOnError": {
26
+ "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",
27
+ "type": "boolean"
28
+ },
29
+ "failOnWarning": {
30
+ "description": "Will cause the module build to fail if there are any warnings, if set to `true`.",
31
+ "type": "boolean"
32
+ },
33
+ "files": {
34
+ "description": "Specify directories, files, or globs. Must be relative to `options.context`. Directories are traveresed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.",
35
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
36
+ },
37
+ "formatter": {
38
+ "description": "Specify the formatter that you would like to use to format your results.",
39
+ "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
40
+ },
41
+ "lintDirtyModulesOnly": {
42
+ "description": "Lint only changed files, skip lint on start.",
43
+ "type": "boolean"
44
+ },
45
+ "quiet": {
46
+ "description": "Will process and report errors only and ignore warnings, if set to `true`.",
47
+ "type": "boolean"
48
+ },
49
+ "stylelintPath": {
50
+ "description": "Path to `stylelint` instance that will be used for linting.",
51
+ "type": "string"
52
+ },
53
+ "outputReport": {
54
+ "description": "Write the output of the errors to a file, for example a `json` file for use for reporting.",
55
+ "anyOf": [
56
+ {
57
+ "type": "boolean"
58
+ },
59
+ {
60
+ "type": "object",
61
+ "additionalProperties": false,
62
+ "properties": {
63
+ "filePath": {
64
+ "description": "The `filePath` is relative to the webpack config: `output.path`.",
65
+ "anyOf": [{ "type": "string" }]
66
+ },
67
+ "formatter": {
68
+ "description": "You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.",
69
+ "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
70
+ }
71
+ }
72
+ }
73
+ ]
74
+ },
75
+ "threads": {
76
+ "description": "Set to true for an auto-selected pool size based on number of cpus. Set to a number greater than 1 to set an explicit pool size. Set to false, 1, or less to disable and only run in main process.",
77
+ "anyOf": [{ "type": "number" }, { "type": "boolean" }]
78
+ }
79
+ }
80
+ }