@ntnyq/eslint-config 6.1.5 → 7.0.0-beta.10
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 +159 -213
- package/dist/index.d.mts +1385 -276
- package/dist/index.mjs +145 -58
- package/package.json +52 -49
package/README.md
CHANGED
|
@@ -1,126 +1,195 @@
|
|
|
1
1
|
# @ntnyq/eslint-config
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> ESLint flat config preset for modern frontend projects (TypeScript, Vue, JSON, Markdown, YAML, TOML, and more).
|
|
4
4
|
|
|
5
5
|
[](https://github.com/ntnyq/eslint-config/actions)
|
|
6
6
|
[](https://www.npmjs.com/package/@ntnyq/eslint-config/v/latest)
|
|
7
|
+
[](https://www.npmjs.com/package/@ntnyq/eslint-config/v/next)
|
|
7
8
|
[](https://www.npmjs.com/package/@ntnyq/eslint-config)
|
|
8
9
|
[](https://github.com/ntnyq/eslint-config/blob/main/LICENSE)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
## Requirements
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## 📋 Requirements
|
|
16
|
-
|
|
17
|
-
- Node.js ^20.19.0 || ^22.13.0 || >=24
|
|
18
|
-
- ESLint ^9.38.0
|
|
13
|
+
- Node.js ^22.13.0 || >=24.11.0
|
|
14
|
+
- ESLint ^10.4.0
|
|
19
15
|
|
|
20
16
|
> [!TIP]
|
|
21
|
-
>
|
|
17
|
+
> Need legacy runtime support?
|
|
22
18
|
>
|
|
23
|
-
>
|
|
19
|
+
> - Node.js v18: use [v4](https://github.com/ntnyq/eslint-config/tree/v4)
|
|
20
|
+
> - Node.js < 20.19.0: use [v5](https://github.com/ntnyq/eslint-config/tree/v5)
|
|
21
|
+
> - Node.js < 22.13.0: use [v6](https://github.com/ntnyq/eslint-config/tree/v6)
|
|
24
22
|
|
|
25
|
-
##
|
|
23
|
+
## Why Frontend Teams Use It
|
|
26
24
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
- 🔧 Custom ESLint commands for [eslint-plugin-command](https://github.com/antfu/eslint-plugin-command)
|
|
33
|
-
- 🎪 [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files) for ESLint v9.38.0+
|
|
25
|
+
- Works out of the box with ESLint flat config.
|
|
26
|
+
- Auto-detects and enables configs by your dependencies and file types.
|
|
27
|
+
- Covers common frontend files: TS, Vue SFC, JSON, Markdown, YAML, TOML.
|
|
28
|
+
- Keeps formatting tool friendly (Prettier or oxfmt).
|
|
29
|
+
- Supports scaling from single apps to monorepos.
|
|
34
30
|
|
|
35
|
-
##
|
|
31
|
+
## Install
|
|
36
32
|
|
|
37
33
|
```shell
|
|
38
|
-
|
|
34
|
+
# pnpm
|
|
35
|
+
pnpm add -D eslint typescript @ntnyq/eslint-config
|
|
36
|
+
|
|
37
|
+
# npm
|
|
38
|
+
npm i -D eslint typescript @ntnyq/eslint-config
|
|
39
|
+
|
|
40
|
+
# yarn
|
|
41
|
+
yarn add -D eslint typescript @ntnyq/eslint-config
|
|
42
|
+
|
|
43
|
+
# bun
|
|
44
|
+
bun add -D eslint typescript @ntnyq/eslint-config
|
|
39
45
|
```
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
## 60-Second Quick Start
|
|
48
|
+
|
|
49
|
+
1. Create `eslint.config.mjs` in project root.
|
|
50
|
+
2. Add npm scripts.
|
|
51
|
+
3. Run lint.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
// eslint.config.mjs
|
|
55
|
+
// @ts-check
|
|
56
|
+
|
|
57
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
58
|
+
|
|
59
|
+
export default defineESLintConfig()
|
|
43
60
|
```
|
|
44
61
|
|
|
45
|
-
```
|
|
46
|
-
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"lint:fix": "eslint . --fix"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
```
|
|
48
70
|
|
|
49
71
|
```shell
|
|
50
|
-
|
|
72
|
+
pnpm lint
|
|
51
73
|
```
|
|
52
74
|
|
|
53
|
-
##
|
|
75
|
+
## Common Frontend Setups
|
|
54
76
|
|
|
55
|
-
|
|
77
|
+
### Vite + Vue 3 + TypeScript
|
|
56
78
|
|
|
57
79
|
```js
|
|
58
|
-
//
|
|
80
|
+
// eslint.config.mjs
|
|
81
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
82
|
+
|
|
83
|
+
export default defineESLintConfig({
|
|
84
|
+
vue: true,
|
|
85
|
+
typescript: {
|
|
86
|
+
tsconfigPath: './tsconfig.app.json',
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
```
|
|
59
90
|
|
|
91
|
+
### Vite + React + TypeScript
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
// eslint.config.mjs
|
|
95
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
96
|
+
|
|
97
|
+
export default defineESLintConfig({
|
|
98
|
+
vue: false,
|
|
99
|
+
typescript: {
|
|
100
|
+
tsconfigPath: './tsconfig.json',
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Monorepo (apps + packages)
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// eslint.config.mjs
|
|
60
109
|
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
61
110
|
|
|
62
111
|
export default defineESLintConfig(
|
|
63
|
-
// Options here
|
|
64
112
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Disable a config
|
|
68
|
-
jsdoc: false,
|
|
69
|
-
vue: {
|
|
70
|
-
// Overrides built-in rules
|
|
71
|
-
overrides: {
|
|
72
|
-
'vue/slot-name-casing': 'off',
|
|
73
|
-
},
|
|
74
|
-
},
|
|
113
|
+
typescript: true,
|
|
114
|
+
vue: true,
|
|
75
115
|
},
|
|
76
|
-
// Optional user configs here
|
|
77
116
|
[
|
|
78
117
|
{
|
|
79
|
-
files: ['
|
|
118
|
+
files: ['apps/web/**'],
|
|
80
119
|
rules: {
|
|
81
|
-
'
|
|
120
|
+
'no-console': 'warn',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
files: ['packages/**'],
|
|
125
|
+
rules: {
|
|
126
|
+
'no-console': 'off',
|
|
82
127
|
},
|
|
83
128
|
},
|
|
84
129
|
],
|
|
85
130
|
)
|
|
86
131
|
```
|
|
87
132
|
|
|
88
|
-
|
|
133
|
+
## Configuration Patterns
|
|
89
134
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
135
|
+
### Enable or disable modules
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
139
|
+
|
|
140
|
+
export default defineESLintConfig({
|
|
141
|
+
svgo: true,
|
|
142
|
+
astro: true,
|
|
143
|
+
jsdoc: false,
|
|
144
|
+
unicorn: false,
|
|
145
|
+
})
|
|
97
146
|
```
|
|
98
147
|
|
|
99
|
-
|
|
100
|
-
<summary>💼 Integration: Prettier, VS Code, husky and nano-staged</summary>
|
|
148
|
+
### Override built-in rules
|
|
101
149
|
|
|
102
|
-
|
|
150
|
+
```js
|
|
151
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
103
152
|
|
|
104
|
-
|
|
153
|
+
export default defineESLintConfig({
|
|
154
|
+
vue: {
|
|
155
|
+
overrides: {
|
|
156
|
+
'vue/slot-name-casing': 'off',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
typescript: {
|
|
160
|
+
overrides: {
|
|
161
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
```
|
|
105
166
|
|
|
106
|
-
|
|
167
|
+
### Add project-specific flat config blocks
|
|
107
168
|
|
|
108
|
-
|
|
169
|
+
```js
|
|
170
|
+
import { defineESLintConfig } from '@ntnyq/eslint-config'
|
|
109
171
|
|
|
110
|
-
|
|
111
|
-
|
|
172
|
+
export default defineESLintConfig({}, [
|
|
173
|
+
{
|
|
174
|
+
files: ['**/scripts/**'],
|
|
175
|
+
rules: {
|
|
176
|
+
'no-console': 'off',
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
])
|
|
112
180
|
```
|
|
113
181
|
|
|
114
|
-
|
|
115
|
-
yarn add prettier @ntnyq/prettier-config -D
|
|
116
|
-
```
|
|
182
|
+
## Formatter Integration
|
|
117
183
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
184
|
+
Use one formatter strategy in a project:
|
|
185
|
+
|
|
186
|
+
- Prettier path: install `prettier` and optional `@ntnyq/prettier-config`
|
|
187
|
+
- Oxfmt path: install `oxfmt`
|
|
188
|
+
|
|
189
|
+
### Prettier example
|
|
121
190
|
|
|
122
191
|
```shell
|
|
123
|
-
|
|
192
|
+
pnpm add -D prettier @ntnyq/prettier-config
|
|
124
193
|
```
|
|
125
194
|
|
|
126
195
|
```js
|
|
@@ -129,179 +198,56 @@ bun add prettier @ntnyq/prettier-config -D
|
|
|
129
198
|
|
|
130
199
|
import { defineConfig } from '@ntnyq/prettier-config'
|
|
131
200
|
|
|
132
|
-
export default defineConfig(
|
|
133
|
-
// Custom options if needed
|
|
134
|
-
printWidth: 100,
|
|
135
|
-
trailingComma: 'none',
|
|
136
|
-
overrides: [
|
|
137
|
-
{
|
|
138
|
-
files: ['**/*.html'],
|
|
139
|
-
options: {
|
|
140
|
-
singleAttributePerLine: false,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
files: ['**/*.{css,scss,less}'],
|
|
145
|
-
options: {
|
|
146
|
-
singleQuote: false,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
})
|
|
201
|
+
export default defineConfig()
|
|
151
202
|
```
|
|
152
203
|
|
|
153
|
-
|
|
204
|
+
### VS Code example
|
|
154
205
|
|
|
155
206
|
```json
|
|
156
207
|
{
|
|
157
208
|
"eslint.enable": true,
|
|
158
|
-
"prettier.enable": true,
|
|
159
|
-
"editor.formatOnSave": true,
|
|
160
|
-
"prettier.configPath": "./prettier.config.mjs",
|
|
161
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
162
209
|
"editor.codeActionsOnSave": {
|
|
163
210
|
"source.fixAll.eslint": "explicit",
|
|
164
211
|
"source.organizeImports": "never",
|
|
165
212
|
"source.sortImports": "never"
|
|
166
|
-
},
|
|
167
|
-
"eslint.validate": [
|
|
168
|
-
"vue",
|
|
169
|
-
"yaml",
|
|
170
|
-
"toml",
|
|
171
|
-
"json",
|
|
172
|
-
"jsonc",
|
|
173
|
-
"json5",
|
|
174
|
-
"markdown",
|
|
175
|
-
"javascript",
|
|
176
|
-
"typescript",
|
|
177
|
-
"javascriptreact",
|
|
178
|
-
"typescriptreact"
|
|
179
|
-
]
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## 🎯 Lint changed files only
|
|
184
|
-
|
|
185
|
-
### 1. Add dependencies
|
|
186
|
-
|
|
187
|
-
```shell
|
|
188
|
-
pnpm add husky nano-staged -D
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### 2. Config in `package.json`
|
|
192
|
-
|
|
193
|
-
```json
|
|
194
|
-
{
|
|
195
|
-
"scripts": {
|
|
196
|
-
"prepare": "husky"
|
|
197
|
-
},
|
|
198
|
-
"nano-staged": {
|
|
199
|
-
"*.{js,ts,cjs,mjs,jsx,tsx,vue,md,svg,yml,yaml,toml,json}": "eslint --fix",
|
|
200
|
-
"*.{css,scss,html}": "prettier -uw"
|
|
201
213
|
}
|
|
202
214
|
}
|
|
203
215
|
```
|
|
204
216
|
|
|
205
|
-
|
|
217
|
+
## Optional Configs (Disabled by Default)
|
|
206
218
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
219
|
+
- `astro`
|
|
220
|
+
- `eslintPlugin`
|
|
221
|
+
- `html`
|
|
222
|
+
- `pnpm`
|
|
223
|
+
- `svelte`
|
|
224
|
+
- `svgo`
|
|
225
|
+
- `unusedImports`
|
|
210
226
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
##
|
|
214
|
-
|
|
215
|
-
Please check [eslint-config-inspector](https://eslint-config-inspector.ntnyq.com/) powered by [@eslint/config-inspector](https://github.com/eslint/config-inspector).
|
|
216
|
-
|
|
217
|
-
## ⚙️ Advanced config
|
|
218
|
-
|
|
219
|
-
For details, see:
|
|
220
|
-
|
|
221
|
-
- [./src/types/config.ts](https://github.com/ntnyq/eslint-config/blob/main/src/types/config.ts)
|
|
222
|
-
- [./src/core.ts](https://github.com/ntnyq/eslint-config/blob/main/src/core.ts)
|
|
223
|
-
|
|
224
|
-
### 📝 Config interface
|
|
225
|
-
|
|
226
|
-
```ts
|
|
227
|
-
export interface ConfigOptions {
|
|
228
|
-
/**
|
|
229
|
-
* Shareable options
|
|
230
|
-
*/
|
|
231
|
-
shareable?: OptionsShareable
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Configs enabled by default
|
|
235
|
-
*/
|
|
236
|
-
command?: ConfigCommandOptions
|
|
237
|
-
eslintComments?: ConfigESLintCommentsOptions
|
|
238
|
-
ignores?: ConfigIgnoresOptions
|
|
239
|
-
javascript?: ConfigJavaScriptOptions
|
|
240
|
-
node?: ConfigNodeOptions
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Configs below can be disabled
|
|
244
|
-
*/
|
|
245
|
-
antfu?: boolean | ConfigAntfuOptions
|
|
246
|
-
deMorgan?: boolean | ConfigDeMorganOptions
|
|
247
|
-
depend?: boolean | ConfigDependOptions
|
|
248
|
-
githubAction?: boolean | ConfigGitHubActionOptions
|
|
249
|
-
gitignore?: boolean | ConfigGitIgnoreOptions
|
|
250
|
-
importX?: boolean | ConfigImportXOptions
|
|
251
|
-
jsdoc?: boolean | ConfigJsdocOptions
|
|
252
|
-
jsonc?: boolean | ConfigJsoncOptions
|
|
253
|
-
markdown?: boolean | ConfigMarkdownOptions
|
|
254
|
-
ntnyq?: boolean | ConfigNtnyqOptions
|
|
255
|
-
perfectionist?: boolean | ConfigPerfectionistOptions
|
|
256
|
-
pinia?: boolean | ConfigPiniaOptions
|
|
257
|
-
prettier?: boolean | ConfigPrettierOptions
|
|
258
|
-
regexp?: boolean | ConfigRegexpOptions
|
|
259
|
-
sort?: boolean | ConfigSortOptions
|
|
260
|
-
specials?: boolean | ConfigSpecialsOptions
|
|
261
|
-
test?: boolean | ConfigTestOptions
|
|
262
|
-
toml?: boolean | ConfigTomlOptions
|
|
263
|
-
typescript?: boolean | ConfigTypeScriptOptions
|
|
264
|
-
unicorn?: boolean | ConfigUnicornOptions
|
|
265
|
-
unocss?: boolean | ConfigUnoCSSOptions
|
|
266
|
-
vue?: boolean | ConfigVueOptions
|
|
267
|
-
yml?: boolean | ConfigYmlOptions
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Configs below are disabled by default
|
|
271
|
-
*/
|
|
272
|
-
astro?: boolean | ConfigAstroOptions
|
|
273
|
-
html?: boolean | ConfigHtmlOptions
|
|
274
|
-
pnpm?: boolean | ConfigPnpmOptions
|
|
275
|
-
oxfmt?: boolean | ConfigOxfmtOptions
|
|
276
|
-
svelte?: boolean | ConfigSvelteOptions
|
|
277
|
-
svgo?: boolean | ConfigSVGOOptions
|
|
278
|
-
eslintPlugin?: boolean | ConfigESLintPluginOptions
|
|
279
|
-
unusedImports?: boolean | ConfigUnusedImportsOptions
|
|
280
|
-
}
|
|
281
|
-
```
|
|
227
|
+
Enable them explicitly in `defineESLintConfig({ ... })` when needed.
|
|
228
|
+
|
|
229
|
+
## Inspect Final Rules
|
|
282
230
|
|
|
283
|
-
|
|
231
|
+
- Online inspector: [eslint-config-inspector.ntnyq.com](https://eslint-config-inspector.ntnyq.com/)
|
|
232
|
+
- Local inspect: `npx eslint --inspect-config path/to/file.ts`
|
|
284
233
|
|
|
285
|
-
|
|
234
|
+
## Advanced API
|
|
286
235
|
|
|
287
|
-
|
|
236
|
+
- [Config options type](./src/types/config.ts)
|
|
237
|
+
- [Factory implementation](./src/core.ts)
|
|
288
238
|
|
|
289
|
-
|
|
290
|
-
- Huge refactors that might break the config
|
|
291
|
-
- Plugins made major changes that might break the config
|
|
292
|
-
- Changes that might affect most of the codebases
|
|
239
|
+
## Versioning Policy
|
|
293
240
|
|
|
294
|
-
|
|
241
|
+
This project follows Semantic Versioning with opinionated lint rules:
|
|
295
242
|
|
|
296
|
-
-
|
|
297
|
-
-
|
|
298
|
-
- Version bumps of dependencies
|
|
243
|
+
- Treated as breaking: Node.js engine changes, major plugin incompatibility, broad refactors.
|
|
244
|
+
- Treated as non-breaking: enabling/disabling rules, rule option tuning, dependency bumps.
|
|
299
245
|
|
|
300
|
-
##
|
|
246
|
+
## Credits
|
|
301
247
|
|
|
302
248
|
- [@sxzz/eslint-config](https://github.com/sxzz/eslint-config)
|
|
303
249
|
- [@antfu/eslint-config](https://github.com/antfu/eslint-config)
|
|
304
250
|
|
|
305
|
-
##
|
|
251
|
+
## License
|
|
306
252
|
|
|
307
253
|
[MIT](./LICENSE) License © 2023-PRESENT [ntnyq](https://github.com/ntnyq)
|