stylelint-webpack-plugin 2.3.2 → 3.1.1

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/README.md CHANGED
@@ -1,199 +1,201 @@
1
- <div align="center">
2
- <a href="https://github.com/stylelint/stylelint"><img width="200" height="200" src="https://cdn.worldvectorlogo.com/logos/stylelint.svg"></a>
3
- <a href="https://github.com/webpack/webpack"><img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"></a>
4
- </div>
5
-
6
- [![npm][npm]][npm-url]
7
- [![node][node]][node-url]
8
- [![deps][deps]][deps-url]
9
- [![tests][tests]][tests-url]
10
- [![coverage][cover]][cover-url]
11
- [![chat][chat]][chat-url]
12
- [![size][size]][size-url]
13
-
14
- # stylelint-webpack-plugin
15
-
16
- > A Stylelint plugin for webpack
17
-
18
- ## Install
19
-
20
- ```bash
21
- npm install stylelint-webpack-plugin@2 --save-dev
22
- ```
23
-
24
- **Note**: You also need to install `stylelint` from npm, if you haven't already:
25
-
26
- ```bash
27
- npm install stylelint --save-dev
28
- ```
29
-
30
- **Note**: If you are using Stylelint 13 rather than 14+, you might also need to install `@types/stylelint` as a dev dependency if getting stylelint related type errors.
31
-
32
- ## Usage
33
-
34
- In your webpack configuration:
35
-
36
- ```js
37
- const StylelintPlugin = require('stylelint-webpack-plugin');
38
-
39
- module.exports = {
40
- // ...
41
- plugins: [new StylelintPlugin(options)],
42
- // ...
43
- };
44
- ```
45
-
46
- ## Options
47
-
48
- See [stylelint's options](http://stylelint.io/user-guide/node-api/#options) for the complete list of options available. These options are passed through to the `stylelint` directly.
49
-
50
- ### `configFile`
51
-
52
- - Type: `String`
53
- - Default: `undefined`
54
-
55
- Specify the config file location to be used by `stylelint`.
56
-
57
- **Note:** By default this is [handled by `stylelint`](http://stylelint.io/user-guide/configuration/).
58
-
59
- ### `context`
60
-
61
- - Type: `String`
62
- - Default: `compiler.context`
63
-
64
- A string indicating the root of your files.
65
-
66
- ### `exclude`
67
-
68
- - Type: `String|Array[String]`
69
- - Default: `['node_modules', compiler.options.output.path]`
70
-
71
- Specify the files and/or directories to exclude. Must be relative to `options.context`.
72
-
73
- ### `extensions`
74
-
75
- - Type: `String|Array[String]`
76
- - Default: `['css', 'scss', 'sass']`
77
-
78
- Specify extensions that should be checked.
79
-
80
- ### `files`
81
-
82
- - Type: `String|Array[String]`
83
- - Default: `null`
84
-
85
- 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`.
86
-
87
- ### `fix`
88
-
89
- - Type: `Boolean`
90
- - Default: `false`
91
-
92
- If `true`, `stylelint` will fix as many errors as possible. The fixes are made to the actual source files. All unfixed errors will be reported. See [Autofixing errors](https://stylelint.io/user-guide/cli#autofixing-errors) docs.
93
-
94
- ### `formatter`
95
-
96
- - Type: `String|Function`
97
- - Default: `'string'`
98
-
99
- Specify the formatter that you would like to use to format your results. See [formatter option](https://stylelint.io/user-guide/node-api#formatter).
100
-
101
- ### `lintDirtyModulesOnly`
102
-
103
- - Type: `Boolean`
104
- - Default: `false`
105
-
106
- Lint only changed files, skip lint on start.
107
-
108
- ### `stylelintPath`
109
-
110
- - Type: `String`
111
- - Default: `stylelint`
112
-
113
- Path to `stylelint` instance that will be used for linting.
114
-
115
- ### `threads`
116
-
117
- - Type: `Boolean | Number`
118
- - Default: `false`
119
-
120
- 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.
121
-
122
- ### Errors and Warning
123
-
124
- **By default the plugin will auto adjust error reporting depending on stylelint errors/warnings counts.**
125
- You can still force this behavior by using `emitError` **or** `emitWarning` options:
126
-
127
- #### `emitError`
128
-
129
- - Type: `Boolean`
130
- - Default: `false`
131
-
132
- The errors found will always be emitted, to disable set to `false`.
133
-
134
- #### `emitWarning`
135
-
136
- - Type: `Boolean`
137
- - Default: `false`
138
-
139
- The warnings found will always be emitted, to disable set to `false`.
140
-
141
- #### `failOnError`
142
-
143
- - Type: `Boolean`
144
- - Default: `false`
145
-
146
- Will cause the module build to fail if there are any errors, to disable set to `false`.
147
-
148
- #### `failOnWarning`
149
-
150
- - Type: `Boolean`
151
- - Default: `false`
152
-
153
- Will cause the module build to fail if there are any warnings, if set to `true`.
154
-
155
- #### `quiet`
156
-
157
- - Type: `Boolean`
158
- - Default: `false`
159
-
160
- Will process and report errors only and ignore warnings, if set to `true`.
161
-
162
- #### `outputReport`
163
-
164
- - Type: `Boolean|Object`
165
- - Default: `false`
166
-
167
- Write the output of the errors to a file, for example a `json` file for use for reporting.
168
- The `filePath` is relative to the webpack config: `output.path`.
169
- You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.
170
-
171
- ```js
172
- {
173
- filePath: 'path/to/file';
174
- formatter: 'json';
175
- }
176
- ```
177
-
178
- ## Changelog
179
-
180
- [Changelog](CHANGELOG.md)
181
-
182
- ## License
183
-
184
- [MIT](./LICENSE)
185
-
186
- [npm]: https://img.shields.io/npm/v/stylelint-webpack-plugin/2x.svg
187
- [npm-url]: https://npmjs.com/package/stylelint-webpack-plugin/v/2x
188
- [node]: https://img.shields.io/node/v/stylelint-webpack-plugin/2x.svg
189
- [node-url]: https://nodejs.org
190
- [deps]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin.svg
191
- [deps-url]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin
192
- [tests]: https://github.com/webpack-contrib/stylelint-webpack-plugin/workflows/stylelint-webpack-plugin/badge.svg?branch=2.x
193
- [tests-url]: https://github.com/webpack-contrib/stylelint-webpack-plugin/actions
194
- [cover]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/2.x/graph/badge.svg
195
- [cover-url]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/2.x
196
- [chat]: https://badges.gitter.im/webpack/webpack.svg
197
- [chat-url]: https://gitter.im/webpack/webpack
198
- [size]: https://packagephobia.now.sh/badge?p=stylelint-webpack-plugin
199
- [size-url]: https://packagephobia.now.sh/result?p=stylelint-webpack-plugin
1
+ <div align="center">
2
+ <a href="https://github.com/stylelint/stylelint"><img width="200" height="200" src="https://cdn.worldvectorlogo.com/logos/stylelint.svg"></a>
3
+ <a href="https://github.com/webpack/webpack"><img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"></a>
4
+ </div>
5
+
6
+ [![npm][npm]][npm-url]
7
+ [![node][node]][node-url]
8
+ [![deps][deps]][deps-url]
9
+ [![tests][tests]][tests-url]
10
+ [![coverage][cover]][cover-url]
11
+ [![chat][chat]][chat-url]
12
+ [![size][size]][size-url]
13
+
14
+ # stylelint-webpack-plugin
15
+
16
+ > This is stylelint-webpack-plugin 3.0 which works only with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/stylelint-webpack-plugin/tree/2.x).
17
+
18
+ This plugin uses [`stylelint`](https://stylelint.io/) that helps you avoid errors and enforce conventions in your styles.
19
+
20
+ ## Getting Started
21
+
22
+ To begin, you'll need to install `stylelint-webpack-plugin`:
23
+
24
+ ```bash
25
+ npm install stylelint-webpack-plugin --save-dev
26
+ ```
27
+
28
+ **Note**: You also need to install `stylelint >= 13` from npm, if you haven't already:
29
+
30
+ ```bash
31
+ npm install stylelint --save-dev
32
+ ```
33
+
34
+ **Note**: If you are using Stylelint 13 rather than 14+, you might also need to install `@types/stylelint` as a dev dependency if getting stylelint related type errors.
35
+
36
+ Then add the plugin to your webpack config. For example:
37
+
38
+ ```js
39
+ const StylelintPlugin = require('stylelint-webpack-plugin');
40
+
41
+ module.exports = {
42
+ // ...
43
+ plugins: [new StylelintPlugin(options)],
44
+ // ...
45
+ };
46
+ ```
47
+
48
+ ## Options
49
+
50
+ See [stylelint's options](https://stylelint.io/user-guide/usage/node-api#options) for the complete list of options available. These options are passed through to the `stylelint` directly.
51
+
52
+ ### `configFile`
53
+
54
+ - Type: `String`
55
+ - Default: `undefined`
56
+
57
+ Specify the config file location to be used by `stylelint`.
58
+
59
+ **Note:** By default this is [handled by `stylelint`](https://stylelint.io/user-guide/configure).
60
+
61
+ ### `context`
62
+
63
+ - Type: `String`
64
+ - Default: `compiler.context`
65
+
66
+ A string indicating the root of your files.
67
+
68
+ ### `exclude`
69
+
70
+ - Type: `String|Array[String]`
71
+ - Default: `['node_modules', compiler.options.output.path]`
72
+
73
+ Specify the files and/or directories to exclude. Must be relative to `options.context`.
74
+
75
+ ### `extensions`
76
+
77
+ - Type: `String|Array[String]`
78
+ - Default: `['css', 'scss', 'sass']`
79
+
80
+ Specify extensions that should be checked.
81
+
82
+ ### `files`
83
+
84
+ - Type: `String|Array[String]`
85
+ - Default: `null`
86
+
87
+ 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`.
88
+
89
+ ### `fix`
90
+
91
+ - Type: `Boolean`
92
+ - Default: `false`
93
+
94
+ If `true`, `stylelint` will fix as many errors as possible. The fixes are made to the actual source files. All unfixed errors will be reported. See [Autofixing errors](https://stylelint.io/user-guide/usage/options#fix) docs.
95
+
96
+ ### `formatter`
97
+
98
+ - Type: `String|Function`
99
+ - Default: `'string'`
100
+
101
+ Specify the formatter that you would like to use to format your results. See [formatter option](https://stylelint.io/user-guide/usage/options#formatter).
102
+
103
+ ### `lintDirtyModulesOnly`
104
+
105
+ - Type: `Boolean`
106
+ - Default: `false`
107
+
108
+ Lint only changed files, skip lint on start.
109
+
110
+ ### `stylelintPath`
111
+
112
+ - Type: `String`
113
+ - Default: `stylelint`
114
+
115
+ Path to `stylelint` instance that will be used for linting.
116
+
117
+ ### `threads`
118
+
119
+ - Type: `Boolean | Number`
120
+ - Default: `false`
121
+
122
+ 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.
123
+
124
+ ### Errors and Warning
125
+
126
+ **By default the plugin will auto adjust error reporting depending on stylelint errors/warnings counts.**
127
+ You can still force this behavior by using `emitError` **or** `emitWarning` options:
128
+
129
+ #### `emitError`
130
+
131
+ - Type: `Boolean`
132
+ - Default: `true`
133
+
134
+ The errors found will always be emitted, to disable set to `false`.
135
+
136
+ #### `emitWarning`
137
+
138
+ - Type: `Boolean`
139
+ - Default: `true`
140
+
141
+ The warnings found will always be emitted, to disable set to `false`.
142
+
143
+ #### `failOnError`
144
+
145
+ - Type: `Boolean`
146
+ - Default: `true`
147
+
148
+ Will cause the module build to fail if there are any errors, to disable set to `false`.
149
+
150
+ #### `failOnWarning`
151
+
152
+ - Type: `Boolean`
153
+ - Default: `false`
154
+
155
+ Will cause the module build to fail if there are any warnings, if set to `true`.
156
+
157
+ #### `quiet`
158
+
159
+ - Type: `Boolean`
160
+ - Default: `false`
161
+
162
+ Will process and report errors only and ignore warnings, if set to `true`.
163
+
164
+ #### `outputReport`
165
+
166
+ - Type: `Boolean|Object`
167
+ - Default: `false`
168
+
169
+ Write the output of the errors to a file, for example a `json` file for use for reporting.
170
+ The `filePath` is relative to the webpack config: `output.path`.
171
+ You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.
172
+
173
+ ```js
174
+ {
175
+ filePath: 'path/to/file';
176
+ formatter: 'json';
177
+ }
178
+ ```
179
+
180
+ ## Changelog
181
+
182
+ [Changelog](CHANGELOG.md)
183
+
184
+ ## License
185
+
186
+ [MIT](./LICENSE)
187
+
188
+ [npm]: https://img.shields.io/npm/v/stylelint-webpack-plugin.svg
189
+ [npm-url]: https://npmjs.com/package/stylelint-webpack-plugin
190
+ [node]: https://img.shields.io/node/v/stylelint-webpack-plugin.svg
191
+ [node-url]: https://nodejs.org
192
+ [deps]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin.svg
193
+ [deps-url]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin
194
+ [tests]: https://github.com/webpack-contrib/stylelint-webpack-plugin/workflows/stylelint-webpack-plugin/badge.svg
195
+ [tests-url]: https://github.com/webpack-contrib/stylelint-webpack-plugin/actions
196
+ [cover]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/master/graph/badge.svg
197
+ [cover-url]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin
198
+ [chat]: https://badges.gitter.im/webpack/webpack.svg
199
+ [chat-url]: https://gitter.im/webpack/webpack
200
+ [size]: https://packagephobia.now.sh/badge?p=stylelint-webpack-plugin
201
+ [size-url]: https://packagephobia.now.sh/result?p=stylelint-webpack-plugin
@@ -58,13 +58,12 @@ export type LintResult = import('stylelint').LintResult;
58
58
  export type Options = import('./options').Options;
59
59
  export type AsyncTask = () => Promise<void>;
60
60
  export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
61
- export type Worker = JestWorker & {
62
- lintFiles: LintTask;
63
- };
64
61
  export type Linter = {
65
62
  stylelint: Stylelint;
66
63
  lintFiles: LintTask;
67
64
  cleanup: AsyncTask;
68
65
  threads: number;
69
66
  };
70
- import { Worker as JestWorker } from 'jest-worker';
67
+ export type Worker = import('jest-worker').Worker & {
68
+ lintFiles: LintTask;
69
+ };
@@ -20,11 +20,7 @@ declare class StylelintWebpackPlugin {
20
20
  */
21
21
  run(compiler: Compiler): Promise<void>;
22
22
  startTime: number;
23
- /** @type {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} */
24
- prevTimestamps: ReadonlyMap<
25
- string,
26
- 'ignore' | FileSystemInfoEntry | null | undefined
27
- >;
23
+ prevTimestamps: Map<any, any>;
28
24
  /**
29
25
  * @param {Compiler} compiler
30
26
  * @returns {void}
@@ -36,21 +32,4 @@ declare class StylelintWebpackPlugin {
36
32
  * @returns {string}
37
33
  */
38
34
  getContext(compiler: Compiler): string;
39
- /**
40
- * @param {Compiler} compiler
41
- * @param {string[]} wanted
42
- * @param {string[]} exclude
43
- * @returns {string[]}
44
- */
45
- getFiles(compiler: Compiler, wanted: string[], exclude: string[]): string[];
46
- /**
47
- * @param {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} fileTimestamps
48
- * @returns {string[]}
49
- */
50
- getChangedFiles(
51
- fileTimestamps: ReadonlyMap<
52
- string,
53
- 'ignore' | FileSystemInfoEntry | null | undefined
54
- >
55
- ): string[];
56
35
  }
@@ -1,12 +1,35 @@
1
1
  /**
2
- * @param {string|(string|undefined)[]} files
2
+ * @template T
3
+ * @param {T} value
4
+ * @return {
5
+ T extends (null | undefined)
6
+ ? []
7
+ : T extends string
8
+ ? [string]
9
+ : T extends readonly unknown[]
10
+ ? T
11
+ : T extends Iterable<infer T>
12
+ ? T[]
13
+ : [T]
14
+ }
15
+ */
16
+ export function arrify<T>(
17
+ value: T
18
+ ): T extends null | undefined
19
+ ? []
20
+ : T extends string
21
+ ? [string]
22
+ : T extends readonly unknown[]
23
+ ? T
24
+ : T extends Iterable<infer T_1>
25
+ ? T_1[]
26
+ : [T];
27
+ /**
28
+ * @param {string|string[]} files
3
29
  * @param {string} context
4
30
  * @returns {string[]}
5
31
  */
6
- export function parseFiles(
7
- files: string | (string | undefined)[],
8
- context: string
9
- ): string[];
32
+ export function parseFiles(files: string | string[], context: string): string[];
10
33
  /**
11
34
  * @param {string|string[]} patterns
12
35
  * @param {string|string[]} extensions
@@ -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);
@@ -29,13 +29,13 @@ const cache = {};
29
29
 
30
30
  /** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
31
31
 
32
- /** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
33
-
34
32
  /** @typedef {{stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
35
33
 
36
- /**
37
- * @param {Options} options
38
- * @returns {Linter}
34
+ /** @typedef {import('jest-worker').Worker & {lintFiles: LintTask}} Worker */
35
+
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
 
@@ -66,11 +66,8 @@ function loadStylelintThreaded(key, poolSize, options) {
66
66
  setupArgs: [options, (0, _options.getStylelintOptions)(options)]
67
67
  };
68
68
  const local = loadStylelint(options);
69
- /** @type {Worker?} */
70
- // prettier-ignore
71
-
72
69
  let worker =
73
- /** @type {Worker} */
70
+ /** @type {Worker?} */
74
71
  new _jestWorker.Worker(source, workerOptions);
75
72
  /** @type {Linter} */
76
73
 
@@ -94,10 +91,10 @@ function loadStylelintThreaded(key, poolSize, options) {
94
91
  };
95
92
  return context;
96
93
  }
97
- /**
98
- * @param {string|undefined} key
99
- * @param {Options} options
100
- * @returns {Linter}
94
+ /**
95
+ * @param {string|undefined} key
96
+ * @param {Options} options
97
+ * @returns {Linter}
101
98
  */
102
99
 
103
100
 
@@ -117,10 +114,10 @@ function getStylelint(key, {
117
114
 
118
115
  return cache[cacheKey];
119
116
  }
120
- /**
121
- * @param {string|undefined} key
122
- * @param {Options} options
123
- * @returns {string}
117
+ /**
118
+ * @param {string|undefined} key
119
+ * @param {Options} options
120
+ * @returns {string}
124
121
  */
125
122
 
126
123