@antfu/eslint-config 2.1.1 → 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 CHANGED
@@ -8,9 +8,10 @@
8
8
  - Lints also for json, yaml, markdown
9
9
  - Sorted imports, dangling commas
10
10
  - Reasonable defaults, best practices, only one-line of config
11
- - Respects `.gitignore` by default
11
+ - Opinionated, but [very customizable](#customization)
12
12
  - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
13
13
  - Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
14
+ - Respects `.gitignore` by default
14
15
  - **Style principle**: Minimal for reading, stable for diff, consistent
15
16
 
16
17
  > [!IMPORTANT]
@@ -32,7 +33,7 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
32
33
  // eslint.config.js
33
34
  import antfu from '@antfu/eslint-config'
34
35
 
35
- export default await antfu()
36
+ export default antfu()
36
37
  ```
37
38
 
38
39
  With CJS:
@@ -155,7 +156,7 @@ Normally you only need to import the `antfu` preset:
155
156
  // eslint.config.js
156
157
  import antfu from '@antfu/eslint-config'
157
158
 
158
- export default await antfu()
159
+ export default antfu()
159
160
  ```
160
161
 
161
162
  And that's it! Or you can configure each integration individually, for example:
@@ -164,7 +165,7 @@ And that's it! Or you can configure each integration individually, for example:
164
165
  // eslint.config.js
165
166
  import antfu from '@antfu/eslint-config'
166
167
 
167
- export default await antfu({
168
+ export default antfu({
168
169
  // Enable stylistic formatting rules
169
170
  // stylistic: true,
170
171
 
@@ -196,7 +197,7 @@ The `antfu` factory function also accepts any number of arbitrary custom config
196
197
  // eslint.config.js
197
198
  import antfu from '@antfu/eslint-config'
198
199
 
199
- export default await antfu(
200
+ export default antfu(
200
201
  {
201
202
  // Configures for antfu's config
202
203
  },
@@ -241,7 +242,7 @@ import {
241
242
  yaml,
242
243
  } from '@antfu/eslint-config'
243
244
 
244
- export default await combine(
245
+ export default combine(
245
246
  ignores(),
246
247
  javascript(/* Options */),
247
248
  comments(),
@@ -294,7 +295,7 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules
294
295
  // eslint.config.js
295
296
  import antfu from '@antfu/eslint-config'
296
297
 
297
- export default await antfu(
298
+ export default antfu(
298
299
  { vue: true, typescript: true },
299
300
  {
300
301
  // Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
@@ -336,9 +337,36 @@ export default antfu({
336
337
 
337
338
  We provide some optional configs for specific use cases, that we don't include their dependencies by default.
338
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
+
339
367
  #### React
340
368
 
341
- To enable React support, need to explicitly turn it on:
369
+ To enable React support you need to explicitly turn it on:
342
370
 
343
371
  ```js
344
372
  // eslint.config.js
@@ -357,7 +385,7 @@ npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refre
357
385
 
358
386
  #### UnoCSS
359
387
 
360
- To enable UnoCSS support, need to explicitly turn it on:
388
+ To enable UnoCSS support, you need to explicitly turn it on:
361
389
 
362
390
  ```js
363
391
  // eslint.config.js
@@ -432,6 +460,16 @@ and then
432
460
  npm i -D lint-staged simple-git-hooks
433
461
  ```
434
462
 
463
+ ## View what rules are enabled
464
+
465
+ I built a visual tool to help you view what rules are enabled in your project and apply them to what files, [eslint-flat-config-viewer](https://github.com/antfu/eslint-flat-config-viewer)
466
+
467
+ Go to your project root that contains `eslint.config.js` and run:
468
+
469
+ ```bash
470
+ npx eslint-flat-config-viewer
471
+ ```
472
+
435
473
  ## Versioning Policy
436
474
 
437
475
  This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.
@@ -465,9 +503,15 @@ If you enjoy this code style, and would like to mention it in your project, here
465
503
 
466
504
  [Why I don't use Prettier](https://antfu.me/posts/why-not-prettier)
467
505
 
468
- ### How to lint CSS?
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.
469
513
 
470
- This config does NOT lint CSS. I personally use [UnoCSS](https://github.com/unocss/unocss) so I don't write CSS. If you still prefer CSS, you can use [stylelint](https://stylelint.io/) for CSS linting.
514
+ For better linting, we recommend trying [stylelint](https://stylelint.io/).
471
515
 
472
516
  ### I prefer XXX...
473
517
 
package/dist/cli.cjs CHANGED
@@ -46,14 +46,15 @@ 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.1.1";
49
+ var version = "2.2.0";
50
50
  var devDependencies = {
51
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",
52
+ "@antfu/eslint-plugin-prettier": "^5.0.1-1",
53
+ "@antfu/ni": "^0.21.12",
54
+ "@stylistic/eslint-plugin-migrate": "^1.4.1",
55
+ "@types/eslint": "^8.44.8",
55
56
  "@types/fs-extra": "^11.0.4",
56
- "@types/node": "^20.9.4",
57
+ "@types/node": "^20.10.1",
57
58
  "@types/prompts": "^2.4.9",
58
59
  "@types/yargs": "^17.0.32",
59
60
  "@unocss/eslint-plugin": "^0.57.7",
@@ -66,7 +67,7 @@ var devDependencies = {
66
67
  esno: "^4.0.0",
67
68
  execa: "^8.0.1",
68
69
  "fast-glob": "^3.3.2",
69
- "fs-extra": "^11.1.1",
70
+ "fs-extra": "^11.2.0",
70
71
  "lint-staged": "^15.1.0",
71
72
  rimraf: "^5.0.5",
72
73
  "simple-git-hooks": "^2.9.0",
@@ -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 pathESLintIngore = import_node_path.default.join(cwd, ".eslintignore");
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(pathESLintIngore)) {
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(pathESLintIngore, "utf-8");
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,14 +17,15 @@ import parse from "parse-gitignore";
17
17
  import c from "picocolors";
18
18
 
19
19
  // package.json
20
- var version = "2.1.1";
20
+ var version = "2.2.0";
21
21
  var devDependencies = {
22
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",
23
+ "@antfu/eslint-plugin-prettier": "^5.0.1-1",
24
+ "@antfu/ni": "^0.21.12",
25
+ "@stylistic/eslint-plugin-migrate": "^1.4.1",
26
+ "@types/eslint": "^8.44.8",
26
27
  "@types/fs-extra": "^11.0.4",
27
- "@types/node": "^20.9.4",
28
+ "@types/node": "^20.10.1",
28
29
  "@types/prompts": "^2.4.9",
29
30
  "@types/yargs": "^17.0.32",
30
31
  "@unocss/eslint-plugin": "^0.57.7",
@@ -37,7 +38,7 @@ var devDependencies = {
37
38
  esno: "^4.0.0",
38
39
  execa: "^8.0.1",
39
40
  "fast-glob": "^3.3.2",
40
- "fs-extra": "^11.1.1",
41
+ "fs-extra": "^11.2.0",
41
42
  "lint-staged": "^15.1.0",
42
43
  rimraf: "^5.0.5",
43
44
  "simple-git-hooks": "^2.9.0",
@@ -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 pathESLintIngore = path.join(cwd, ".eslintignore");
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(pathESLintIngore)) {
133
+ if (fs.existsSync(pathESLintIgnore)) {
133
134
  console.log(c2.cyan(`${ARROW} migrating existing .eslintignore`));
134
- const content = await fsp.readFile(pathESLintIngore, "utf-8");
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) {