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