8
8
- Lint also for json, yaml, markdown
9
9
- Sorted imports, dangling commas
10
10
- Reasonable defaults, best practices, only one-line of config
11
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
11
12
- **Style principle**: Minimal for reading, stable for diff
12
13
13
-
> Configs uses [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
14
+
> Configs uses [🌈 ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
15
+
16
+
> [!IMPORTANT]
17
+
> The main branch is for v1.0-beta, which rewrites to ESLint Flat config, check #250 for more details.
14
18
15
19
## Usage
16
20
20
24
pnpm add -D eslint @antfu/eslint-config
21
25
```
22
26
23
-
### Config `.eslintrc`
27
+
### Create config file
24
28
25
-
```json
26
-
{
27
-
"extends": "@antfu"
28
-
}
29
+
```js
30
+
// eslint.config.js
31
+
import antfu from '@antfu/eslint-config'
32
+
33
+
export default [
34
+
...antfu,
35
+
{
36
+
rules: {
37
+
// your overrides
38
+
},
39
+
},
40
+
]
29
41
```
30
42
31
43
> You don't need `.eslintignore` normally as it has been provided by the preset.
@@ -43,14 +55,18 @@ For example:
43
55
}
44
56
```
45
57
46
-
### VS Code support (auto fix)
58
+
## VS Code support (auto fix)
47
59
48
60
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
49
61
50
62
Add the following settings to your `settings.json`:
51
63
52
64
```jsonc
53
65
{
66
+
// Enable the flat config support
67
+
"eslint.experimental.useFlatConfig": true,
68
+
69
+
// Disable the default formatter
54
70
"prettier.enable": false,
55
71
"editor.formatOnSave": false,
56
72
@@ -87,19 +103,98 @@ Add the following settings to your `settings.json`:
87
103
}
88
104
```
89
105
90
-
### TypeScript Aware Rules
106
+
## Flat Config
91
107
92
-
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
108
+
Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), provides a much better organization and composition.
109
+
110
+
You can now compose your own config easily:
93
111
94
112
```js
95
-
// .eslintrc.js
96
-
const process = require('node:process')
113
+
// eslint.config.js
114
+
import {
115
+
presetAuto,
116
+
presetJavaScriptCore,
117
+
presetLangsExtensions,
118
+
presetTypeScript,
119
+
} from '@antfu/eslint-config'
120
+
121
+
export default [
122
+
// javascript, node, unicorn, jsdoc, imports, etc.
123
+
...presetJavaScriptCore,
124
+
// typescript support
125
+
...presetTypeScript,
126
+
// yaml, markdown, json, support
127
+
...presetLangsExtensions,
128
+
]
129
+
```
97
130
98
-
process.env.ESLINT_TSCONFIG = 'tsconfig.json'
131
+
Or even more granular:
99
132
100
-
module.exports = {
101
-
extends: '@antfu'
102
-
}
133
+
```js
134
+
// eslint.config.js
135
+
import {
136
+
comments,
137
+
ignores,
138
+
imports,
139
+
javascript,
140
+
javascriptStylistic,
141
+
jsdoc,
142
+
jsonc,
143
+
markdown,
144
+
node,
145
+
sortPackageJson,
146
+
sortTsconfig,
147
+
typescript,
148
+
typescriptStylistic,
149
+
unicorn,
150
+
vue,
151
+
yml,
152
+
} from '@antfu/eslint-config'
153
+
154
+
export default [
155
+
...ignores,
156
+
...javascript,
157
+
...comments,
158
+
...node,
159
+
...jsdoc,
160
+
...imports,
161
+
...unicorn,
162
+
...javascriptStylistic,
163
+
164
+
...typescript,
165
+
...typescriptStylistic,
166
+
167
+
...vue,
168
+
169
+
...jsonc,
170
+
...yml,
171
+
...markdown,
172
+
]
173
+
```
174
+
175
+
Check out the [presets](https://github.com/antfu/eslint-config/blob/main/packages/eslint-config/src/presets.ts) and [configs](https://github.com/antfu/eslint-config/blob/main/packages/eslint-config/src/configs) for more details.
176
+
177
+
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
178
+
179
+
### Type Aware Rules
180
+
181
+
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by importing `typescriptWithLanguageServer` config:
182
+
183
+
```js
184
+
// eslint.config.js
185
+
import { presetAuto, typescriptWithLanguageServer } from '@antfu/eslint-config'
186
+
187
+
export default [
188
+
...presetAuto,
189
+
...typescriptWithLanguageServer({
190
+
tsconfig: 'tsconfig.json', // path to your tsconfig
191
+
}),
192
+
{
193
+
rules: {
194
+
// your overrides
195
+
},
196
+
},
197
+
]
103
198
```
104
199
105
200
### Lint Staged
@@ -145,20 +240,7 @@ This config does NOT lint CSS. I personally use [UnoCSS](https://github.com/unoc
145
240
146
241
### I prefer XXX...
147
242
148
-
Sure, you can override the rules in your `.eslintrc` file.
149
-
150
-
<!-- eslint-skip -->
151
-
152
-
```jsonc
153
-
{
154
-
"extends": "@antfu",
155
-
"rules": {
156
-
// your rules...
157
-
}
158
-
}
159
-
```
160
-
161
-
Or you can always fork this repo and make your own.
243
+
Sure, you can override rules locally in your project to fit your needs. Or you can always fork this repo and make your own.
162
244
163
245
## Check Also
164
246
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4