stylelint-webpack-plugin 2.1.1 → 2.3.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/README.md CHANGED
@@ -61,12 +61,26 @@ Specify the config file location to be used by `stylelint`.
61
61
 
62
62
  A string indicating the root of your files.
63
63
 
64
+ ### `exclude`
65
+
66
+ - Type: `String|Array[String]`
67
+ - Default: `['node_modules', compiler.options.output.path]`
68
+
69
+ Specify the files and/or directories to exclude. Must be relative to `options.context`.
70
+
71
+ ### `extensions`
72
+
73
+ - Type: `String|Array[String]`
74
+ - Default: `['css', 'scss', 'sass']`
75
+
76
+ Specify extensions that should be checked.
77
+
64
78
  ### `files`
65
79
 
66
80
  - Type: `String|Array[String]`
67
- - Default: `'**/*.s?(a|c)ss'`
81
+ - Default: `null`
68
82
 
69
- Specify the glob pattern for finding files. Must be relative to `options.context`.
83
+ 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`.
70
84
 
71
85
  ### `fix`
72
86
 
@@ -96,6 +110,13 @@ Lint only changed files, skip lint on start.
96
110
 
97
111
  Path to `stylelint` instance that will be used for linting.
98
112
 
113
+ ### `threads`
114
+
115
+ - Type: `Boolean | Number`
116
+ - Default: `false`
117
+
118
+ 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.
119
+
99
120
  ### Errors and Warning
100
121
 
101
122
  **By default the plugin will auto adjust error reporting depending on stylelint errors/warnings counts.**
@@ -106,21 +127,21 @@ You can still force this behavior by using `emitError` **or** `emitWarning` opti
106
127
  - Type: `Boolean`
107
128
  - Default: `false`
108
129
 
109
- Will always return errors, if set to `true`.
130
+ The errors found will always be emitted, to disable set to `false`.
110
131
 
111
132
  #### `emitWarning`
112
133
 
113
134
  - Type: `Boolean`
114
135
  - Default: `false`
115
136
 
116
- Will always return warnings, if set to `true`.
137
+ The warnings found will always be emitted, to disable set to `false`.
117
138
 
118
139
  #### `failOnError`
119
140
 
120
141
  - Type: `Boolean`
121
142
  - Default: `false`
122
143
 
123
- Will cause the module build to fail if there are any errors, if set to `true`.
144
+ Will cause the module build to fail if there are any errors, to disable set to `false`.
124
145
 
125
146
  #### `failOnWarning`
126
147
 
@@ -136,6 +157,22 @@ Will cause the module build to fail if there are any warnings, if set to `true`.
136
157
 
137
158
  Will process and report errors only and ignore warnings, if set to `true`.
138
159
 
160
+ #### `outputReport`
161
+
162
+ - Type: `Boolean|Object`
163
+ - Default: `false`
164
+
165
+ Write the output of the errors to a file, for example a `json` file for use for reporting.
166
+ The `filePath` is relative to the webpack config: `output.path`.
167
+ You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.
168
+
169
+ ```js
170
+ {
171
+ filePath: 'path/to/file';
172
+ formatter: 'json';
173
+ }
174
+ ```
175
+
139
176
  ## Changelog
140
177
 
141
178
  [Changelog](CHANGELOG.md)
@@ -1,30 +1,2 @@
1
- /** @typedef {import('stylelint').LintResult} LintResult */
2
- /** @typedef {import('./getOptions').Options} Options */
3
- export default class StylelintError extends Error {
4
- /**
5
- * @param {Options} options
6
- * @param {Array<LintResult>} messages
7
- * @returns {StylelintError}
8
- */
9
- static format(
10
- { formatter }: Options,
11
- messages: Array<LintResult>
12
- ): StylelintError;
13
- /**
14
- * @param {Partial<string>} messages
15
- */
16
- constructor(messages: Partial<string>);
17
- }
18
- export type LintResult = import('stylelint').LintResult;
19
- export type Options = {
20
- context?: string | undefined;
21
- emitError?: boolean | undefined;
22
- emitWarning?: boolean | undefined;
23
- failOnError?: boolean | undefined;
24
- failOnWarning?: boolean | undefined;
25
- files: string | string[];
26
- formatter: TimerHandler;
27
- lintDirtyModulesOnly?: boolean | undefined;
28
- quiet?: boolean | undefined;
29
- stylelintPath: string;
30
- };
1
+ export default StylelintError;
2
+ declare class StylelintError extends Error {}
@@ -1,2 +1,3 @@
1
- declare const _exports: typeof import('.').default;
1
+ declare const _exports: typeof plugin.default;
2
2
  export = _exports;
3
+ import plugin = require('./index');
@@ -0,0 +1,72 @@
1
+ /// <reference types="stylelint" />
2
+ /**
3
+ * @param {string|undefined} key
4
+ * @param {Options} options
5
+ * @returns {Linter}
6
+ */
7
+ export default function getStylelint(
8
+ key: string | undefined,
9
+ { threads, ...options }: Options
10
+ ): Linter;
11
+ export type Stylelint = import('stylelint/node_modules/postcss').PluginCreator<
12
+ import('stylelint').PostcssPluginOptions
13
+ > & {
14
+ lint: (
15
+ options: import('stylelint').LinterOptions
16
+ ) => Promise<import('stylelint').LinterResult>;
17
+ rules: {
18
+ [k: string]: import('stylelint').Rule<any, any>;
19
+ };
20
+ formatters: {
21
+ [k: string]: import('stylelint').Formatter;
22
+ };
23
+ createPlugin: (
24
+ ruleName: string,
25
+ plugin: import('stylelint').Plugin<any, any>
26
+ ) => {
27
+ ruleName: string;
28
+ rule: import('stylelint').Rule<any, any>;
29
+ };
30
+ createLinter: (
31
+ options: import('stylelint').LinterOptions
32
+ ) => import('stylelint').InternalApi;
33
+ utils: {
34
+ report: (problem: import('stylelint').Problem) => void;
35
+ ruleMessages: <
36
+ T extends import('stylelint').RuleMessages,
37
+ R extends { [K in keyof T]: T[K] }
38
+ >(
39
+ ruleName: string,
40
+ messages: T
41
+ ) => R;
42
+ validateOptions: (
43
+ result: import('stylelint').PostcssResult,
44
+ ruleName: string,
45
+ ...optionDescriptions: import('stylelint').RuleOptions[]
46
+ ) => boolean;
47
+ checkAgainstRule: <T_1, O extends Object>(
48
+ options: {
49
+ ruleName: string;
50
+ ruleSettings: import('stylelint').ConfigRuleSettings<T_1, O>;
51
+ root: import('stylelint/node_modules/postcss').Root;
52
+ },
53
+ callback: (
54
+ warning: import('stylelint/node_modules/postcss').Warning
55
+ ) => void
56
+ ) => void;
57
+ };
58
+ };
59
+ export type LintResult = import('stylelint').LintResult;
60
+ export type Options = import('./options').Options;
61
+ export type AsyncTask = () => Promise<void>;
62
+ export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
63
+ export type Worker = JestWorker & {
64
+ lintFiles: LintTask;
65
+ };
66
+ export type Linter = {
67
+ stylelint: Stylelint;
68
+ lintFiles: LintTask;
69
+ cleanup: AsyncTask;
70
+ threads: number;
71
+ };
72
+ import { Worker as JestWorker } from 'jest-worker';
@@ -1,9 +1,30 @@
1
1
  export default StylelintWebpackPlugin;
2
2
  export type Compiler = import('webpack').Compiler;
3
- /** @typedef {import('webpack').Compiler} Compiler */
3
+ export type Module = import('webpack').Module;
4
+ export type Options = import('./options').Options;
5
+ export type FileSystemInfoEntry = Partial<
6
+ | {
7
+ timestamp: number;
8
+ }
9
+ | number
10
+ >;
4
11
  declare class StylelintWebpackPlugin {
5
- constructor(options?: {});
6
- options: import('./getOptions').Options;
12
+ /**
13
+ * @param {Options} options
14
+ */
15
+ constructor(options?: Options);
16
+ key: string;
17
+ options: Partial<import('./options').PluginOptions>;
18
+ /**
19
+ * @param {Compiler} compiler
20
+ */
21
+ run(compiler: Compiler): Promise<void>;
22
+ startTime: number;
23
+ /** @type {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} */
24
+ prevTimestamps: ReadonlyMap<
25
+ string,
26
+ 'ignore' | FileSystemInfoEntry | null | undefined
27
+ >;
7
28
  /**
8
29
  * @param {Compiler} compiler
9
30
  * @returns {void}
@@ -15,4 +36,21 @@ declare class StylelintWebpackPlugin {
15
36
  * @returns {string}
16
37
  */
17
38
  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[];
18
56
  }
@@ -1,47 +1,82 @@
1
- /** @typedef {import('stylelint').LinterResult} LinterResult */
2
- /** @typedef {import('stylelint').LintResult} LintResult */
3
- /** @typedef {import('webpack').Compiler} Compiler */
4
- /** @typedef {import('./getOptions').Options} Options */
1
+ /// <reference types="stylelint" />
5
2
  /**
6
- * @callback Lint
3
+ * @param {string|undefined} key
7
4
  * @param {Options} options
8
- * @returns {Promise<LinterResult>}
9
- */
10
- /**
11
- * @callback LinterCallback
12
- * @param {StylelintError | null=} error
13
- * @returns {void}
14
- */
15
- /**
16
- * @param {Lint} lint
17
- * @param {Options} options
18
- * @param {Compiler} compiler
19
- * @param {LinterCallback} callback
20
- * @returns {void}
5
+ * @param {Compilation} compilation
6
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
21
7
  */
22
8
  export default function linter(
23
- lint: Lint,
9
+ key: string | undefined,
24
10
  options: Options,
25
- compiler: Compiler,
26
- callback: LinterCallback
27
- ): void;
28
- export type LinterResult = import('stylelint').LinterResult;
11
+ compilation: Compilation
12
+ ): {
13
+ lint: Linter;
14
+ report: Reporter;
15
+ threads: number;
16
+ };
17
+ export type Stylelint = import('stylelint/node_modules/postcss').PluginCreator<
18
+ import('stylelint').PostcssPluginOptions
19
+ > & {
20
+ lint: (
21
+ options: import('stylelint').LinterOptions
22
+ ) => Promise<import('stylelint').LinterResult>;
23
+ rules: {
24
+ [k: string]: import('stylelint').Rule<any, any>;
25
+ };
26
+ formatters: {
27
+ [k: string]: import('stylelint').Formatter;
28
+ };
29
+ createPlugin: (
30
+ ruleName: string,
31
+ plugin: import('stylelint').Plugin<any, any>
32
+ ) => {
33
+ ruleName: string;
34
+ rule: import('stylelint').Rule<any, any>;
35
+ };
36
+ createLinter: (
37
+ options: import('stylelint').LinterOptions
38
+ ) => import('stylelint').InternalApi;
39
+ utils: {
40
+ report: (problem: import('stylelint').Problem) => void;
41
+ ruleMessages: <
42
+ T extends import('stylelint').RuleMessages,
43
+ R extends { [K in keyof T]: T[K] }
44
+ >(
45
+ ruleName: string,
46
+ messages: T
47
+ ) => R;
48
+ validateOptions: (
49
+ result: import('stylelint').PostcssResult,
50
+ ruleName: string,
51
+ ...optionDescriptions: import('stylelint').RuleOptions[]
52
+ ) => boolean;
53
+ checkAgainstRule: <T_1, O extends Object>(
54
+ options: {
55
+ ruleName: string;
56
+ ruleSettings: import('stylelint').ConfigRuleSettings<T_1, O>;
57
+ root: import('stylelint/node_modules/postcss').Root;
58
+ },
59
+ callback: (
60
+ warning: import('stylelint/node_modules/postcss').Warning
61
+ ) => void
62
+ ) => void;
63
+ };
64
+ };
29
65
  export type LintResult = import('stylelint').LintResult;
30
66
  export type Compiler = import('webpack').Compiler;
31
- export type Options = {
32
- context?: string | undefined;
33
- emitError?: boolean | undefined;
34
- emitWarning?: boolean | undefined;
35
- failOnError?: boolean | undefined;
36
- failOnWarning?: boolean | undefined;
37
- files: string | string[];
38
- formatter: TimerHandler;
39
- lintDirtyModulesOnly?: boolean | undefined;
40
- quiet?: boolean | undefined;
41
- stylelintPath: string;
67
+ export type Compilation = import('webpack').Compilation;
68
+ export type Options = import('./options').Options;
69
+ export type FormatterType = import('./options').FormatterType;
70
+ export type FormatterFunction = (results: LintResult[]) => string;
71
+ export type GenerateReport = (compilation: Compilation) => Promise<void>;
72
+ export type Report = {
73
+ errors?: StylelintError;
74
+ warnings?: StylelintError;
75
+ generateReportAsset?: GenerateReport;
76
+ };
77
+ export type Reporter = () => Promise<Report>;
78
+ export type Linter = (files: string | string[]) => void;
79
+ export type LintResultMap = {
80
+ [files: string]: import('stylelint').LintResult;
42
81
  };
43
- export type Lint = (options: Options) => Promise<LinterResult>;
44
- export type LinterCallback = (
45
- error?: (StylelintError | null) | undefined
46
- ) => void;
47
82
  import StylelintError from './StylelintError';
@@ -0,0 +1,110 @@
1
+ /// <reference types="stylelint" />
2
+ /** @typedef {import("stylelint")} stylelint */
3
+ /** @typedef {import("stylelint").LinterOptions} StylelintOptions */
4
+ /** @typedef {import("stylelint").FormatterType} FormatterType */
5
+ /**
6
+ * @typedef {Object} OutputReport
7
+ * @property {string=} filePath
8
+ * @property {FormatterType=} formatter
9
+ */
10
+ /**
11
+ * @typedef {Object} PluginOptions
12
+ * @property {string} context
13
+ * @property {boolean} emitError
14
+ * @property {boolean} emitWarning
15
+ * @property {string|string[]=} exclude
16
+ * @property {string|string[]} extensions
17
+ * @property {boolean} failOnError
18
+ * @property {boolean} failOnWarning
19
+ * @property {string|string[]} files
20
+ * @property {FormatterType} formatter
21
+ * @property {boolean} lintDirtyModulesOnly
22
+ * @property {boolean} quiet
23
+ * @property {string} stylelintPath
24
+ * @property {OutputReport} outputReport
25
+ * @property {number|boolean=} threads
26
+ */
27
+ /** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
28
+ /**
29
+ * @param {Options} pluginOptions
30
+ * @returns {Partial<PluginOptions>}
31
+ */
32
+ export function getOptions(pluginOptions: Options): Partial<PluginOptions>;
33
+ /**
34
+ * @param {Options} pluginOptions
35
+ * @returns {Partial<StylelintOptions>}
36
+ */
37
+ export function getStylelintOptions(
38
+ pluginOptions: Options
39
+ ): Partial<StylelintOptions>;
40
+ export type stylelint = import('stylelint/node_modules/postcss').PluginCreator<
41
+ import('stylelint').PostcssPluginOptions
42
+ > & {
43
+ lint: (
44
+ options: import('stylelint').LinterOptions
45
+ ) => Promise<import('stylelint').LinterResult>;
46
+ rules: {
47
+ [k: string]: import('stylelint').Rule<any, any>;
48
+ };
49
+ formatters: {
50
+ [k: string]: import('stylelint').Formatter;
51
+ };
52
+ createPlugin: (
53
+ ruleName: string,
54
+ plugin: import('stylelint').Plugin<any, any>
55
+ ) => {
56
+ ruleName: string;
57
+ rule: import('stylelint').Rule<any, any>;
58
+ };
59
+ createLinter: (
60
+ options: import('stylelint').LinterOptions
61
+ ) => import('stylelint').InternalApi;
62
+ utils: {
63
+ report: (problem: import('stylelint').Problem) => void;
64
+ ruleMessages: <
65
+ T extends import('stylelint').RuleMessages,
66
+ R extends { [K in keyof T]: T[K] }
67
+ >(
68
+ ruleName: string,
69
+ messages: T
70
+ ) => R;
71
+ validateOptions: (
72
+ result: import('stylelint').PostcssResult,
73
+ ruleName: string,
74
+ ...optionDescriptions: import('stylelint').RuleOptions[]
75
+ ) => boolean;
76
+ checkAgainstRule: <T_1, O extends Object>(
77
+ options: {
78
+ ruleName: string;
79
+ ruleSettings: import('stylelint').ConfigRuleSettings<T_1, O>;
80
+ root: import('stylelint/node_modules/postcss').Root;
81
+ },
82
+ callback: (
83
+ warning: import('stylelint/node_modules/postcss').Warning
84
+ ) => void
85
+ ) => void;
86
+ };
87
+ };
88
+ export type StylelintOptions = import('stylelint').LinterOptions;
89
+ export type FormatterType = import('stylelint').FormatterType;
90
+ export type OutputReport = {
91
+ filePath?: string | undefined;
92
+ formatter?: FormatterType | undefined;
93
+ };
94
+ export type PluginOptions = {
95
+ context: string;
96
+ emitError: boolean;
97
+ emitWarning: boolean;
98
+ exclude?: (string | string[]) | undefined;
99
+ extensions: string | string[];
100
+ failOnError: boolean;
101
+ failOnWarning: boolean;
102
+ files: string | string[];
103
+ formatter: FormatterType;
104
+ lintDirtyModulesOnly: boolean;
105
+ quiet: boolean;
106
+ stylelintPath: string;
107
+ outputReport: OutputReport;
108
+ threads?: (number | boolean) | undefined;
109
+ };
110
+ export type Options = Partial<PluginOptions & StylelintOptions>;
@@ -1,14 +1,19 @@
1
1
  /**
2
- * @param {Array<string> | string} files
2
+ * @param {string|(string|undefined)[]} files
3
3
  * @param {string} context
4
- * @returns {Array<string>}
4
+ * @returns {string[]}
5
5
  */
6
6
  export function parseFiles(
7
- files: Array<string> | string,
7
+ files: string | (string | undefined)[],
8
8
  context: string
9
- ): Array<string>;
9
+ ): string[];
10
10
  /**
11
- * @param {string} str
12
- * @returns {string}
11
+ * @param {string|string[]} patterns
12
+ * @param {string|string[]} extensions
13
+ * @returns {string[]}
13
14
  */
14
- export function replaceBackslashes(str: string): string;
15
+ export function parseFoldersToGlobs(
16
+ patterns: string | string[],
17
+ extensions?: string | string[]
18
+ ): string[];
19
+ export function jsonStringifyReplacerSortKeys(_: string, value: any): any;
@@ -0,0 +1,51 @@
1
+ /// <reference types="stylelint" />
2
+ export type Stylelint = import('stylelint/node_modules/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('stylelint/node_modules/postcss').Root;
43
+ },
44
+ callback: (
45
+ warning: import('stylelint/node_modules/postcss').Warning
46
+ ) => void
47
+ ) => void;
48
+ };
49
+ };
50
+ export type StylelintOptions = import('stylelint').LinterOptions;
51
+ export type Options = import('./options').Options;
@@ -5,32 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- /** @typedef {import('stylelint').LintResult} LintResult */
9
-
10
- /** @typedef {import('./getOptions').Options} Options */
11
8
  class StylelintError extends Error {
12
9
  /**
13
- * @param {Partial<string>} messages
10
+ * @param {string=} messages
14
11
  */
15
12
  constructor(messages) {
16
13
  super(messages);
17
14
  this.name = 'StylelintError';
18
15
  this.stack = '';
19
16
  }
20
- /**
21
- * @param {Options} options
22
- * @param {Array<LintResult>} messages
23
- * @returns {StylelintError}
24
- */
25
-
26
-
27
- static format({
28
- formatter
29
- }, messages) {
30
- // @ts-ignore
31
- return new StylelintError(formatter(messages));
32
- }
33
17
 
34
18
  }
35
19
 
36
- exports.default = StylelintError;
20
+ var _default = StylelintError;
21
+ exports.default = _default;