@antfu/eslint-config 2.1.2 → 2.2.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 +43 -10
- package/dist/cli.cjs +5 -4
- package/dist/cli.js +5 -4
- package/dist/index.cjs +310 -206
- package/dist/index.d.cts +154 -14
- package/dist/index.d.ts +154 -14
- package/dist/index.js +306 -206
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
|
|
|
33
33
|
// eslint.config.js
|
|
34
34
|
import antfu from '@antfu/eslint-config'
|
|
35
35
|
|
|
36
|
-
export default
|
|
36
|
+
export default antfu()
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
With CJS:
|
|
@@ -156,7 +156,7 @@ Normally you only need to import the `antfu` preset:
|
|
|
156
156
|
// eslint.config.js
|
|
157
157
|
import antfu from '@antfu/eslint-config'
|
|
158
158
|
|
|
159
|
-
export default
|
|
159
|
+
export default antfu()
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
And that's it! Or you can configure each integration individually, for example:
|
|
@@ -165,7 +165,7 @@ And that's it! Or you can configure each integration individually, for example:
|
|
|
165
165
|
// eslint.config.js
|
|
166
166
|
import antfu from '@antfu/eslint-config'
|
|
167
167
|
|
|
168
|
-
export default
|
|
168
|
+
export default antfu({
|
|
169
169
|
// Enable stylistic formatting rules
|
|
170
170
|
// stylistic: true,
|
|
171
171
|
|
|
@@ -197,7 +197,7 @@ The `antfu` factory function also accepts any number of arbitrary custom config
|
|
|
197
197
|
// eslint.config.js
|
|
198
198
|
import antfu from '@antfu/eslint-config'
|
|
199
199
|
|
|
200
|
-
export default
|
|
200
|
+
export default antfu(
|
|
201
201
|
{
|
|
202
202
|
// Configures for antfu's config
|
|
203
203
|
},
|
|
@@ -242,7 +242,7 @@ import {
|
|
|
242
242
|
yaml,
|
|
243
243
|
} from '@antfu/eslint-config'
|
|
244
244
|
|
|
245
|
-
export default
|
|
245
|
+
export default combine(
|
|
246
246
|
ignores(),
|
|
247
247
|
javascript(/* Options */),
|
|
248
248
|
comments(),
|
|
@@ -295,7 +295,7 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules
|
|
|
295
295
|
// eslint.config.js
|
|
296
296
|
import antfu from '@antfu/eslint-config'
|
|
297
297
|
|
|
298
|
-
export default
|
|
298
|
+
export default antfu(
|
|
299
299
|
{ vue: true, typescript: true },
|
|
300
300
|
{
|
|
301
301
|
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
@@ -337,9 +337,36 @@ export default antfu({
|
|
|
337
337
|
|
|
338
338
|
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
339
339
|
|
|
340
|
+
#### Prettier
|
|
341
|
+
|
|
342
|
+
ESLint is mainly forced on JavaScript. It can support other languages with custom parsers, but that requires a lot of effort to rule parsers and rules to build ecosystems around them. For example, ESLint does not handle CSS and HTML at this moment. It has been a shame for a long time. But since Prettier supports wider range of languages, why don't we use Prettier for them?
|
|
343
|
+
|
|
344
|
+
> [!WARNING]
|
|
345
|
+
> This is experiemental :)
|
|
346
|
+
|
|
347
|
+
To enable Prettier support, you need to explicitly turn it on and specify the languages you want to handle:
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
// eslint.config.js
|
|
351
|
+
import antfu from '@antfu/eslint-config'
|
|
352
|
+
|
|
353
|
+
export default antfu({
|
|
354
|
+
prettier: {
|
|
355
|
+
css: true, // Let Prettier handles CSS, LESS, SCSS, etc
|
|
356
|
+
html: true, // Let Prettier handles HTML
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
npm i -D eslint-plugin-prettier prettier
|
|
365
|
+
```
|
|
366
|
+
|
|
340
367
|
#### React
|
|
341
368
|
|
|
342
|
-
To enable React support
|
|
369
|
+
To enable React support you need to explicitly turn it on:
|
|
343
370
|
|
|
344
371
|
```js
|
|
345
372
|
// eslint.config.js
|
|
@@ -358,7 +385,7 @@ npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refre
|
|
|
358
385
|
|
|
359
386
|
#### UnoCSS
|
|
360
387
|
|
|
361
|
-
To enable UnoCSS support, need to explicitly turn it on:
|
|
388
|
+
To enable UnoCSS support, you need to explicitly turn it on:
|
|
362
389
|
|
|
363
390
|
```js
|
|
364
391
|
// eslint.config.js
|
|
@@ -476,9 +503,15 @@ If you enjoy this code style, and would like to mention it in your project, here
|
|
|
476
503
|
|
|
477
504
|
[Why I don't use Prettier](https://antfu.me/posts/why-not-prettier)
|
|
478
505
|
|
|
479
|
-
|
|
506
|
+
Well, on the other hand, you can [use still Prettier to handle CSS and HTML formatting](#prettier), which is not yet supported by ESLint.
|
|
507
|
+
|
|
508
|
+
### How to format CSS?
|
|
509
|
+
|
|
510
|
+
~~This config does NOT lint CSS. I personally use [UnoCSS](https://github.com/unocss/unocss) so I don't write CSS.~~
|
|
511
|
+
|
|
512
|
+
Yes, we do now! See [Prettier](#prettier) section for more details.
|
|
480
513
|
|
|
481
|
-
|
|
514
|
+
For better linting, we recommend trying [stylelint](https://stylelint.io/).
|
|
482
515
|
|
|
483
516
|
### I prefer XXX...
|
|
484
517
|
|
package/dist/cli.cjs
CHANGED
|
@@ -46,9 +46,10 @@ 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 = "2.
|
|
49
|
+
var version = "2.2.0";
|
|
50
50
|
var devDependencies = {
|
|
51
51
|
"@antfu/eslint-config": "workspace:*",
|
|
52
|
+
"@antfu/eslint-plugin-prettier": "^5.0.1-1",
|
|
52
53
|
"@antfu/ni": "^0.21.12",
|
|
53
54
|
"@stylistic/eslint-plugin-migrate": "^1.4.1",
|
|
54
55
|
"@types/eslint": "^8.44.8",
|
|
@@ -141,7 +142,7 @@ async function run(options = {}) {
|
|
|
141
142
|
const cwd = import_node_process.default.cwd();
|
|
142
143
|
const pathFlatConfig = import_node_path.default.join(cwd, "eslint.config.js");
|
|
143
144
|
const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
|
|
144
|
-
const
|
|
145
|
+
const pathESLintIgnore = import_node_path.default.join(cwd, ".eslintignore");
|
|
145
146
|
if (import_node_fs.default.existsSync(pathFlatConfig)) {
|
|
146
147
|
console.log(import_picocolors2.default.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
|
|
147
148
|
return;
|
|
@@ -158,9 +159,9 @@ async function run(options = {}) {
|
|
|
158
159
|
await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
159
160
|
console.log(import_picocolors2.default.green(`${CHECK} changes wrote to package.json`));
|
|
160
161
|
const eslintIgnores = [];
|
|
161
|
-
if (import_node_fs.default.existsSync(
|
|
162
|
+
if (import_node_fs.default.existsSync(pathESLintIgnore)) {
|
|
162
163
|
console.log(import_picocolors2.default.cyan(`${ARROW} migrating existing .eslintignore`));
|
|
163
|
-
const content = await import_promises.default.readFile(
|
|
164
|
+
const content = await import_promises.default.readFile(pathESLintIgnore, "utf-8");
|
|
164
165
|
const parsed = (0, import_parse_gitignore.default)(content);
|
|
165
166
|
const globs = parsed.globs();
|
|
166
167
|
for (const glob of globs) {
|
package/dist/cli.js
CHANGED
|
@@ -17,9 +17,10 @@ import parse from "parse-gitignore";
|
|
|
17
17
|
import c from "picocolors";
|
|
18
18
|
|
|
19
19
|
// package.json
|
|
20
|
-
var version = "2.
|
|
20
|
+
var version = "2.2.0";
|
|
21
21
|
var devDependencies = {
|
|
22
22
|
"@antfu/eslint-config": "workspace:*",
|
|
23
|
+
"@antfu/eslint-plugin-prettier": "^5.0.1-1",
|
|
23
24
|
"@antfu/ni": "^0.21.12",
|
|
24
25
|
"@stylistic/eslint-plugin-migrate": "^1.4.1",
|
|
25
26
|
"@types/eslint": "^8.44.8",
|
|
@@ -112,7 +113,7 @@ async function run(options = {}) {
|
|
|
112
113
|
const cwd = process.cwd();
|
|
113
114
|
const pathFlatConfig = path.join(cwd, "eslint.config.js");
|
|
114
115
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
115
|
-
const
|
|
116
|
+
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
116
117
|
if (fs.existsSync(pathFlatConfig)) {
|
|
117
118
|
console.log(c2.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
|
|
118
119
|
return;
|
|
@@ -129,9 +130,9 @@ async function run(options = {}) {
|
|
|
129
130
|
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
130
131
|
console.log(c2.green(`${CHECK} changes wrote to package.json`));
|
|
131
132
|
const eslintIgnores = [];
|
|
132
|
-
if (fs.existsSync(
|
|
133
|
+
if (fs.existsSync(pathESLintIgnore)) {
|
|
133
134
|
console.log(c2.cyan(`${ARROW} migrating existing .eslintignore`));
|
|
134
|
-
const content = await fsp.readFile(
|
|
135
|
+
const content = await fsp.readFile(pathESLintIgnore, "utf-8");
|
|
135
136
|
const parsed = parse(content);
|
|
136
137
|
const globs = parsed.globs();
|
|
137
138
|
for (const glob of globs) {
|