@dhzh/eslint-config 0.1.0 → 0.1.2
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/LICENSE +1 -1
- package/README.md +11 -589
- package/dist/cli.cjs +10 -26
- package/dist/cli.js +10 -26
- package/package.json +5 -17
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024-PRESENT Easton Zheng<https://github.com/eastonzh>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @dhzh/eslint-config
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
Fork from [@antfu/eslint-config](https://github.com/antfu/eslint-config).
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
7
|
-
- Sorted imports, dangling commas
|
|
8
|
-
- Reasonable defaults, best practices, only one line of config
|
|
9
|
-
- Designed to work with TypeScript, JSX, Vue out-of-box
|
|
10
|
-
- Lints also for json, yaml, toml, markdown
|
|
11
|
-
- Opinionated, but [very customizable](#customization)
|
|
12
|
-
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
13
|
-
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
14
|
-
- Respects `.gitignore` by default
|
|
15
|
-
- Optional [React](#react), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro) support
|
|
16
|
-
- Optional [formatters](#formatters) support for CSS, HTML, etc.
|
|
17
|
-
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
18
|
-
|
|
19
|
-
> [!IMPORTANT]
|
|
20
|
-
> Since v1.0.0, this config is rewritten to the new [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), check the [release note](https://github.com/antfu/eslint-config/releases/tag/v1.0.0) for more details.
|
|
5
|
+
[](https://npmjs.com/package/@dhzh/eslint-config)
|
|
21
6
|
|
|
22
7
|
## Usage
|
|
23
8
|
|
|
24
9
|
### Wizard
|
|
25
10
|
|
|
26
|
-
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config.
|
|
27
|
-
|
|
28
11
|
```bash
|
|
29
|
-
npx @
|
|
12
|
+
npx @dhzh/eslint-config@latest
|
|
30
13
|
```
|
|
31
14
|
|
|
32
15
|
### Install
|
|
33
16
|
|
|
34
17
|
```bash
|
|
35
|
-
pnpm i -D eslint @
|
|
18
|
+
pnpm i -D eslint @dhzh/eslint-config
|
|
36
19
|
```
|
|
37
20
|
|
|
38
21
|
### Create config file
|
|
@@ -41,583 +24,22 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
|
|
|
41
24
|
|
|
42
25
|
```js
|
|
43
26
|
// eslint.config.js
|
|
44
|
-
import
|
|
27
|
+
import dhzh from '@dhzh/eslint-config';
|
|
45
28
|
|
|
46
|
-
export default
|
|
29
|
+
export default dhzh();
|
|
47
30
|
```
|
|
48
31
|
|
|
49
32
|
With CJS:
|
|
50
33
|
|
|
51
34
|
```js
|
|
52
35
|
// eslint.config.js
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
module.exports = antfu()
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
> [!TIP]
|
|
59
|
-
> ESLint only detects `eslint.config.js` as the flat config entry, meaning you need to put `type: module` in your `package.json` or you have to use CJS in `eslint.config.js`. If you want explicit extension like `.mjs` or `.cjs`, or even `eslint.config.ts`, you can install [`eslint-ts-patch`](https://github.com/antfu/eslint-ts-patch) to fix it.
|
|
60
|
-
|
|
61
|
-
Combined with legacy config:
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
// eslint.config.js
|
|
65
|
-
const antfu = require('@antfu/eslint-config').default
|
|
66
|
-
const { FlatCompat } = require('@eslint/eslintrc')
|
|
67
|
-
|
|
68
|
-
const compat = new FlatCompat()
|
|
69
|
-
|
|
70
|
-
module.exports = antfu(
|
|
71
|
-
{
|
|
72
|
-
ignores: [],
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
// Legacy config
|
|
76
|
-
...compat.config({
|
|
77
|
-
extends: [
|
|
78
|
-
'eslint:recommended',
|
|
79
|
-
// Other extends...
|
|
80
|
-
],
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
// Other flat configs...
|
|
84
|
-
)
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
88
|
-
|
|
89
|
-
### Add script for package.json
|
|
90
|
-
|
|
91
|
-
For example:
|
|
92
|
-
|
|
93
|
-
```json
|
|
94
|
-
{
|
|
95
|
-
"scripts": {
|
|
96
|
-
"lint": "eslint .",
|
|
97
|
-
"lint:fix": "eslint . --fix"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## VS Code support (auto fix)
|
|
103
|
-
|
|
104
|
-
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
105
|
-
|
|
106
|
-
Add the following settings to your `.vscode/settings.json`:
|
|
107
|
-
|
|
108
|
-
```jsonc
|
|
109
|
-
{
|
|
110
|
-
// Enable the ESlint flat config support
|
|
111
|
-
"eslint.experimental.useFlatConfig": true,
|
|
112
|
-
|
|
113
|
-
// Disable the default formatter, use eslint instead
|
|
114
|
-
"prettier.enable": false,
|
|
115
|
-
"editor.formatOnSave": false,
|
|
116
|
-
|
|
117
|
-
// Auto fix
|
|
118
|
-
"editor.codeActionsOnSave": {
|
|
119
|
-
"source.fixAll.eslint": "explicit",
|
|
120
|
-
"source.organizeImports": "never"
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
124
|
-
"eslint.rules.customizations": [
|
|
125
|
-
{ "rule": "style/*", "severity": "off" },
|
|
126
|
-
{ "rule": "format/*", "severity": "off" },
|
|
127
|
-
{ "rule": "*-indent", "severity": "off" },
|
|
128
|
-
{ "rule": "*-spacing", "severity": "off" },
|
|
129
|
-
{ "rule": "*-spaces", "severity": "off" },
|
|
130
|
-
{ "rule": "*-order", "severity": "off" },
|
|
131
|
-
{ "rule": "*-dangle", "severity": "off" },
|
|
132
|
-
{ "rule": "*-newline", "severity": "off" },
|
|
133
|
-
{ "rule": "*quotes", "severity": "off" },
|
|
134
|
-
{ "rule": "*semi", "severity": "off" }
|
|
135
|
-
],
|
|
136
|
-
|
|
137
|
-
// Enable eslint for all supported languages
|
|
138
|
-
"eslint.validate": [
|
|
139
|
-
"javascript",
|
|
140
|
-
"javascriptreact",
|
|
141
|
-
"typescript",
|
|
142
|
-
"typescriptreact",
|
|
143
|
-
"vue",
|
|
144
|
-
"html",
|
|
145
|
-
"markdown",
|
|
146
|
-
"json",
|
|
147
|
-
"jsonc",
|
|
148
|
-
"yaml",
|
|
149
|
-
"toml"
|
|
150
|
-
]
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Customization
|
|
155
|
-
|
|
156
|
-
Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition.
|
|
157
|
-
|
|
158
|
-
Normally you only need to import the `antfu` preset:
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
// eslint.config.js
|
|
162
|
-
import antfu from '@antfu/eslint-config'
|
|
163
|
-
|
|
164
|
-
export default antfu()
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
And that's it! Or you can configure each integration individually, for example:
|
|
168
|
-
|
|
169
|
-
```js
|
|
170
|
-
// eslint.config.js
|
|
171
|
-
import antfu from '@antfu/eslint-config'
|
|
172
|
-
|
|
173
|
-
export default antfu({
|
|
174
|
-
// Enable stylistic formatting rules
|
|
175
|
-
// stylistic: true,
|
|
176
|
-
|
|
177
|
-
// Or customize the stylistic rules
|
|
178
|
-
stylistic: {
|
|
179
|
-
indent: 2, // 4, or 'tab'
|
|
180
|
-
quotes: 'single', // or 'double'
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
|
|
184
|
-
typescript: true,
|
|
185
|
-
vue: true,
|
|
186
|
-
|
|
187
|
-
// Disable jsonc and yaml support
|
|
188
|
-
jsonc: false,
|
|
189
|
-
yaml: false,
|
|
190
|
-
|
|
191
|
-
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
192
|
-
ignores: [
|
|
193
|
-
'**/fixtures',
|
|
194
|
-
// ...globs
|
|
195
|
-
]
|
|
196
|
-
})
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
The `antfu` factory function also accepts any number of arbitrary custom config overrides:
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
// eslint.config.js
|
|
203
|
-
import antfu from '@antfu/eslint-config'
|
|
204
|
-
|
|
205
|
-
export default antfu(
|
|
206
|
-
{
|
|
207
|
-
// Configures for antfu's config
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
// From the second arguments they are ESLint Flat Configs
|
|
211
|
-
// you can have multiple configs
|
|
212
|
-
{
|
|
213
|
-
files: ['**/*.ts'],
|
|
214
|
-
rules: {},
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
rules: {},
|
|
218
|
-
},
|
|
219
|
-
)
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Going more advanced, you can also import fine-grained configs and compose them as you wish:
|
|
223
|
-
|
|
224
|
-
<details>
|
|
225
|
-
<summary>Advanced Example</summary>
|
|
226
|
-
|
|
227
|
-
We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
|
|
228
|
-
|
|
229
|
-
```js
|
|
230
|
-
// eslint.config.js
|
|
231
|
-
import {
|
|
232
|
-
combine,
|
|
233
|
-
comments,
|
|
234
|
-
ignores,
|
|
235
|
-
imports,
|
|
236
|
-
javascript,
|
|
237
|
-
jsdoc,
|
|
238
|
-
jsonc,
|
|
239
|
-
markdown,
|
|
240
|
-
node,
|
|
241
|
-
sortPackageJson,
|
|
242
|
-
sortTsconfig,
|
|
243
|
-
stylistic,
|
|
244
|
-
toml,
|
|
245
|
-
typescript,
|
|
246
|
-
unicorn,
|
|
247
|
-
vue,
|
|
248
|
-
yaml,
|
|
249
|
-
} from '@antfu/eslint-config'
|
|
250
|
-
|
|
251
|
-
export default combine(
|
|
252
|
-
ignores(),
|
|
253
|
-
javascript(/* Options */),
|
|
254
|
-
comments(),
|
|
255
|
-
node(),
|
|
256
|
-
jsdoc(),
|
|
257
|
-
imports(),
|
|
258
|
-
unicorn(),
|
|
259
|
-
typescript(/* Options */),
|
|
260
|
-
stylistic(),
|
|
261
|
-
vue(),
|
|
262
|
-
jsonc(),
|
|
263
|
-
yaml(),
|
|
264
|
-
toml(),
|
|
265
|
-
markdown(),
|
|
266
|
-
)
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
</details>
|
|
270
|
-
|
|
271
|
-
Check out the [configs](https://github.com/antfu/eslint-config/blob/main/src/configs) and [factory](https://github.com/antfu/eslint-config/blob/main/src/factory.ts) for more details.
|
|
272
|
-
|
|
273
|
-
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
|
|
274
|
-
|
|
275
|
-
### Plugins Renaming
|
|
276
|
-
|
|
277
|
-
Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm package name), we renamed some plugins to make the overall scope more consistent and easier to write.
|
|
278
|
-
|
|
279
|
-
| New Prefix | Original Prefix | Source Plugin |
|
|
280
|
-
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
281
|
-
| `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
|
|
282
|
-
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
283
|
-
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
284
|
-
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
285
|
-
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
286
|
-
| `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
|
|
287
|
-
| `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
288
|
-
|
|
289
|
-
When you want to override rules, or disable them inline, you need to update to the new prefix:
|
|
290
|
-
|
|
291
|
-
```diff
|
|
292
|
-
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
293
|
-
+// eslint-disable-next-line ts/consistent-type-definitions
|
|
294
|
-
type foo = { bar: 2 }
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
> [!NOTE]
|
|
298
|
-
> About plugin renaming - it is actually rather a dangrous move that might leading to potential naming collisions, pointed out [here](https://github.com/eslint/eslint/discussions/17766) and [here](https://github.com/prettier/eslint-config-prettier#eslintconfigjs-flat-config-plugin-caveat). As this config also very **personal** and **opinionated**, I ambitiously position this config as the only **"top-level"** config per project, that might pivots the taste of how rules are named.
|
|
299
|
-
>
|
|
300
|
-
> This config cares more about the user-facings DX, and try to ease out the implementation details. For example, users could keep using the semantic `import/order` without ever knowing the underlying plugin has migrated twice to `eslint-plugin-i` and then to `eslint-plugin-import-x`. User are also not forced to migrate to the implicit `i/order` halfway only because we swapped the implementation to a fork.
|
|
301
|
-
>
|
|
302
|
-
> That said, it's probably still not a good idea. You might not want to doing this if you are maintaining your own eslint config.
|
|
303
|
-
>
|
|
304
|
-
> Feel free to open issues if you want to combine this config with some other config presets but faced naming collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the renaming.
|
|
305
|
-
|
|
306
|
-
### Rules Overrides
|
|
307
|
-
|
|
308
|
-
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
|
|
309
|
-
|
|
310
|
-
```js
|
|
311
|
-
// eslint.config.js
|
|
312
|
-
import antfu from '@antfu/eslint-config'
|
|
313
|
-
|
|
314
|
-
export default antfu(
|
|
315
|
-
{
|
|
316
|
-
vue: true,
|
|
317
|
-
typescript: true
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
321
|
-
files: ['**/*.vue'],
|
|
322
|
-
rules: {
|
|
323
|
-
'vue/operator-linebreak': ['error', 'before'],
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
// Without `files`, they are general rules for all files
|
|
328
|
-
rules: {
|
|
329
|
-
'style/semi': ['error', 'never'],
|
|
330
|
-
},
|
|
331
|
-
}
|
|
332
|
-
)
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
We also provided a `overrides` options in each integration to make it easier:
|
|
336
|
-
|
|
337
|
-
```js
|
|
338
|
-
// eslint.config.js
|
|
339
|
-
import antfu from '@antfu/eslint-config'
|
|
340
|
-
|
|
341
|
-
export default antfu({
|
|
342
|
-
vue: {
|
|
343
|
-
overrides: {
|
|
344
|
-
'vue/operator-linebreak': ['error', 'before'],
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
typescript: {
|
|
348
|
-
overrides: {
|
|
349
|
-
'ts/consistent-type-definitions': ['error', 'interface'],
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
|
-
yaml: {
|
|
353
|
-
overrides: {
|
|
354
|
-
// ...
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
})
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
### Optional Configs
|
|
361
|
-
|
|
362
|
-
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
363
|
-
|
|
364
|
-
#### Formatters
|
|
365
|
-
|
|
366
|
-
> [!WARNING]
|
|
367
|
-
> Experimental feature, changes might not follow semver.
|
|
368
|
-
|
|
369
|
-
Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
|
|
370
|
-
|
|
371
|
-
```js
|
|
372
|
-
// eslint.config.js
|
|
373
|
-
import antfu from '@antfu/eslint-config'
|
|
374
|
-
|
|
375
|
-
export default antfu({
|
|
376
|
-
formatters: {
|
|
377
|
-
/**
|
|
378
|
-
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
|
|
379
|
-
* By default uses Prettier
|
|
380
|
-
*/
|
|
381
|
-
css: true,
|
|
382
|
-
/**
|
|
383
|
-
* Format HTML files
|
|
384
|
-
* By default uses Prettier
|
|
385
|
-
*/
|
|
386
|
-
html: true,
|
|
387
|
-
/**
|
|
388
|
-
* Format Markdown files
|
|
389
|
-
* Supports Prettier and dprint
|
|
390
|
-
* By default uses Prettier
|
|
391
|
-
*/
|
|
392
|
-
markdown: 'prettier'
|
|
393
|
-
}
|
|
394
|
-
})
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
398
|
-
|
|
399
|
-
```bash
|
|
400
|
-
npm i -D eslint-plugin-format
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
#### React
|
|
404
|
-
|
|
405
|
-
To enable React support, you need to explicitly turn it on:
|
|
406
|
-
|
|
407
|
-
```js
|
|
408
|
-
// eslint.config.js
|
|
409
|
-
import antfu from '@antfu/eslint-config'
|
|
410
|
-
|
|
411
|
-
export default antfu({
|
|
412
|
-
react: true,
|
|
413
|
-
})
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
417
|
-
|
|
418
|
-
```bash
|
|
419
|
-
npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
#### Svelte
|
|
423
|
-
|
|
424
|
-
To enable svelte support, you need to explicitly turn it on:
|
|
425
|
-
|
|
426
|
-
```js
|
|
427
|
-
// eslint.config.js
|
|
428
|
-
import antfu from '@antfu/eslint-config'
|
|
36
|
+
const dhzh = require('@dhzh/eslint-config').default;
|
|
429
37
|
|
|
430
|
-
|
|
431
|
-
svelte: true,
|
|
432
|
-
})
|
|
38
|
+
module.exports = dhzh();
|
|
433
39
|
```
|
|
434
40
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
```bash
|
|
438
|
-
npm i -D eslint-plugin-svelte
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
#### Astro
|
|
442
|
-
|
|
443
|
-
To enable astro support, you need to explicitly turn it on:
|
|
444
|
-
|
|
445
|
-
```js
|
|
446
|
-
// eslint.config.js
|
|
447
|
-
import antfu from '@antfu/eslint-config'
|
|
448
|
-
|
|
449
|
-
export default antfu({
|
|
450
|
-
astro: true,
|
|
451
|
-
})
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
455
|
-
|
|
456
|
-
```bash
|
|
457
|
-
npm i -D eslint-plugin-astro
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
#### UnoCSS
|
|
461
|
-
|
|
462
|
-
To enable UnoCSS support, you need to explicitly turn it on:
|
|
463
|
-
|
|
464
|
-
```js
|
|
465
|
-
// eslint.config.js
|
|
466
|
-
import antfu from '@antfu/eslint-config'
|
|
467
|
-
|
|
468
|
-
export default antfu({
|
|
469
|
-
unocss: true,
|
|
470
|
-
})
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
474
|
-
|
|
475
|
-
```bash
|
|
476
|
-
npm i -D @unocss/eslint-plugin
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
### Optional Rules
|
|
480
|
-
|
|
481
|
-
This config also provides some optional plugins/rules for extended usage.
|
|
482
|
-
|
|
483
|
-
#### `perfectionist` (sorting)
|
|
484
|
-
|
|
485
|
-
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sorted object keys, imports, etc, with auto-fix.
|
|
486
|
-
|
|
487
|
-
The plugin is installed but no rules are enabled by default.
|
|
488
|
-
|
|
489
|
-
It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
|
|
490
|
-
|
|
491
|
-
```js
|
|
492
|
-
/* eslint perfectionist/sort-objects: "error" */
|
|
493
|
-
const objectWantedToSort = {
|
|
494
|
-
a: 2,
|
|
495
|
-
b: 1,
|
|
496
|
-
c: 3,
|
|
497
|
-
}
|
|
498
|
-
/* eslint perfectionist/sort-objects: "off" */
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
### Type Aware Rules
|
|
502
|
-
|
|
503
|
-
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
|
|
504
|
-
|
|
505
|
-
```js
|
|
506
|
-
// eslint.config.js
|
|
507
|
-
import antfu from '@antfu/eslint-config'
|
|
508
|
-
|
|
509
|
-
export default antfu({
|
|
510
|
-
typescript: {
|
|
511
|
-
tsconfigPath: 'tsconfig.json',
|
|
512
|
-
},
|
|
513
|
-
})
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
### Editor Specific Disables
|
|
517
|
-
|
|
518
|
-
Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
|
|
519
|
-
|
|
520
|
-
This is to prevent unused imports from getting removed by the IDE during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them:
|
|
521
|
-
|
|
522
|
-
```js
|
|
523
|
-
// eslint.config.js
|
|
524
|
-
import antfu from '@antfu/eslint-config'
|
|
525
|
-
|
|
526
|
-
export default antfu({
|
|
527
|
-
isInEditor: false
|
|
528
|
-
})
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
### Lint Staged
|
|
532
|
-
|
|
533
|
-
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
534
|
-
|
|
535
|
-
```json
|
|
536
|
-
{
|
|
537
|
-
"simple-git-hooks": {
|
|
538
|
-
"pre-commit": "pnpm lint-staged"
|
|
539
|
-
},
|
|
540
|
-
"lint-staged": {
|
|
541
|
-
"*": "eslint --fix"
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
and then
|
|
547
|
-
|
|
548
|
-
```bash
|
|
549
|
-
npm i -D lint-staged simple-git-hooks
|
|
550
|
-
|
|
551
|
-
// to active the hooks
|
|
552
|
-
npx simple-git-hooks
|
|
553
|
-
```
|
|
554
|
-
|
|
555
|
-
## View what rules are enabled
|
|
556
|
-
|
|
557
|
-
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)
|
|
558
|
-
|
|
559
|
-
Go to your project root that contains `eslint.config.js` and run:
|
|
560
|
-
|
|
561
|
-
```bash
|
|
562
|
-
npx eslint-flat-config-viewer
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
## Versioning Policy
|
|
566
|
-
|
|
567
|
-
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.
|
|
568
|
-
|
|
569
|
-
### Changes Considered as Breaking Changes
|
|
570
|
-
|
|
571
|
-
- Node.js version requirement changes
|
|
572
|
-
- Huge refactors that might break the config
|
|
573
|
-
- Plugins made major changes that might break the config
|
|
574
|
-
- Changes that might affect most of the codebases
|
|
575
|
-
|
|
576
|
-
### Changes Considered as Non-breaking Changes
|
|
577
|
-
|
|
578
|
-
- Enable/disable rules and plugins (that might become stricter)
|
|
579
|
-
- Rules options changes
|
|
580
|
-
- Version bumps of dependencies
|
|
581
|
-
|
|
582
|
-
## Badge
|
|
583
|
-
|
|
584
|
-
If you enjoy this code style, and would like to mention it in your project, here is the badge you can use:
|
|
585
|
-
|
|
586
|
-
```md
|
|
587
|
-
[](https://github.com/antfu/eslint-config)
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
[](https://github.com/antfu/eslint-config)
|
|
591
|
-
|
|
592
|
-
## FAQ
|
|
593
|
-
|
|
594
|
-
### Prettier?
|
|
595
|
-
|
|
596
|
-
[Why I don't use Prettier](https://antfu.me/posts/why-not-prettier)
|
|
597
|
-
|
|
598
|
-
Well, you can still use Prettier to format files that are not supported well by ESLint yet, such as `.css`, `.html`, etc. See [formatters](#formatters) for more details.
|
|
599
|
-
|
|
600
|
-
### dprint?
|
|
601
|
-
|
|
602
|
-
[dprint](https://dprint.dev/) is also a great formatter that with more abilities to customize. However, it's in the same model as Prettier which reads the AST and reprints the code from scratch. This means it's similar to Prettier, which ignores the original line breaks and might also cause the inconsistent diff. So in general, we prefer to use ESLint to format and lint JavaScript/TypeScript code.
|
|
603
|
-
|
|
604
|
-
Meanwhile, we do have dprint integrations for formatting other files such as `.md`. See [formatters](#formatters) for more details.
|
|
605
|
-
|
|
606
|
-
### How to format CSS?
|
|
607
|
-
|
|
608
|
-
You can opt-in to the [`formatters`](#formatters) feature to format your CSS. Note that it's only doing formatting, but not linting. If you want proper linting support, give [`stylelint`](https://stylelint.io/) a try.
|
|
609
|
-
|
|
610
|
-
### I prefer XXX...
|
|
611
|
-
|
|
612
|
-
Sure, you can configure and override rules locally in your project to fit your needs. If that still does not work for you, you can always fork this repo and maintain your own.
|
|
613
|
-
|
|
614
|
-
## Check Also
|
|
615
|
-
|
|
616
|
-
- [antfu/dotfiles](https://github.com/antfu/dotfiles) - My dotfiles
|
|
617
|
-
- [antfu/vscode-settings](https://github.com/antfu/vscode-settings) - My VS Code settings
|
|
618
|
-
- [antfu/starter-ts](https://github.com/antfu/starter-ts) - My starter template for TypeScript library
|
|
619
|
-
- [antfu/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app
|
|
41
|
+
More details, you can see [README-antfu](./README-antfu.md).
|
|
620
42
|
|
|
621
43
|
## License
|
|
622
44
|
|
|
623
|
-
[MIT](./LICENSE) License ©
|
|
45
|
+
[MIT](./LICENSE) License © 2024-PRESENT [Easton Zheng](https://github.com/eastonzh)
|
package/dist/cli.cjs
CHANGED
|
@@ -48,7 +48,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
48
48
|
var package_default = {
|
|
49
49
|
name: "@dhzh/eslint-config",
|
|
50
50
|
type: "module",
|
|
51
|
-
version: "0.1.
|
|
51
|
+
version: "0.1.2",
|
|
52
52
|
packageManager: "pnpm@8.15.4",
|
|
53
53
|
description: "Easton's ESLint config",
|
|
54
54
|
author: "Easton Zheng <dhzhme@gmail.com>",
|
|
@@ -88,9 +88,6 @@ var package_default = {
|
|
|
88
88
|
eslint: ">=8.40.0",
|
|
89
89
|
"eslint-plugin-astro": "^0.31.4",
|
|
90
90
|
"eslint-plugin-format": ">=0.1.0",
|
|
91
|
-
"eslint-plugin-react": "^7.33.2",
|
|
92
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
93
|
-
"eslint-plugin-react-refresh": "^0.4.4",
|
|
94
91
|
"eslint-plugin-svelte": "^2.34.1",
|
|
95
92
|
"prettier-plugin-astro": "^0.13.0",
|
|
96
93
|
"prettier-plugin-slidev": "^1.0.5",
|
|
@@ -109,15 +106,6 @@ var package_default = {
|
|
|
109
106
|
"eslint-plugin-format": {
|
|
110
107
|
optional: true
|
|
111
108
|
},
|
|
112
|
-
"eslint-plugin-react": {
|
|
113
|
-
optional: true
|
|
114
|
-
},
|
|
115
|
-
"eslint-plugin-react-hooks": {
|
|
116
|
-
optional: true
|
|
117
|
-
},
|
|
118
|
-
"eslint-plugin-react-refresh": {
|
|
119
|
-
optional: true
|
|
120
|
-
},
|
|
121
109
|
"eslint-plugin-svelte": {
|
|
122
110
|
optional: true
|
|
123
111
|
},
|
|
@@ -152,6 +140,9 @@ var package_default = {
|
|
|
152
140
|
"eslint-plugin-n": "^16.6.2",
|
|
153
141
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
154
142
|
"eslint-plugin-perfectionist": "^2.6.0",
|
|
143
|
+
"eslint-plugin-react": "^7.34.1",
|
|
144
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
145
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
155
146
|
"eslint-plugin-toml": "^0.9.2",
|
|
156
147
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
157
148
|
"eslint-plugin-unused-imports": "^3.1.0",
|
|
@@ -170,9 +161,9 @@ var package_default = {
|
|
|
170
161
|
yargs: "^17.7.2"
|
|
171
162
|
},
|
|
172
163
|
devDependencies: {
|
|
173
|
-
"@antfu/eslint-config": "workspace:*",
|
|
174
164
|
"@antfu/eslint-plugin-prettier": "^5.0.1-1",
|
|
175
165
|
"@antfu/ni": "^0.21.12",
|
|
166
|
+
"@dhzh/eslint-config": "workspace:*",
|
|
176
167
|
"@stylistic/eslint-plugin-migrate": "^1.7.0",
|
|
177
168
|
"@types/eslint": "^8.56.5",
|
|
178
169
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -186,9 +177,6 @@ var package_default = {
|
|
|
186
177
|
"eslint-flat-config-viewer": "^0.1.11",
|
|
187
178
|
"eslint-plugin-astro": "^0.31.4",
|
|
188
179
|
"eslint-plugin-format": "^0.1.0",
|
|
189
|
-
"eslint-plugin-react": "^7.34.0",
|
|
190
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
191
|
-
"eslint-plugin-react-refresh": "^0.4.6",
|
|
192
180
|
"eslint-plugin-svelte": "^2.35.1",
|
|
193
181
|
"eslint-ts-patch": "^8.57.0-0",
|
|
194
182
|
esno: "^4.7.0",
|
|
@@ -261,14 +249,14 @@ var vscodeSettingsString = `
|
|
|
261
249
|
]
|
|
262
250
|
`;
|
|
263
251
|
var frameworkOptions = [
|
|
264
|
-
{
|
|
265
|
-
label: import_picocolors.default.green("Vue"),
|
|
266
|
-
value: "vue"
|
|
267
|
-
},
|
|
268
252
|
{
|
|
269
253
|
label: import_picocolors.default.cyan("React"),
|
|
270
254
|
value: "react"
|
|
271
255
|
},
|
|
256
|
+
{
|
|
257
|
+
label: import_picocolors.default.green("Vue"),
|
|
258
|
+
value: "vue"
|
|
259
|
+
},
|
|
272
260
|
{
|
|
273
261
|
label: import_picocolors.default.red("Svelte"),
|
|
274
262
|
value: "svelte"
|
|
@@ -300,11 +288,7 @@ var dependenciesMap = {
|
|
|
300
288
|
"eslint-plugin-astro",
|
|
301
289
|
"astro-eslint-parser"
|
|
302
290
|
],
|
|
303
|
-
react: [
|
|
304
|
-
"eslint-plugin-react",
|
|
305
|
-
"eslint-plugin-react-hooks",
|
|
306
|
-
"eslint-plugin-react-refresh"
|
|
307
|
-
],
|
|
291
|
+
react: [],
|
|
308
292
|
slidev: [
|
|
309
293
|
"prettier-plugin-slidev"
|
|
310
294
|
],
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import c from "picocolors";
|
|
|
19
19
|
var package_default = {
|
|
20
20
|
name: "@dhzh/eslint-config",
|
|
21
21
|
type: "module",
|
|
22
|
-
version: "0.1.
|
|
22
|
+
version: "0.1.2",
|
|
23
23
|
packageManager: "pnpm@8.15.4",
|
|
24
24
|
description: "Easton's ESLint config",
|
|
25
25
|
author: "Easton Zheng <dhzhme@gmail.com>",
|
|
@@ -59,9 +59,6 @@ var package_default = {
|
|
|
59
59
|
eslint: ">=8.40.0",
|
|
60
60
|
"eslint-plugin-astro": "^0.31.4",
|
|
61
61
|
"eslint-plugin-format": ">=0.1.0",
|
|
62
|
-
"eslint-plugin-react": "^7.33.2",
|
|
63
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
64
|
-
"eslint-plugin-react-refresh": "^0.4.4",
|
|
65
62
|
"eslint-plugin-svelte": "^2.34.1",
|
|
66
63
|
"prettier-plugin-astro": "^0.13.0",
|
|
67
64
|
"prettier-plugin-slidev": "^1.0.5",
|
|
@@ -80,15 +77,6 @@ var package_default = {
|
|
|
80
77
|
"eslint-plugin-format": {
|
|
81
78
|
optional: true
|
|
82
79
|
},
|
|
83
|
-
"eslint-plugin-react": {
|
|
84
|
-
optional: true
|
|
85
|
-
},
|
|
86
|
-
"eslint-plugin-react-hooks": {
|
|
87
|
-
optional: true
|
|
88
|
-
},
|
|
89
|
-
"eslint-plugin-react-refresh": {
|
|
90
|
-
optional: true
|
|
91
|
-
},
|
|
92
80
|
"eslint-plugin-svelte": {
|
|
93
81
|
optional: true
|
|
94
82
|
},
|
|
@@ -123,6 +111,9 @@ var package_default = {
|
|
|
123
111
|
"eslint-plugin-n": "^16.6.2",
|
|
124
112
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
125
113
|
"eslint-plugin-perfectionist": "^2.6.0",
|
|
114
|
+
"eslint-plugin-react": "^7.34.1",
|
|
115
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
116
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
126
117
|
"eslint-plugin-toml": "^0.9.2",
|
|
127
118
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
128
119
|
"eslint-plugin-unused-imports": "^3.1.0",
|
|
@@ -141,9 +132,9 @@ var package_default = {
|
|
|
141
132
|
yargs: "^17.7.2"
|
|
142
133
|
},
|
|
143
134
|
devDependencies: {
|
|
144
|
-
"@antfu/eslint-config": "workspace:*",
|
|
145
135
|
"@antfu/eslint-plugin-prettier": "^5.0.1-1",
|
|
146
136
|
"@antfu/ni": "^0.21.12",
|
|
137
|
+
"@dhzh/eslint-config": "workspace:*",
|
|
147
138
|
"@stylistic/eslint-plugin-migrate": "^1.7.0",
|
|
148
139
|
"@types/eslint": "^8.56.5",
|
|
149
140
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -157,9 +148,6 @@ var package_default = {
|
|
|
157
148
|
"eslint-flat-config-viewer": "^0.1.11",
|
|
158
149
|
"eslint-plugin-astro": "^0.31.4",
|
|
159
150
|
"eslint-plugin-format": "^0.1.0",
|
|
160
|
-
"eslint-plugin-react": "^7.34.0",
|
|
161
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
162
|
-
"eslint-plugin-react-refresh": "^0.4.6",
|
|
163
151
|
"eslint-plugin-svelte": "^2.35.1",
|
|
164
152
|
"eslint-ts-patch": "^8.57.0-0",
|
|
165
153
|
esno: "^4.7.0",
|
|
@@ -232,14 +220,14 @@ var vscodeSettingsString = `
|
|
|
232
220
|
]
|
|
233
221
|
`;
|
|
234
222
|
var frameworkOptions = [
|
|
235
|
-
{
|
|
236
|
-
label: c.green("Vue"),
|
|
237
|
-
value: "vue"
|
|
238
|
-
},
|
|
239
223
|
{
|
|
240
224
|
label: c.cyan("React"),
|
|
241
225
|
value: "react"
|
|
242
226
|
},
|
|
227
|
+
{
|
|
228
|
+
label: c.green("Vue"),
|
|
229
|
+
value: "vue"
|
|
230
|
+
},
|
|
243
231
|
{
|
|
244
232
|
label: c.red("Svelte"),
|
|
245
233
|
value: "svelte"
|
|
@@ -271,11 +259,7 @@ var dependenciesMap = {
|
|
|
271
259
|
"eslint-plugin-astro",
|
|
272
260
|
"astro-eslint-parser"
|
|
273
261
|
],
|
|
274
|
-
react: [
|
|
275
|
-
"eslint-plugin-react",
|
|
276
|
-
"eslint-plugin-react-hooks",
|
|
277
|
-
"eslint-plugin-react-refresh"
|
|
278
|
-
],
|
|
262
|
+
react: [],
|
|
279
263
|
slidev: [
|
|
280
264
|
"prettier-plugin-slidev"
|
|
281
265
|
],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhzh/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"packageManager": "pnpm@8.15.4",
|
|
6
6
|
"description": "Easton's ESLint config",
|
|
7
7
|
"author": "Easton Zheng <dhzhme@gmail.com>",
|
|
@@ -29,9 +29,6 @@
|
|
|
29
29
|
"eslint": ">=8.40.0",
|
|
30
30
|
"eslint-plugin-astro": "^0.31.4",
|
|
31
31
|
"eslint-plugin-format": ">=0.1.0",
|
|
32
|
-
"eslint-plugin-react": "^7.33.2",
|
|
33
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
34
|
-
"eslint-plugin-react-refresh": "^0.4.4",
|
|
35
32
|
"eslint-plugin-svelte": "^2.34.1",
|
|
36
33
|
"prettier-plugin-astro": "^0.13.0",
|
|
37
34
|
"prettier-plugin-slidev": "^1.0.5",
|
|
@@ -50,15 +47,6 @@
|
|
|
50
47
|
"eslint-plugin-format": {
|
|
51
48
|
"optional": true
|
|
52
49
|
},
|
|
53
|
-
"eslint-plugin-react": {
|
|
54
|
-
"optional": true
|
|
55
|
-
},
|
|
56
|
-
"eslint-plugin-react-hooks": {
|
|
57
|
-
"optional": true
|
|
58
|
-
},
|
|
59
|
-
"eslint-plugin-react-refresh": {
|
|
60
|
-
"optional": true
|
|
61
|
-
},
|
|
62
50
|
"eslint-plugin-svelte": {
|
|
63
51
|
"optional": true
|
|
64
52
|
},
|
|
@@ -93,6 +81,9 @@
|
|
|
93
81
|
"eslint-plugin-n": "^16.6.2",
|
|
94
82
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
95
83
|
"eslint-plugin-perfectionist": "^2.6.0",
|
|
84
|
+
"eslint-plugin-react": "^7.34.1",
|
|
85
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
86
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
96
87
|
"eslint-plugin-toml": "^0.9.2",
|
|
97
88
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
98
89
|
"eslint-plugin-unused-imports": "^3.1.0",
|
|
@@ -126,9 +117,6 @@
|
|
|
126
117
|
"eslint-flat-config-viewer": "^0.1.11",
|
|
127
118
|
"eslint-plugin-astro": "^0.31.4",
|
|
128
119
|
"eslint-plugin-format": "^0.1.0",
|
|
129
|
-
"eslint-plugin-react": "^7.34.0",
|
|
130
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
131
|
-
"eslint-plugin-react-refresh": "^0.4.6",
|
|
132
120
|
"eslint-plugin-svelte": "^2.35.1",
|
|
133
121
|
"eslint-ts-patch": "^8.57.0-0",
|
|
134
122
|
"esno": "^4.7.0",
|
|
@@ -146,7 +134,7 @@
|
|
|
146
134
|
"typescript": "^5.4.2",
|
|
147
135
|
"vitest": "^1.3.1",
|
|
148
136
|
"vue": "^3.4.21",
|
|
149
|
-
"@
|
|
137
|
+
"@dhzh/eslint-config": "0.1.2"
|
|
150
138
|
},
|
|
151
139
|
"simple-git-hooks": {
|
|
152
140
|
"pre-commit": "pnpm lint-staged"
|