@ntnyq/eslint-config 7.0.0-beta.3 → 7.0.0-beta.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ntnyq/eslint-config
2
2
 
3
- > 🎨 ESLint config for JavaScript, TypeScript, Vue, JSON, Markdown, YAML, TOML, SVG, and more.
3
+ > ESLint flat config preset for modern frontend projects (TypeScript, Vue, JSON, Markdown, YAML, TOML, and more).
4
4
 
5
5
  [![CI](https://github.com/ntnyq/eslint-config/workflows/CI/badge.svg)](https://github.com/ntnyq/eslint-config/actions)
6
6
  [![NPM VERSION](https://img.shields.io/npm/v/@ntnyq/eslint-config/latest.svg)](https://www.npmjs.com/package/@ntnyq/eslint-config/v/latest)
@@ -8,118 +8,188 @@
8
8
  [![NPM DOWNLOADS](https://img.shields.io/npm/dy/@ntnyq/eslint-config)](https://www.npmjs.com/package/@ntnyq/eslint-config)
9
9
  [![LICENSE](https://img.shields.io/github/license/ntnyq/eslint-config.svg)](https://github.com/ntnyq/eslint-config/blob/main/LICENSE)
10
10
 
11
- > [!IMPORTANT]
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 ^10.4.0
18
15
 
19
16
  > [!TIP]
20
- > For Node.js v18 support, please use [v4](https://github.com/ntnyq/eslint-config/tree/v4).
17
+ > Need legacy runtime support?
21
18
  >
22
- > For Node.js versions below 20.19.0, please use [v5](https://github.com/ntnyq/eslint-config/tree/v5).
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
- ## Features
23
+ ## Why Frontend Teams Use It
25
24
 
26
- - Designed to work alongside formatters, e.g. [Prettier](https://prettier.io) or [oxfmt](https://oxc.rs/docs/guide/usage/formatter)
27
- - 🎯 Opinionated: single quote, no semi, trailing comma, etc
28
- - 🪄 Respect `.gitignore` via [eslint-config-flat-gitignore](https://github.com/antfu/eslint-config-flat-gitignore)
29
- - 📦 Out-of-the-box support for TypeScript, Vue, JSON, Markdown, YAML, TOML, SVG, Astro, Svelte, etc
30
- - 🛡️ Strict but provides useful rules to guard your codebase
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
- ## 📦 Install
31
+ ## Install
35
32
 
36
33
  ```shell
37
- npm i eslint typescript @ntnyq/eslint-config -D
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
- ```shell
41
- yarn add eslint typescript @ntnyq/eslint-config -D
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
- ```shell
45
- pnpm add eslint typescript @ntnyq/eslint-config -D
62
+ ```json
63
+ {
64
+ "scripts": {
65
+ "lint": "eslint .",
66
+ "lint:fix": "eslint . --fix"
67
+ }
68
+ }
46
69
  ```
47
70
 
48
71
  ```shell
49
- bun add eslint typescript @ntnyq/eslint-config -D
72
+ pnpm lint
50
73
  ```
51
74
 
52
- ## 🚀 Usage
75
+ ## Common Frontend Setups
53
76
 
54
- Highly recommend using **`eslint.config.mjs`** as the config file:
77
+ ### Vite + Vue 3 + TypeScript
55
78
 
56
79
  ```js
57
- // @ts-check
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
- // Enable a config
65
- svgo: true,
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: ['**/utils/*.ts'],
118
+ files: ['apps/web/**'],
119
+ rules: {
120
+ 'no-console': 'warn',
121
+ },
122
+ },
123
+ {
124
+ files: ['packages/**'],
79
125
  rules: {
80
- 'antfu/top-level-function': 'error',
126
+ 'no-console': 'off',
81
127
  },
82
128
  },
83
129
  ],
84
130
  )
85
131
  ```
86
132
 
87
- Add a `lint` script to `package.json`:
133
+ ## Configuration Patterns
88
134
 
89
- ```json
90
- {
91
- "scripts": {
92
- "lint": "eslint",
93
- "lint:fix": "eslint --fix"
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
- <details>
99
- <summary>💼 Integration: Prettier, VS Code, husky and nano-staged</summary>
148
+ ### Override built-in rules
100
149
 
101
- <br>
150
+ ```js
151
+ import { defineESLintConfig } from '@ntnyq/eslint-config'
102
152
 
103
- ## 🎨 Prettier config
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
- > Feel free to use your own prettier config.
167
+ ### Add project-specific flat config blocks
106
168
 
107
- Install `prettier` and set up your Prettier config:
169
+ ```js
170
+ import { defineESLintConfig } from '@ntnyq/eslint-config'
108
171
 
109
- ```shell
110
- npm i prettier @ntnyq/prettier-config -D
172
+ export default defineESLintConfig({}, [
173
+ {
174
+ files: ['**/scripts/**'],
175
+ rules: {
176
+ 'no-console': 'off',
177
+ },
178
+ },
179
+ ])
111
180
  ```
112
181
 
113
- ```shell
114
- yarn add prettier @ntnyq/prettier-config -D
115
- ```
182
+ ## Formatter Integration
116
183
 
117
- ```shell
118
- pnpm add prettier @ntnyq/prettier-config -D
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
- bun add prettier @ntnyq/prettier-config -D
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
- ## 💻 VS Code config
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
- ### 3. Add a Git hook
217
+ ## Optional Configs (Disabled by Default)
205
218
 
206
- ```shell
207
- echo "nano-staged" > .husky/pre-commit
208
- ```
219
+ - `astro`
220
+ - `eslintPlugin`
221
+ - `html`
222
+ - `pnpm`
223
+ - `svelte`
224
+ - `svgo`
225
+ - `unusedImports`
209
226
 
210
- </details>
211
-
212
- ## 🔍 View what rules are enabled
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
- ## 📌 Versioning policy
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
- This project aims to follow [Semantic Versioning](https://semver.org/) for releases.
234
+ ## Advanced API
285
235
 
286
- ### 🔴 Changes treated as Breaking Changes
236
+ - [Config options type](./src/types/config.ts)
237
+ - [Factory implementation](./src/core.ts)
287
238
 
288
- - Node.js version requirement changes
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
- ### 🟢 Changes treated as Non-Breaking Changes
241
+ This project follows Semantic Versioning with opinionated lint rules:
294
242
 
295
- - Enable/disable rules and plugins (that might become stricter)
296
- - Rule option changes
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
- ## 🙏 Credits
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
- ## 📄 License
251
+ ## License
305
252
 
306
253
  [MIT](./LICENSE) License © 2023-PRESENT [ntnyq](https://github.com/ntnyq)