@antfu/eslint-config 1.2.1 → 2.1.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 -24
- package/dist/cli.cjs +39 -13
- package/dist/cli.js +39 -13
- package/dist/index.cjs +246 -130
- package/dist/index.d.cts +53 -55
- package/dist/index.d.ts +53 -55
- package/dist/index.js +251 -118
- package/package.json +37 -18
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
|
|
|
32
32
|
// eslint.config.js
|
|
33
33
|
import antfu from '@antfu/eslint-config'
|
|
34
34
|
|
|
35
|
-
export default antfu()
|
|
35
|
+
export default await antfu()
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
With CJS:
|
|
@@ -87,13 +87,13 @@ For example:
|
|
|
87
87
|
|
|
88
88
|
### Migration
|
|
89
89
|
|
|
90
|
-
We provided an experimental
|
|
90
|
+
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npx @antfu/eslint-config
|
|
93
|
+
npx @antfu/eslint-config@latest
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Before running the migration, make sure to commit your changes first.
|
|
96
|
+
Before running the migration, make sure to commit your unsaved changes first.
|
|
97
97
|
|
|
98
98
|
## VS Code support (auto fix)
|
|
99
99
|
|
|
@@ -155,7 +155,7 @@ Normally you only need to import the `antfu` preset:
|
|
|
155
155
|
// eslint.config.js
|
|
156
156
|
import antfu from '@antfu/eslint-config'
|
|
157
157
|
|
|
158
|
-
export default antfu()
|
|
158
|
+
export default await antfu()
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
And that's it! Or you can configure each integration individually, for example:
|
|
@@ -164,7 +164,7 @@ And that's it! Or you can configure each integration individually, for example:
|
|
|
164
164
|
// eslint.config.js
|
|
165
165
|
import antfu from '@antfu/eslint-config'
|
|
166
166
|
|
|
167
|
-
export default antfu({
|
|
167
|
+
export default await antfu({
|
|
168
168
|
// Enable stylistic formatting rules
|
|
169
169
|
// stylistic: true,
|
|
170
170
|
|
|
@@ -196,7 +196,7 @@ The `antfu` factory function also accepts any number of arbitrary custom config
|
|
|
196
196
|
// eslint.config.js
|
|
197
197
|
import antfu from '@antfu/eslint-config'
|
|
198
198
|
|
|
199
|
-
export default antfu(
|
|
199
|
+
export default await antfu(
|
|
200
200
|
{
|
|
201
201
|
// Configures for antfu's config
|
|
202
202
|
},
|
|
@@ -223,6 +223,7 @@ We don't recommend using this style in general usages, as there are shared optio
|
|
|
223
223
|
```js
|
|
224
224
|
// eslint.config.js
|
|
225
225
|
import {
|
|
226
|
+
combine,
|
|
226
227
|
comments,
|
|
227
228
|
ignores,
|
|
228
229
|
imports,
|
|
@@ -240,21 +241,21 @@ import {
|
|
|
240
241
|
yaml,
|
|
241
242
|
} from '@antfu/eslint-config'
|
|
242
243
|
|
|
243
|
-
export default
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
244
|
+
export default await combine(
|
|
245
|
+
ignores(),
|
|
246
|
+
javascript(/* Options */),
|
|
247
|
+
comments(),
|
|
248
|
+
node(),
|
|
249
|
+
jsdoc(),
|
|
250
|
+
imports(),
|
|
251
|
+
unicorn(),
|
|
252
|
+
typescript(/* Options */),
|
|
253
|
+
stylistic(),
|
|
254
|
+
vue(),
|
|
255
|
+
jsonc(),
|
|
256
|
+
yaml(),
|
|
257
|
+
markdown(),
|
|
258
|
+
)
|
|
258
259
|
```
|
|
259
260
|
|
|
260
261
|
</details>
|
|
@@ -293,7 +294,7 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules
|
|
|
293
294
|
// eslint.config.js
|
|
294
295
|
import antfu from '@antfu/eslint-config'
|
|
295
296
|
|
|
296
|
-
export default antfu(
|
|
297
|
+
export default await antfu(
|
|
297
298
|
{ vue: true, typescript: true },
|
|
298
299
|
{
|
|
299
300
|
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
@@ -311,7 +312,7 @@ export default antfu(
|
|
|
311
312
|
)
|
|
312
313
|
```
|
|
313
314
|
|
|
314
|
-
We also provided
|
|
315
|
+
We also provided a `overrides` options to make it easier:
|
|
315
316
|
|
|
316
317
|
```js
|
|
317
318
|
// eslint.config.js
|
|
@@ -331,6 +332,29 @@ export default antfu({
|
|
|
331
332
|
})
|
|
332
333
|
```
|
|
333
334
|
|
|
335
|
+
### Optional Configs
|
|
336
|
+
|
|
337
|
+
#### React
|
|
338
|
+
|
|
339
|
+
We do include configs for React. But due to the install size of React plugins we didn't include the dependencies by default.
|
|
340
|
+
|
|
341
|
+
To enable React support, need to explicitly turn it on:
|
|
342
|
+
|
|
343
|
+
```js
|
|
344
|
+
// eslint.config.js
|
|
345
|
+
import antfu from '@antfu/eslint-config'
|
|
346
|
+
|
|
347
|
+
export default antfu({
|
|
348
|
+
react: true,
|
|
349
|
+
})
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise you can install them manually:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
|
|
356
|
+
```
|
|
357
|
+
|
|
334
358
|
### Optional Rules
|
|
335
359
|
|
|
336
360
|
This config also provides some optional plugins/rules for extended usages.
|
package/dist/cli.cjs
CHANGED
|
@@ -46,13 +46,40 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
|
46
46
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
47
47
|
|
|
48
48
|
// package.json
|
|
49
|
-
var version = "
|
|
49
|
+
var version = "2.1.0";
|
|
50
|
+
var devDependencies = {
|
|
51
|
+
"@antfu/eslint-config": "workspace:*",
|
|
52
|
+
"@antfu/ni": "^0.21.10",
|
|
53
|
+
"@stylistic/eslint-plugin-migrate": "^1.4.0",
|
|
54
|
+
"@types/eslint": "^8.44.7",
|
|
55
|
+
"@types/fs-extra": "^11.0.4",
|
|
56
|
+
"@types/node": "^20.9.4",
|
|
57
|
+
"@types/prompts": "^2.4.9",
|
|
58
|
+
"@types/yargs": "^17.0.32",
|
|
59
|
+
bumpp: "^9.2.0",
|
|
60
|
+
eslint: "^8.54.0",
|
|
61
|
+
"eslint-flat-config-viewer": "^0.1.3",
|
|
62
|
+
"eslint-plugin-react": "^7.33.2",
|
|
63
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
64
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
65
|
+
esno: "^4.0.0",
|
|
66
|
+
execa: "^8.0.1",
|
|
67
|
+
"fast-glob": "^3.3.2",
|
|
68
|
+
"fs-extra": "^11.1.1",
|
|
69
|
+
"lint-staged": "^15.1.0",
|
|
70
|
+
rimraf: "^5.0.5",
|
|
71
|
+
"simple-git-hooks": "^2.9.0",
|
|
72
|
+
tsup: "^8.0.1",
|
|
73
|
+
typescript: "^5.3.2",
|
|
74
|
+
vitest: "^0.34.6"
|
|
75
|
+
};
|
|
50
76
|
|
|
51
77
|
// src/cli/constants.ts
|
|
52
78
|
var ARROW = import_picocolors.default.cyan("\u2192");
|
|
53
79
|
var CHECK = import_picocolors.default.green("\u2714");
|
|
54
80
|
var CROSS = import_picocolors.default.red("\u2718");
|
|
55
81
|
var WARN = import_picocolors.default.yellow("\u2139");
|
|
82
|
+
var eslintVersion = devDependencies.eslint;
|
|
56
83
|
var vscodeSettingsString = `
|
|
57
84
|
// Enable the ESlint flat config support
|
|
58
85
|
"eslint.experimental.useFlatConfig": true,
|
|
@@ -107,9 +134,9 @@ function isGitClean() {
|
|
|
107
134
|
}
|
|
108
135
|
|
|
109
136
|
// src/cli/run.ts
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
async function run(options = {}) {
|
|
138
|
+
const SKIP_PROMPT = !!import_node_process.default.env.SKIP_PROMPT || options.yes;
|
|
139
|
+
const SKIP_GIT_CHECK = !!import_node_process.default.env.SKIP_GIT_CHECK;
|
|
113
140
|
const cwd = import_node_process.default.cwd();
|
|
114
141
|
const pathFlatConfig = import_node_path.default.join(cwd, "eslint.config.js");
|
|
115
142
|
const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
|
|
@@ -125,6 +152,8 @@ async function run() {
|
|
|
125
152
|
const pkg = JSON.parse(pkgContent);
|
|
126
153
|
pkg.devDependencies ?? (pkg.devDependencies = {});
|
|
127
154
|
pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
|
|
155
|
+
if (!pkg.devDependencies.eslint)
|
|
156
|
+
pkg.devDependencies.eslint = eslintVersion;
|
|
128
157
|
await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
129
158
|
console.log(import_picocolors2.default.green(`${CHECK} changes wrote to package.json`));
|
|
130
159
|
const eslintIgnores = [];
|
|
@@ -221,22 +250,19 @@ function header() {
|
|
|
221
250
|
${import_picocolors3.default.green(`@antfu/eslint-config `)}${import_picocolors3.default.dim(`v${version}`)}`);
|
|
222
251
|
}
|
|
223
252
|
var instance = (0, import_yargs.default)((0, import_helpers.hideBin)(import_node_process2.default.argv)).scriptName("@antfu/eslint-config").usage("").command(
|
|
224
|
-
"
|
|
225
|
-
"
|
|
226
|
-
(args) => args.help(),
|
|
227
|
-
async (
|
|
253
|
+
"*",
|
|
254
|
+
"Run the initialization or migration",
|
|
255
|
+
(args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
|
|
256
|
+
async (args) => {
|
|
228
257
|
header();
|
|
229
258
|
console.log();
|
|
230
259
|
try {
|
|
231
|
-
await run();
|
|
260
|
+
await run(args);
|
|
232
261
|
} catch (error) {
|
|
233
262
|
console.error(import_picocolors3.default.inverse(import_picocolors3.default.red(" Failed to migrate ")));
|
|
234
263
|
console.error(import_picocolors3.default.red(`${CROSS} ${String(error)}`));
|
|
235
264
|
import_node_process2.default.exit(1);
|
|
236
265
|
}
|
|
237
266
|
}
|
|
238
|
-
).
|
|
239
|
-
header();
|
|
240
|
-
instance.showHelp();
|
|
241
|
-
}).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
267
|
+
).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
242
268
|
instance.help().argv;
|
package/dist/cli.js
CHANGED
|
@@ -17,13 +17,40 @@ import parse from "parse-gitignore";
|
|
|
17
17
|
import c from "picocolors";
|
|
18
18
|
|
|
19
19
|
// package.json
|
|
20
|
-
var version = "
|
|
20
|
+
var version = "2.1.0";
|
|
21
|
+
var devDependencies = {
|
|
22
|
+
"@antfu/eslint-config": "workspace:*",
|
|
23
|
+
"@antfu/ni": "^0.21.10",
|
|
24
|
+
"@stylistic/eslint-plugin-migrate": "^1.4.0",
|
|
25
|
+
"@types/eslint": "^8.44.7",
|
|
26
|
+
"@types/fs-extra": "^11.0.4",
|
|
27
|
+
"@types/node": "^20.9.4",
|
|
28
|
+
"@types/prompts": "^2.4.9",
|
|
29
|
+
"@types/yargs": "^17.0.32",
|
|
30
|
+
bumpp: "^9.2.0",
|
|
31
|
+
eslint: "^8.54.0",
|
|
32
|
+
"eslint-flat-config-viewer": "^0.1.3",
|
|
33
|
+
"eslint-plugin-react": "^7.33.2",
|
|
34
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
36
|
+
esno: "^4.0.0",
|
|
37
|
+
execa: "^8.0.1",
|
|
38
|
+
"fast-glob": "^3.3.2",
|
|
39
|
+
"fs-extra": "^11.1.1",
|
|
40
|
+
"lint-staged": "^15.1.0",
|
|
41
|
+
rimraf: "^5.0.5",
|
|
42
|
+
"simple-git-hooks": "^2.9.0",
|
|
43
|
+
tsup: "^8.0.1",
|
|
44
|
+
typescript: "^5.3.2",
|
|
45
|
+
vitest: "^0.34.6"
|
|
46
|
+
};
|
|
21
47
|
|
|
22
48
|
// src/cli/constants.ts
|
|
23
49
|
var ARROW = c.cyan("\u2192");
|
|
24
50
|
var CHECK = c.green("\u2714");
|
|
25
51
|
var CROSS = c.red("\u2718");
|
|
26
52
|
var WARN = c.yellow("\u2139");
|
|
53
|
+
var eslintVersion = devDependencies.eslint;
|
|
27
54
|
var vscodeSettingsString = `
|
|
28
55
|
// Enable the ESlint flat config support
|
|
29
56
|
"eslint.experimental.useFlatConfig": true,
|
|
@@ -78,9 +105,9 @@ function isGitClean() {
|
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
// src/cli/run.ts
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
108
|
+
async function run(options = {}) {
|
|
109
|
+
const SKIP_PROMPT = !!process.env.SKIP_PROMPT || options.yes;
|
|
110
|
+
const SKIP_GIT_CHECK = !!process.env.SKIP_GIT_CHECK;
|
|
84
111
|
const cwd = process.cwd();
|
|
85
112
|
const pathFlatConfig = path.join(cwd, "eslint.config.js");
|
|
86
113
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
@@ -96,6 +123,8 @@ async function run() {
|
|
|
96
123
|
const pkg = JSON.parse(pkgContent);
|
|
97
124
|
pkg.devDependencies ?? (pkg.devDependencies = {});
|
|
98
125
|
pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
|
|
126
|
+
if (!pkg.devDependencies.eslint)
|
|
127
|
+
pkg.devDependencies.eslint = eslintVersion;
|
|
99
128
|
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
100
129
|
console.log(c2.green(`${CHECK} changes wrote to package.json`));
|
|
101
130
|
const eslintIgnores = [];
|
|
@@ -192,22 +221,19 @@ function header() {
|
|
|
192
221
|
${c3.green(`@antfu/eslint-config `)}${c3.dim(`v${version}`)}`);
|
|
193
222
|
}
|
|
194
223
|
var instance = yargs(hideBin(process2.argv)).scriptName("@antfu/eslint-config").usage("").command(
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
(args) => args.help(),
|
|
198
|
-
async (
|
|
224
|
+
"*",
|
|
225
|
+
"Run the initialization or migration",
|
|
226
|
+
(args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
|
|
227
|
+
async (args) => {
|
|
199
228
|
header();
|
|
200
229
|
console.log();
|
|
201
230
|
try {
|
|
202
|
-
await run();
|
|
231
|
+
await run(args);
|
|
203
232
|
} catch (error) {
|
|
204
233
|
console.error(c3.inverse(c3.red(" Failed to migrate ")));
|
|
205
234
|
console.error(c3.red(`${CROSS} ${String(error)}`));
|
|
206
235
|
process2.exit(1);
|
|
207
236
|
}
|
|
208
237
|
}
|
|
209
|
-
).
|
|
210
|
-
header();
|
|
211
|
-
instance.showHelp();
|
|
212
|
-
}).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
238
|
+
).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
213
239
|
instance.help().argv;
|