eslint-config-webpack 4.15.0 → 5.0.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 +48 -4
- package/configs/browser.js +70 -7
- package/configs/index.js +7 -6
- package/configs/javascript.js +746 -151
- package/configs/json.js +72 -0
- package/configs/markdown.js +111 -6
- package/configs/node.js +78 -23
- package/configs/performance.js +8 -0
- package/configs/react.js +7 -19
- package/configs/stylistic.js +17 -0
- package/configs/{jest.js → test.js} +65 -5
- package/configs/typescript.js +39 -10
- package/configs/utils/code-files.js +20 -0
- package/configs/utils/get-es-version-from-node.js +9 -4
- package/configs/utils/get-json-file.js +1 -5
- package/configs/utils/is-jest-installed.js +20 -0
- package/configs/utils/is-typescript-installed.js +3 -3
- package/configs.js +47 -31
- package/package.json +31 -26
- package/plugins/package-json/index.js +0 -5
- package/plugins/package-json/rules/order-properties.js +8 -18
- package/plugins/performance/index.js +60 -0
- package/plugins/performance/rules/no-case-insensitive-unicode-range.js +214 -0
- package/plugins/performance/rules/require-precompiled-schema.js +414 -0
- package/plugins/webpack/index.js +0 -1
- package/plugins/webpack/rules/comment-length.js +1 -3
- package/plugins/webpack/rules/format-schema.js +18 -16
- package/plugins/webpack/rules/inherit-jsdoc.js +2 -3
- package/plugins/webpack/rules/no-duplicate-import-tag.js +3 -4
- package/plugins/webpack/rules/no-unused-import-tag.js +8 -11
- package/plugins/webpack/rules/prefer-import-tag.js +1 -2
- package/plugins/webpack/rules/require-license-comment.js +3 -5
- package/plugins/webpack/rules/valid-schema.js +9 -13
- package/plugins/webpack/utils/import-tags.js +4 -3
- package/configs/package-json.js +0 -8
package/README.md
CHANGED
|
@@ -4,17 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
|
|
7
|
-
<img width="200" height="200"
|
|
7
|
+
<img width="200" height="200" alt="ESLint logo"
|
|
8
8
|
src="https://cdn.worldvectorlogo.com/logos/eslint.svg">
|
|
9
9
|
<a href="https://github.com/webpack/webpack">
|
|
10
|
-
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
|
|
10
|
+
<img width="200" height="200" alt="webpack logo" src="https://webpack.js.org/assets/icon-square-big.svg">
|
|
11
11
|
</a>
|
|
12
12
|
<h1>ESLint Config Webpack</h1>
|
|
13
13
|
<p>Provides Webpacks's eslint config as an extensible shared config.<p>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
# eslint-config-webpack
|
|
17
|
-
|
|
18
16
|
## Install
|
|
19
17
|
|
|
20
18
|
```bash
|
|
@@ -84,6 +82,52 @@ export default defineConfig([
|
|
|
84
82
|
]);
|
|
85
83
|
```
|
|
86
84
|
|
|
85
|
+
### Tests with `node:test`
|
|
86
|
+
|
|
87
|
+
Every recommended config includes `node-test/recommended`: the recommended rules of [`eslint-node-test`](https://github.com/sindresorhus/eslint-node-test) for tests written with the built-in Node.js test runner, with the same choices as for Jest (`test` at the top level and `it` inside `describe`, lowercase titles except for `describe`, no commented-out tests; conditional assertions and `done` callbacks are allowed). Its rules only apply to files that import `node:test` (assertion rules also to files that import `node:assert`), so it needs no test file patterns. It can also be extended on its own:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
import { defineConfig } from "eslint/config";
|
|
91
|
+
import configs from "eslint-config-webpack/configs.js";
|
|
92
|
+
|
|
93
|
+
export default defineConfig([
|
|
94
|
+
{
|
|
95
|
+
extends: [configs["node-test/recommended"]],
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### JSDoc `@import` tags
|
|
101
|
+
|
|
102
|
+
When `typescript` is installed, the `typescript/jsdoc` config of every recommended config checks JSDoc type imports:
|
|
103
|
+
|
|
104
|
+
| Rule | What it checks |
|
|
105
|
+
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
106
|
+
| `webpack/prefer-import-tag` | `/** @import { Node } from "estree" */` instead of a `@typedef` that only aliases an `import()`, like `{import("estree").Node} Node` (autofixable). |
|
|
107
|
+
| `webpack/no-duplicate-import-tag` | One `@import` per module in a file. |
|
|
108
|
+
| `webpack/no-unused-import-tag` | Every `@import` binding is referenced (autofixable). |
|
|
109
|
+
|
|
110
|
+
### Performance
|
|
111
|
+
|
|
112
|
+
Every recommended config includes `performance/recommended`: rules that catch code
|
|
113
|
+
which is correct but slow. It can also be extended on its own:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { defineConfig } from "eslint/config";
|
|
117
|
+
import configs from "eslint-config-webpack/configs.js";
|
|
118
|
+
|
|
119
|
+
export default defineConfig([
|
|
120
|
+
{
|
|
121
|
+
extends: [configs["performance/recommended"]],
|
|
122
|
+
},
|
|
123
|
+
]);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Rule | What it checks |
|
|
127
|
+
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
128
|
+
| `performance/no-case-insensitive-unicode-range` | No `i` flag on a regex with a character range past ASCII or a `\p{…}` escape. V8 case-folds each such range when it compiles the regex, about 0.1–0.4 ms per range; spell the ASCII letters in both cases (`a-zA-Z`) instead. Checks `new RegExp(…)` built from constants too. |
|
|
129
|
+
| `performance/require-precompiled-schema` | A precompiled check when validating options against a schema: `compiler.validate(schema, options, configuration, check)` in plugins, `this.getOptions(schema, check)` in loaders and `validate(schema, options, configuration, check)` from `schema-utils`. Without it `ajv` is loaded and compiles the schema on every start, about 150 ms for the first one; generate the check with `npx schema-utils precompile options.json`. Suggests passing `options.check.js` when it already exists next to a required schema. |
|
|
130
|
+
|
|
87
131
|
### Webpack-specific configs
|
|
88
132
|
|
|
89
133
|
Three opt-in configs cover conventions only webpack's own repositories need.
|
package/configs/browser.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import importPlugin from "eslint-plugin-import";
|
|
1
|
+
import importPlugin from "eslint-plugin-import-x";
|
|
2
2
|
import unicornPlugin from "eslint-plugin-unicorn";
|
|
3
3
|
import globals from "globals";
|
|
4
|
+
import { codeFiles, codeIgnores } from "./utils/code-files.js";
|
|
4
5
|
|
|
5
6
|
/** @type {import("eslint").Linter.Config} */
|
|
6
7
|
const recommendedBrowserOutdatedScriptConfig = {
|
|
7
8
|
name: "browser/recommended-outdated-script",
|
|
9
|
+
files: codeFiles,
|
|
10
|
+
ignores: codeIgnores,
|
|
8
11
|
languageOptions: {
|
|
9
12
|
sourceType: "script",
|
|
10
13
|
globals: {
|
|
@@ -16,6 +19,8 @@ const recommendedBrowserOutdatedScriptConfig = {
|
|
|
16
19
|
/** @type {import("eslint").Linter.Config} */
|
|
17
20
|
const recommendedBrowserOutdatedCommonjsConfig = {
|
|
18
21
|
name: "browser/recommended-outdated-commonjs",
|
|
22
|
+
files: codeFiles,
|
|
23
|
+
ignores: codeIgnores,
|
|
19
24
|
languageOptions: {
|
|
20
25
|
sourceType: "commonjs",
|
|
21
26
|
globals: {
|
|
@@ -27,17 +32,28 @@ const recommendedBrowserOutdatedCommonjsConfig = {
|
|
|
27
32
|
/** @type {import("eslint").Linter.Config} */
|
|
28
33
|
const recommendedBrowserOutdatedModuleConfig = {
|
|
29
34
|
name: "browser/recommended-outdated-module",
|
|
35
|
+
files: codeFiles,
|
|
36
|
+
ignores: codeIgnores,
|
|
30
37
|
languageOptions: {
|
|
31
38
|
sourceType: "module",
|
|
32
39
|
globals: {
|
|
33
40
|
...globals.browser,
|
|
34
41
|
},
|
|
35
42
|
},
|
|
43
|
+
plugins: {
|
|
44
|
+
unicorn: unicornPlugin,
|
|
45
|
+
},
|
|
46
|
+
rules: {
|
|
47
|
+
// Disabled for ECMAScript < 2022 in `javascript/*`
|
|
48
|
+
"unicorn/prefer-top-level-await": "error",
|
|
49
|
+
},
|
|
36
50
|
};
|
|
37
51
|
|
|
38
52
|
/** @type {import("eslint").Linter.Config} */
|
|
39
53
|
const recommendedBrowserConfig = {
|
|
40
54
|
name: "browser/recommended",
|
|
55
|
+
files: codeFiles,
|
|
56
|
+
ignores: codeIgnores,
|
|
41
57
|
languageOptions: {
|
|
42
58
|
sourceType: "module",
|
|
43
59
|
globals: {
|
|
@@ -46,15 +62,61 @@ const recommendedBrowserConfig = {
|
|
|
46
62
|
},
|
|
47
63
|
plugins: {
|
|
48
64
|
unicorn: unicornPlugin,
|
|
49
|
-
import: importPlugin,
|
|
65
|
+
"import-x": importPlugin,
|
|
50
66
|
},
|
|
51
67
|
rules: {
|
|
68
|
+
"unicorn/dom-node-dataset": "error",
|
|
69
|
+
|
|
70
|
+
"unicorn/no-canvas-to-image": "error",
|
|
71
|
+
|
|
72
|
+
"unicorn/no-incorrect-query-selector": "error",
|
|
73
|
+
|
|
74
|
+
"unicorn/no-invalid-boolean-attribute-value": "error",
|
|
75
|
+
|
|
76
|
+
"unicorn/no-invalid-dom-token": "error",
|
|
77
|
+
|
|
78
|
+
"unicorn/no-invalid-style-set-property": "error",
|
|
79
|
+
|
|
80
|
+
"unicorn/no-late-current-target-access": "error",
|
|
81
|
+
|
|
82
|
+
"unicorn/no-late-event-control": "error",
|
|
83
|
+
|
|
84
|
+
"unicorn/no-selector-as-dom-name": "error",
|
|
85
|
+
|
|
86
|
+
// Do not need
|
|
87
|
+
// "unicorn/no-unsafe-dom-html": "error",
|
|
88
|
+
|
|
89
|
+
"unicorn/prefer-add-event-listener": "error",
|
|
90
|
+
|
|
91
|
+
"unicorn/prefer-add-event-listener-options": "error",
|
|
92
|
+
|
|
93
|
+
"unicorn/prefer-dom-node-html-methods": [
|
|
94
|
+
"error",
|
|
95
|
+
{
|
|
96
|
+
// Reading `innerHTML` can be safely replaced only when the receiver is a DOM node
|
|
97
|
+
checkGetHTML: false,
|
|
98
|
+
checkSetHTML: true,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
|
|
102
|
+
"unicorn/prefer-dom-node-replace-children": "error",
|
|
103
|
+
|
|
104
|
+
"unicorn/prefer-location-assign": "error",
|
|
105
|
+
|
|
106
|
+
"unicorn/prefer-observer-apis": "error",
|
|
107
|
+
|
|
108
|
+
"unicorn/prefer-path2d": "error",
|
|
109
|
+
|
|
110
|
+
"unicorn/prefer-toggle-attribute": "error",
|
|
111
|
+
|
|
112
|
+
"unicorn/require-css-escape": "error",
|
|
113
|
+
|
|
114
|
+
"unicorn/require-passive-events": "error",
|
|
115
|
+
|
|
52
116
|
"unicorn/prefer-classlist-toggle": "error",
|
|
53
117
|
|
|
54
118
|
"unicorn/prefer-dom-node-append": "error",
|
|
55
119
|
|
|
56
|
-
"unicorn/prefer-dom-node-dataset": "error",
|
|
57
|
-
|
|
58
120
|
"unicorn/prefer-dom-node-remove": "error",
|
|
59
121
|
|
|
60
122
|
"unicorn/prefer-dom-node-text-content": "error",
|
|
@@ -65,7 +127,10 @@ const recommendedBrowserConfig = {
|
|
|
65
127
|
|
|
66
128
|
"unicorn/prefer-query-selector": "error",
|
|
67
129
|
|
|
68
|
-
|
|
130
|
+
// Disabled for ECMAScript < 2022 in `javascript/*`
|
|
131
|
+
"unicorn/prefer-top-level-await": "error",
|
|
132
|
+
|
|
133
|
+
"import-x/extensions": [
|
|
69
134
|
"error",
|
|
70
135
|
"always",
|
|
71
136
|
{ ignorePackages: true, checkTypeImports: true },
|
|
@@ -75,8 +140,6 @@ const recommendedBrowserConfig = {
|
|
|
75
140
|
|
|
76
141
|
export default {
|
|
77
142
|
"browser/recommended": recommendedBrowserConfig,
|
|
78
|
-
// TODO remove me in the next major release
|
|
79
|
-
"browser/recommended-outdated": recommendedBrowserOutdatedModuleConfig,
|
|
80
143
|
// Useful when you need to generate outdated es5 code using babel/swc/etc
|
|
81
144
|
"browser/recommended-outdated-script": recommendedBrowserOutdatedScriptConfig,
|
|
82
145
|
"browser/recommended-outdated-commonjs":
|
package/configs/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import browserConfig from "./browser.js";
|
|
2
2
|
import javascriptConfig from "./javascript.js";
|
|
3
|
-
import
|
|
3
|
+
import jsonConfig from "./json.js";
|
|
4
4
|
import markdownConfig from "./markdown.js";
|
|
5
5
|
import nodeConfig from "./node.js";
|
|
6
|
-
import
|
|
6
|
+
import performanceConfig from "./performance.js";
|
|
7
7
|
import reactConfig from "./react.js";
|
|
8
8
|
import stylisticConfig from "./stylistic.js";
|
|
9
|
+
import testConfig from "./test.js";
|
|
9
10
|
import typescriptConfig from "./typescript.js";
|
|
10
11
|
import webpackSpecial from "./webpack-special.js";
|
|
11
12
|
|
|
12
13
|
// TODO merge this file with config.js into one to avoid problems with types
|
|
13
14
|
|
|
14
|
-
/** @typedef {typeof browserConfig & typeof javascriptConfig & typeof
|
|
15
|
+
/** @typedef {typeof browserConfig & typeof javascriptConfig & typeof jsonConfig & typeof markdownConfig & typeof nodeConfig & typeof testConfig & typeof stylisticConfig & typeof typescriptConfig & typeof reactConfig & typeof performanceConfig & typeof webpackSpecial} BasicConfigs */
|
|
15
16
|
/** @typedef {import("eslint").Linter.Config} Config */
|
|
16
17
|
/** @typedef {(Config | Config[])[]} NestedConfig */
|
|
17
18
|
/**
|
|
@@ -28,7 +29,6 @@ import webpackSpecial from "./webpack-special.js";
|
|
|
28
29
|
* "browser-outdated-recommended-script": NestedConfig,
|
|
29
30
|
* "browser-outdated-recommended-commonjs": NestedConfig,
|
|
30
31
|
* "browser-outdated-recommended-module": NestedConfig,
|
|
31
|
-
* "browser-outdated-recommended": NestedConfig,
|
|
32
32
|
* "universal-recommended": NestedConfig,
|
|
33
33
|
}} AddvancedConfigs */
|
|
34
34
|
|
|
@@ -38,13 +38,14 @@ const configs =
|
|
|
38
38
|
({
|
|
39
39
|
...browserConfig,
|
|
40
40
|
...javascriptConfig,
|
|
41
|
-
...
|
|
41
|
+
...jsonConfig,
|
|
42
42
|
...markdownConfig,
|
|
43
43
|
...nodeConfig,
|
|
44
|
+
...testConfig,
|
|
44
45
|
...stylisticConfig,
|
|
45
46
|
...typescriptConfig,
|
|
46
47
|
...reactConfig,
|
|
47
|
-
...
|
|
48
|
+
...performanceConfig,
|
|
48
49
|
...webpackSpecial,
|
|
49
50
|
});
|
|
50
51
|
|