@antfu/eslint-config 1.0.0-beta.0 → 1.0.0-beta.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/README.md +289 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +673 -659
- package/package.json +33 -9
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# @antfu/eslint-config
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@antfu/eslint-config) [](https://github.com/antfu/eslint-config)
|
|
4
|
+
|
|
5
|
+
- Single quotes, no semi
|
|
6
|
+
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
7
|
+
- Designed to work with TypeScript, Vue out-of-box
|
|
8
|
+
- Lint also for json, yaml, markdown
|
|
9
|
+
- Sorted imports, dangling commas
|
|
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!
|
|
12
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
13
|
+
- **Style principle**: Minimal for reading, stable for diff
|
|
14
|
+
|
|
15
|
+
> [!IMPORTANT]
|
|
16
|
+
> The main branch is for v1.0-beta, which rewrites to ESLint Flat config, check [#250](https://github.com/antfu/eslint-config/pull/250) for more details.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add -D eslint @antfu/eslint-config
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Create config file
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// eslint.config.js
|
|
30
|
+
import antfu from '@antfu/eslint-config'
|
|
31
|
+
|
|
32
|
+
export default antfu()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
> You don't need `.eslintignore` normally as it has been provided by the preset.
|
|
36
|
+
|
|
37
|
+
### Add script for package.json
|
|
38
|
+
|
|
39
|
+
For example:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"scripts": {
|
|
44
|
+
"lint": "eslint .",
|
|
45
|
+
"lint:fix": "eslint . --fix"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## VS Code support (auto fix)
|
|
51
|
+
|
|
52
|
+
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
53
|
+
|
|
54
|
+
Add the following settings to your `settings.json`:
|
|
55
|
+
|
|
56
|
+
```jsonc
|
|
57
|
+
{
|
|
58
|
+
// Enable the flat config support
|
|
59
|
+
"eslint.experimental.useFlatConfig": true,
|
|
60
|
+
|
|
61
|
+
// Disable the default formatter
|
|
62
|
+
"prettier.enable": false,
|
|
63
|
+
"editor.formatOnSave": false,
|
|
64
|
+
|
|
65
|
+
// Auto fix
|
|
66
|
+
"editor.codeActionsOnSave": {
|
|
67
|
+
"source.fixAll.eslint": true,
|
|
68
|
+
"source.organizeImports": false
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
72
|
+
"eslint.rules.customizations": [
|
|
73
|
+
{ "rule": "@stylistic/*", "severity": "off" },
|
|
74
|
+
{ "rule": "*-indent", "severity": "off" },
|
|
75
|
+
{ "rule": "*-spacing", "severity": "off" },
|
|
76
|
+
{ "rule": "*-spaces", "severity": "off" },
|
|
77
|
+
{ "rule": "*-order", "severity": "off" },
|
|
78
|
+
{ "rule": "*-dangle", "severity": "off" },
|
|
79
|
+
{ "rule": "*-newline", "severity": "off" },
|
|
80
|
+
{ "rule": "*quotes", "severity": "off" },
|
|
81
|
+
{ "rule": "*semi", "severity": "off" }
|
|
82
|
+
],
|
|
83
|
+
|
|
84
|
+
// The following is optional.
|
|
85
|
+
// It's better to put under project setting `.vscode/settings.json`
|
|
86
|
+
// to avoid conflicts with working with different eslint configs
|
|
87
|
+
// that does not support all formats.
|
|
88
|
+
"eslint.validate": [
|
|
89
|
+
"javascript",
|
|
90
|
+
"javascriptreact",
|
|
91
|
+
"typescript",
|
|
92
|
+
"typescriptreact",
|
|
93
|
+
"vue",
|
|
94
|
+
"html",
|
|
95
|
+
"markdown",
|
|
96
|
+
"json",
|
|
97
|
+
"jsonc",
|
|
98
|
+
"yaml"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Customization
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
Normally you only need to import the `antfu` preset:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
// eslint.config.js
|
|
111
|
+
import antfu from '@antfu/eslint-config'
|
|
112
|
+
|
|
113
|
+
export default antfu()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
You can configure each feature individually, for example:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
// eslint.config.js
|
|
120
|
+
import antfu from '@antfu/eslint-config'
|
|
121
|
+
|
|
122
|
+
export default antfu({
|
|
123
|
+
stylistic: true, // enable stylistic formatting rules
|
|
124
|
+
typescript: true,
|
|
125
|
+
vue: true,
|
|
126
|
+
jsonc: false,
|
|
127
|
+
yml: false,
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The `antfu` factory functions also accepts arbitrary numbers of constom configs overrides:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
// eslint.config.js
|
|
135
|
+
import antfu from '@antfu/eslint-config'
|
|
136
|
+
|
|
137
|
+
export default antfu(
|
|
138
|
+
{
|
|
139
|
+
// Configures for antfu's config
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// From the second arguments they are ESLint Flat Configs
|
|
143
|
+
// you can have multiple configs
|
|
144
|
+
{
|
|
145
|
+
rules: {},
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
rules: {},
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Going more advanced, you can also import the very fine-grained configs and compose them as you wish:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
// eslint.config.js
|
|
157
|
+
import {
|
|
158
|
+
comments,
|
|
159
|
+
ignores,
|
|
160
|
+
imports,
|
|
161
|
+
javascript,
|
|
162
|
+
javascriptStylistic,
|
|
163
|
+
jsdoc,
|
|
164
|
+
jsonc,
|
|
165
|
+
markdown,
|
|
166
|
+
node,
|
|
167
|
+
sortPackageJson,
|
|
168
|
+
sortTsconfig,
|
|
169
|
+
typescript,
|
|
170
|
+
typescriptStylistic,
|
|
171
|
+
unicorn,
|
|
172
|
+
vue,
|
|
173
|
+
yml,
|
|
174
|
+
} from '@antfu/eslint-config'
|
|
175
|
+
|
|
176
|
+
export default [
|
|
177
|
+
...ignores,
|
|
178
|
+
...javascript(),
|
|
179
|
+
...comments,
|
|
180
|
+
...node,
|
|
181
|
+
...jsdoc,
|
|
182
|
+
...imports,
|
|
183
|
+
...unicorn,
|
|
184
|
+
...javascriptStylistic,
|
|
185
|
+
|
|
186
|
+
...typescript(),
|
|
187
|
+
...typescriptStylistic,
|
|
188
|
+
|
|
189
|
+
...vue(),
|
|
190
|
+
...jsonc,
|
|
191
|
+
...yml,
|
|
192
|
+
...markdown(),
|
|
193
|
+
]
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
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.
|
|
197
|
+
|
|
198
|
+
> Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
|
|
199
|
+
|
|
200
|
+
## Plugins Renaming
|
|
201
|
+
|
|
202
|
+
Since flat config support explicit provides the plugin names, we renamed some plugins to make them more consistent and hide the implementation details.
|
|
203
|
+
|
|
204
|
+
| Original Prefix | New Prefix | Source Plugin |
|
|
205
|
+
| --------------- | ---------- | ------------- |
|
|
206
|
+
| `i/*` | `import/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
|
|
207
|
+
| `n/*` | `node` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n)
|
|
208
|
+
| `@typescript-eslint/*` | `ts/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
209
|
+
| `@stylistic/js` | `style/*` | [@stylistic/eslint-plugin-js](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
210
|
+
| `@stylistic/ts` | `style-ts/` | [@stylistic/eslint-plugin-ts](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
211
|
+
|
|
212
|
+
When you want to overrides rules, or disable them inline, you need to update to the new prefix:
|
|
213
|
+
|
|
214
|
+
```diff
|
|
215
|
+
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
216
|
+
+// eslint-disable-next-line ts/consistent-type-definitions
|
|
217
|
+
type foo = { bar: 2 }
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Type Aware Rules
|
|
221
|
+
|
|
222
|
+
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
// eslint.config.js
|
|
226
|
+
import antfu from '@antfu/eslint-config'
|
|
227
|
+
|
|
228
|
+
export default antfu({
|
|
229
|
+
typescript: {
|
|
230
|
+
tsconfigPath: 'tsconfig.json',
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Lint Staged
|
|
236
|
+
|
|
237
|
+
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
238
|
+
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"simple-git-hooks": {
|
|
242
|
+
"pre-commit": "pnpm lint-staged"
|
|
243
|
+
},
|
|
244
|
+
"lint-staged": {
|
|
245
|
+
"*": "eslint --fix"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
and then
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
npm i -D lint-staged simple-git-hooks
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Badge
|
|
257
|
+
|
|
258
|
+
If you enjoy this code style, and would like to mention it in your project, here is the badge you can use:
|
|
259
|
+
|
|
260
|
+
```md
|
|
261
|
+
[](https://github.com/antfu/eslint-config)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
[](https://github.com/antfu/eslint-config)
|
|
265
|
+
|
|
266
|
+
## FAQ
|
|
267
|
+
|
|
268
|
+
### Prettier?
|
|
269
|
+
|
|
270
|
+
[Why I don't use Prettier](https://antfu.me/posts/why-not-prettier)
|
|
271
|
+
|
|
272
|
+
### How to lint CSS?
|
|
273
|
+
|
|
274
|
+
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.
|
|
275
|
+
|
|
276
|
+
### I prefer XXX...
|
|
277
|
+
|
|
278
|
+
Sure, you can config 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.
|
|
279
|
+
|
|
280
|
+
## Check Also
|
|
281
|
+
|
|
282
|
+
- [antfu/dotfiles](https://github.com/antfu/dotfiles) - My dotfiles
|
|
283
|
+
- [antfu/vscode-settings](https://github.com/antfu/vscode-settings) - My VS Code settings
|
|
284
|
+
- [antfu/ts-starter](https://github.com/antfu/ts-starter) - My starter template for TypeScript library
|
|
285
|
+
- [antfu/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
[MIT](./LICENSE) License © 2019-PRESENT [Anthony Fu](https://github.com/antfu)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { FlatESLintConfigItem } from 'eslint-define-config';
|
|
2
|
+
export { default as pluginAntfu } from 'eslint-plugin-antfu';
|
|
3
|
+
export { default as pluginComments } from 'eslint-plugin-eslint-comments';
|
|
4
|
+
export { default as pluginImport } from 'eslint-plugin-i';
|
|
5
|
+
export { default as pluginJsdoc } from 'eslint-plugin-jsdoc';
|
|
6
|
+
export { default as pluginJsonc } from 'eslint-plugin-jsonc';
|
|
7
|
+
export { default as pluginMarkdown } from 'eslint-plugin-markdown';
|
|
8
|
+
export { default as pluginNode } from 'eslint-plugin-n';
|
|
9
|
+
export { default as pluginStylisticJs } from '@stylistic/eslint-plugin-js';
|
|
10
|
+
export { default as pluginStylisticTs } from '@stylistic/eslint-plugin-ts';
|
|
11
|
+
export { default as pluginTs } from '@typescript-eslint/eslint-plugin';
|
|
12
|
+
export { default as pluginUnicorn } from 'eslint-plugin-unicorn';
|
|
13
|
+
export { default as pluginUnusedImports } from 'eslint-plugin-unused-imports';
|
|
14
|
+
export { default as pluginVue } from 'eslint-plugin-vue';
|
|
15
|
+
export { default as pluginYml } from 'eslint-plugin-yml';
|
|
16
|
+
export { default as pluginNoOnlyTests } from 'eslint-plugin-no-only-tests';
|
|
17
|
+
export { default as parserTs } from '@typescript-eslint/parser';
|
|
18
|
+
export { default as parserVue } from 'vue-eslint-parser';
|
|
19
|
+
export { default as parserYml } from 'yaml-eslint-parser';
|
|
20
|
+
export { default as parserJsonc } from 'jsonc-eslint-parser';
|
|
21
|
+
|
|
22
|
+
interface OptionsComponentExts {
|
|
23
|
+
/**
|
|
24
|
+
* Additional extensions for components.
|
|
25
|
+
*
|
|
26
|
+
* @example ['vue']
|
|
27
|
+
* @default []
|
|
28
|
+
*/
|
|
29
|
+
componentExts?: string[];
|
|
30
|
+
}
|
|
31
|
+
interface OptionsTypeScriptWithLanguageServer {
|
|
32
|
+
tsconfigPath: string;
|
|
33
|
+
tsconfigRootDir?: string;
|
|
34
|
+
}
|
|
35
|
+
interface OptionsHasTypeScript {
|
|
36
|
+
typescript?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface OptionsIsInEditor {
|
|
39
|
+
isInEditor?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface OptionsConfig {
|
|
42
|
+
/**
|
|
43
|
+
* Enable TypeScript support.
|
|
44
|
+
*
|
|
45
|
+
* Passing an object to enable TypeScript Language Server support.
|
|
46
|
+
*
|
|
47
|
+
* @default auto-detect based on the dependencies
|
|
48
|
+
*/
|
|
49
|
+
typescript?: boolean | OptionsTypeScriptWithLanguageServer;
|
|
50
|
+
/**
|
|
51
|
+
* Enable test support.
|
|
52
|
+
*
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
test?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Enable Vue support.
|
|
58
|
+
*
|
|
59
|
+
* @default auto-detect based on the dependencies
|
|
60
|
+
*/
|
|
61
|
+
vue?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Enable JSONC support.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
jsonc?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Enable YAML support.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
yaml?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enable Markdown support.
|
|
76
|
+
*
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
markdown?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Enable stylistic rules.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
stylistic?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Control to disable some rules in editors.
|
|
88
|
+
* @default auto-detect based on the process.env
|
|
89
|
+
*/
|
|
90
|
+
isInEditor?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Construct an array of ESLint flat config items.
|
|
95
|
+
*/
|
|
96
|
+
declare function antfu(options?: OptionsConfig, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
|
|
97
|
+
|
|
98
|
+
declare const comments: FlatESLintConfigItem[];
|
|
99
|
+
|
|
100
|
+
declare const ignores: FlatESLintConfigItem[];
|
|
101
|
+
|
|
102
|
+
declare const imports: FlatESLintConfigItem[];
|
|
103
|
+
|
|
104
|
+
declare function javascript(options?: OptionsIsInEditor): FlatESLintConfigItem[];
|
|
105
|
+
|
|
106
|
+
declare const jsdoc: FlatESLintConfigItem[];
|
|
107
|
+
|
|
108
|
+
declare const jsonc: FlatESLintConfigItem[];
|
|
109
|
+
|
|
110
|
+
declare function markdown(options?: OptionsComponentExts): FlatESLintConfigItem[];
|
|
111
|
+
|
|
112
|
+
declare const node: FlatESLintConfigItem[];
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Sort package.json
|
|
116
|
+
*
|
|
117
|
+
* Requires `jsonc` config
|
|
118
|
+
*/
|
|
119
|
+
declare const sortPackageJson: FlatESLintConfigItem[];
|
|
120
|
+
/**
|
|
121
|
+
* Sort tsconfig.json
|
|
122
|
+
*
|
|
123
|
+
* Requires `jsonc` config
|
|
124
|
+
*/
|
|
125
|
+
declare const sortTsconfig: FlatESLintConfigItem[];
|
|
126
|
+
|
|
127
|
+
declare const javascriptStylistic: FlatESLintConfigItem[];
|
|
128
|
+
declare const typescriptStylistic: FlatESLintConfigItem[];
|
|
129
|
+
|
|
130
|
+
declare function typescript(options?: OptionsComponentExts): FlatESLintConfigItem[];
|
|
131
|
+
declare function typescriptWithLanguageServer(options: OptionsTypeScriptWithLanguageServer & OptionsComponentExts): FlatESLintConfigItem[];
|
|
132
|
+
|
|
133
|
+
declare const unicorn: FlatESLintConfigItem[];
|
|
134
|
+
|
|
135
|
+
declare function vue(options?: OptionsHasTypeScript): FlatESLintConfigItem[];
|
|
136
|
+
|
|
137
|
+
declare const yml: FlatESLintConfigItem[];
|
|
138
|
+
|
|
139
|
+
declare function test(options?: OptionsIsInEditor): FlatESLintConfigItem[];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Combine array and non-array configs into a single array.
|
|
143
|
+
*/
|
|
144
|
+
declare function combine(...configs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
|
|
145
|
+
declare function renameRules(rules: Record<string, any>, from: string, to: string): {
|
|
146
|
+
[k: string]: any;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export { OptionsComponentExts, OptionsConfig, OptionsHasTypeScript, OptionsIsInEditor, OptionsTypeScriptWithLanguageServer, antfu, combine, comments, antfu as default, ignores, imports, javascript, javascriptStylistic, jsdoc, jsonc, markdown, node, renameRules, sortPackageJson, sortTsconfig, test, typescript, typescriptStylistic, typescriptWithLanguageServer, unicorn, vue, yml };
|