eslint-config-webpack 4.14.0 → 4.15.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 +46 -0
- package/configs/stylistic.js +14 -4
- package/configs/typescript.js +38 -45
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -38,6 +38,52 @@ export default defineConfig([
|
|
|
38
38
|
]);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
### Prettier
|
|
42
|
+
|
|
43
|
+
The recommended config does not run Prettier: formatting every file again
|
|
44
|
+
inside ESLint is slow, and an editor already formats on save. Run Prettier
|
|
45
|
+
on its own, with the shared options:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm i -D prettier
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// prettier.config.mjs
|
|
53
|
+
export { default } from "eslint-config-webpack/prettier-config.js";
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Use `eslint-config-webpack/prettier-config-es5.js` instead for code that must
|
|
57
|
+
stay ES5 (trailing commas only where ES5 allows them).
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"scripts": {
|
|
62
|
+
"lint": "eslint --cache . && prettier --cache --check .",
|
|
63
|
+
"fmt": "prettier --cache --write ."
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run `lint` in CI, so unformatted code fails the build, and set your editor to
|
|
69
|
+
format on save with the Prettier extension. Files Prettier should skip go in
|
|
70
|
+
`.prettierignore`.
|
|
71
|
+
|
|
72
|
+
To report formatting as ESLint errors instead, as before, add the opt-in
|
|
73
|
+
`stylistic/prettier` config:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import { defineConfig } from "eslint/config";
|
|
77
|
+
import config from "eslint-config-webpack";
|
|
78
|
+
import configs from "eslint-config-webpack/configs.js";
|
|
79
|
+
|
|
80
|
+
export default defineConfig([
|
|
81
|
+
{
|
|
82
|
+
extends: [config, configs["stylistic/prettier"]],
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
```
|
|
86
|
+
|
|
41
87
|
### Webpack-specific configs
|
|
42
88
|
|
|
43
89
|
Three opt-in configs cover conventions only webpack's own repositories need.
|
package/configs/stylistic.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import stylisticPlugin from "@stylistic/eslint-plugin";
|
|
2
2
|
import prettierPlugin from "eslint-plugin-prettier";
|
|
3
|
-
import prettierConfig from "eslint-plugin-prettier/recommended";
|
|
4
3
|
|
|
5
4
|
/** @type {import("eslint").Linter.Config} */
|
|
6
5
|
const recommendedConfig = {
|
|
7
|
-
...prettierConfig,
|
|
8
6
|
name: "stylistic/recommended",
|
|
9
7
|
plugins: {
|
|
10
8
|
"@stylistic": stylisticPlugin,
|
|
11
|
-
prettier: prettierPlugin,
|
|
12
9
|
},
|
|
13
10
|
rules: {
|
|
14
|
-
"prettier/prettier": "error",
|
|
15
11
|
curly: ["error", "multi-line", "consistent"],
|
|
16
12
|
"@stylistic/lines-between-class-members": "error",
|
|
17
13
|
"@stylistic/quotes": [
|
|
@@ -85,6 +81,20 @@ const recommendedConfig = {
|
|
|
85
81
|
},
|
|
86
82
|
};
|
|
87
83
|
|
|
84
|
+
// Opt-in: running Prettier as a lint rule formats every file inside ESLint,
|
|
85
|
+
// which is slow; run `prettier --check` on its own instead (see README).
|
|
86
|
+
/** @type {import("eslint").Linter.Config} */
|
|
87
|
+
const prettierConfig = {
|
|
88
|
+
name: "stylistic/prettier",
|
|
89
|
+
plugins: {
|
|
90
|
+
prettier: prettierPlugin,
|
|
91
|
+
},
|
|
92
|
+
rules: {
|
|
93
|
+
"prettier/prettier": "error",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
88
97
|
export default {
|
|
89
98
|
"stylistic/recommended": recommendedConfig,
|
|
99
|
+
"stylistic/prettier": prettierConfig,
|
|
90
100
|
};
|
package/configs/typescript.js
CHANGED
|
@@ -106,7 +106,8 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
106
106
|
// From recommended
|
|
107
107
|
// "jsdoc/escape-inline-tags": "error",
|
|
108
108
|
|
|
109
|
-
//
|
|
109
|
+
// TypeScript reports `@implements` outside a class itself (TS8022)
|
|
110
|
+
"jsdoc/implements-on-classes": "off",
|
|
110
111
|
|
|
111
112
|
// No need
|
|
112
113
|
// "jsdoc/informative-docs": "error",
|
|
@@ -141,37 +142,23 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
141
142
|
"jsdoc/no-restricted-syntax": [
|
|
142
143
|
"error",
|
|
143
144
|
{
|
|
145
|
+
// One context with one `:has()` instead of one per check: the plugin
|
|
146
|
+
// rebuilds the comment AST per context and `:has()` walks it each time.
|
|
144
147
|
contexts: [
|
|
145
|
-
// Prefer TypeScript syntax for functions
|
|
146
148
|
{
|
|
147
|
-
comment:
|
|
149
|
+
comment: `JsdocBlock:has(${[
|
|
150
|
+
// Prefer TypeScript syntax for functions
|
|
151
|
+
"JsdocTypeFunction[arrow=false]",
|
|
152
|
+
// Prefer `{string=}` over `{string} [arg]`
|
|
153
|
+
"JsdocTag[tag=/^(property|param)$/][name=/[\\[\\]]/]",
|
|
154
|
+
// No `?` type
|
|
155
|
+
"JsdocTypeUnknown",
|
|
156
|
+
// No `Object`
|
|
157
|
+
"JsdocTag[tag!=/^(typedef|template|param)$/]:has(JsdocTypeName[value=/^(Object|object)$/])",
|
|
158
|
+
"JsdocTag[tag=typedef][parsedType.type!=JsdocTypeName]:has(JsdocTypeName[value=/^(Object|object)$/])",
|
|
159
|
+
].join(", ")})`,
|
|
148
160
|
message:
|
|
149
|
-
"Please use TypeScript syntax
|
|
150
|
-
},
|
|
151
|
-
// Prefer `{string=}` over `{string} [arg]`
|
|
152
|
-
{
|
|
153
|
-
comment:
|
|
154
|
-
"JsdocBlock:has(JsdocTag[tag=/^(property|param)$/][name=/[\\[\\]]/])",
|
|
155
|
-
message:
|
|
156
|
-
"Please use `@property {string=} property`/`@param {string=} arg` instead `[arg]` for optional properties and parameters",
|
|
157
|
-
},
|
|
158
|
-
// No `?` type
|
|
159
|
-
{
|
|
160
|
-
comment: "JsdocBlock:has(JsdocTypeUnknown)",
|
|
161
|
-
message: "Please use `unknown` or `any` (or `EXPECTED_ANY`) type",
|
|
162
|
-
},
|
|
163
|
-
// No `Object`
|
|
164
|
-
{
|
|
165
|
-
comment:
|
|
166
|
-
"JsdocBlock:has(JsdocTag[tag!=/^(typedef|template|param)$/]:has(JsdocTypeName[value=/^(Object|object)$/]))",
|
|
167
|
-
message:
|
|
168
|
-
"Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`/`object` or use `EXPECTED_OBJECT` type",
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
comment:
|
|
172
|
-
"JsdocBlock:has(JsdocTag[tag=typedef][parsedType.type!=JsdocTypeName]:has(JsdocTypeName[value=/^(Object|object)$/]))",
|
|
173
|
-
message:
|
|
174
|
-
"Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`/`object` or use `EXPECTED_OBJECT` type",
|
|
161
|
+
"Please use TypeScript syntax: `(a: string) => number` for functions, `{string=}` instead of `[arg]` for optional properties and parameters, `unknown`/`any` (or `EXPECTED_ANY`) instead of `?`, and object types such as `{ property: number }` (or `EXPECTED_OBJECT`) instead of `Object`/`object`",
|
|
175
162
|
},
|
|
176
163
|
],
|
|
177
164
|
},
|
|
@@ -180,8 +167,9 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
180
167
|
// No need
|
|
181
168
|
// "jsdoc/no-types": "error",
|
|
182
169
|
|
|
183
|
-
//
|
|
184
|
-
//
|
|
170
|
+
// TypeScript reports an unknown type name itself (TS2304); it ignores the
|
|
171
|
+
// types of `@throws` and `@yields`, so those go unchecked
|
|
172
|
+
"jsdoc/no-undefined-types": "off",
|
|
185
173
|
|
|
186
174
|
// TODO enable me in future
|
|
187
175
|
// "jsdoc/prefer-import-tag": "error",
|
|
@@ -213,8 +201,9 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
213
201
|
// No need
|
|
214
202
|
// "jsdoc/require-next-description":"error",
|
|
215
203
|
|
|
216
|
-
//
|
|
217
|
-
//
|
|
204
|
+
// TypeScript ignores the type of `@next`; type a generator with
|
|
205
|
+
// `@returns {Generator<…>}` instead
|
|
206
|
+
"jsdoc/require-next-type": "off",
|
|
218
207
|
|
|
219
208
|
// From recommended
|
|
220
209
|
// "jsdoc/require-param": "error",
|
|
@@ -222,11 +211,12 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
222
211
|
// From recommended
|
|
223
212
|
// "jsdoc/require-param-description": "error",
|
|
224
213
|
|
|
225
|
-
//
|
|
226
|
-
|
|
214
|
+
// TypeScript fails to parse a `@param` without a name (TS1003)
|
|
215
|
+
"jsdoc/require-param-name": "off",
|
|
227
216
|
|
|
228
|
-
//
|
|
229
|
-
//
|
|
217
|
+
// `tsc` with `noImplicitAny` already reports an untyped parameter, and
|
|
218
|
+
// accepts one typed by its default value
|
|
219
|
+
"jsdoc/require-param-type": "off",
|
|
230
220
|
|
|
231
221
|
// From recommended
|
|
232
222
|
// "jsdoc/require-property": "error",
|
|
@@ -234,11 +224,13 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
234
224
|
// From recommended
|
|
235
225
|
// "jsdoc/require-property-description": "error",
|
|
236
226
|
|
|
237
|
-
//
|
|
238
|
-
//
|
|
227
|
+
// TypeScript fails to parse a `@typedef` `@property` without a name
|
|
228
|
+
// (TS1003); it ignores `@property` anywhere else
|
|
229
|
+
"jsdoc/require-property-name": "off",
|
|
239
230
|
|
|
240
|
-
//
|
|
241
|
-
//
|
|
231
|
+
// Kept: `tsc` reports an untyped `@property` (TS7005) only once the typedef
|
|
232
|
+
// is used, so an exported-only typedef would silently get `any`
|
|
233
|
+
"jsdoc/require-property-type": "error",
|
|
242
234
|
|
|
243
235
|
// A lot of false positive with loops/`switch`/`if`/etc
|
|
244
236
|
"jsdoc/require-returns-check": "off",
|
|
@@ -263,8 +255,8 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
263
255
|
// No need
|
|
264
256
|
// "jsdoc/require-throws-description": "error",
|
|
265
257
|
|
|
266
|
-
//
|
|
267
|
-
|
|
258
|
+
// TypeScript ignores the type of `@throws`
|
|
259
|
+
"jsdoc/require-throws-type": "off",
|
|
268
260
|
|
|
269
261
|
// From recommended
|
|
270
262
|
// "jsdoc/require-yields": "error",
|
|
@@ -272,8 +264,9 @@ async function getTypescriptJSDocRecommendedConfig() {
|
|
|
272
264
|
// No need
|
|
273
265
|
// "jsdoc/require-yields-description": "error",
|
|
274
266
|
|
|
275
|
-
//
|
|
276
|
-
//
|
|
267
|
+
// TypeScript ignores the type of `@yields`; type a generator with
|
|
268
|
+
// `@returns {Generator<…>}` instead
|
|
269
|
+
"jsdoc/require-yields-type": "off",
|
|
277
270
|
|
|
278
271
|
// From recommended
|
|
279
272
|
// "jsdoc/require-yields-check": "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-webpack",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "Provides Webpack's eslint rules as an extensible shared config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -32,9 +32,11 @@
|
|
|
32
32
|
"configs"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"lint": "npm run lint:code && npm run lint:types",
|
|
35
|
+
"lint": "npm run lint:code && npm run lint:types && npm run fmt:check",
|
|
36
36
|
"lint:code": "eslint --cache .",
|
|
37
37
|
"lint:types": "tsc -p tsconfig.internal.json",
|
|
38
|
+
"fmt": "prettier --cache --write .",
|
|
39
|
+
"fmt:check": "prettier --cache --check .",
|
|
38
40
|
"test": "cd test && node --test",
|
|
39
41
|
"version": "changeset version",
|
|
40
42
|
"release": "changeset publish"
|