@fabdeh/eslint-config 0.9.1 → 0.11.0
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 +310 -69
- package/dist/index.d.mts +15161 -13266
- package/dist/index.mjs +611 -408
- package/package.json +26 -37
package/README.md
CHANGED
|
@@ -4,24 +4,22 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@fabdeh/eslint-config)
|
|
5
5
|
[](https://app.netlify.com/sites/fabdeh-eslint-config/deploys)
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- Designed to work with TypeScript, JSX, etc. Out-of-box.
|
|
7
|
+
- Reasonable defaults and best practices with only one line of config
|
|
8
|
+
- Designed to work with TypeScript, JSX, etc., out of the box.
|
|
10
9
|
- Opinionated, but [very customizable](#customization)
|
|
11
|
-
- [ESLint
|
|
12
|
-
- Automatic [Angular](#angular), [
|
|
13
|
-
-
|
|
14
|
-
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
10
|
+
- [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), composed easily.
|
|
11
|
+
- Automatic [Angular](#angular), [NgRx](#ngrx), [TypeScript](#typescript), and [Vitest](#vitest) support when the corresponding dependency is detected.
|
|
12
|
+
- **Style principle**: minimal for reading, stable for diffs, consistent
|
|
15
13
|
- Sorted imports, dangling commas
|
|
16
14
|
- Single quotes, no semi
|
|
17
15
|
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
18
16
|
- Respects `.gitignore` by default
|
|
19
|
-
- Requires ESLint v9.
|
|
17
|
+
- Requires ESLint v9.38.0+ (or v10+)
|
|
20
18
|
|
|
21
19
|
> [!WARNING]
|
|
22
|
-
> Please keep in mind that this is **_a personal config_** with
|
|
20
|
+
> Please keep in mind that this is **_a personal config_** with many opinions. Changes may not suit everyone or every use case.
|
|
23
21
|
>
|
|
24
|
-
> If you are using this config directly, I
|
|
22
|
+
> If you are using this config directly, I suggest you **review changes every time you update**. If you want more control over the rules, feel free to fork it. Thanks!
|
|
25
23
|
|
|
26
24
|
## Usage
|
|
27
25
|
|
|
@@ -33,7 +31,7 @@ Run the command in your terminal:
|
|
|
33
31
|
pnpm add -D eslint @fabdeh/eslint-config
|
|
34
32
|
```
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
Then create an `eslint.config.mjs` in your project root:
|
|
37
35
|
|
|
38
36
|
```js
|
|
39
37
|
// eslint.config.mjs
|
|
@@ -42,6 +40,57 @@ import { defineConfig } from '@fabdeh/eslint-config';
|
|
|
42
40
|
export default defineConfig();
|
|
43
41
|
```
|
|
44
42
|
|
|
43
|
+
### Monorepo / Workspace
|
|
44
|
+
|
|
45
|
+
For monorepos, split your setup in two layers:
|
|
46
|
+
|
|
47
|
+
- `defineWorkspaceConfig()` for the workspace root.
|
|
48
|
+
- `defineProjectConfig()` for each app/lib to extend the root config.
|
|
49
|
+
|
|
50
|
+
Root config example:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
// eslint.config.ts (workspace root)
|
|
54
|
+
import { defineWorkspaceConfig } from '@fabdeh/eslint-config';
|
|
55
|
+
|
|
56
|
+
export default defineWorkspaceConfig({
|
|
57
|
+
typescript: true,
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Project config example:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { defineProjectConfig } from '@fabdeh/eslint-config';
|
|
65
|
+
|
|
66
|
+
// apps/my-app/eslint.config.ts
|
|
67
|
+
import baseConfig from '../../eslint.config.ts';
|
|
68
|
+
|
|
69
|
+
export default defineProjectConfig(baseConfig, {
|
|
70
|
+
type: 'app',
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Behavior matrix:
|
|
75
|
+
|
|
76
|
+
| Feature | `defineConfig` | `defineWorkspaceConfig` | `defineProjectConfig` |
|
|
77
|
+
| --- | --- | --- | --- |
|
|
78
|
+
| `typescript` | Auto-detected (`typescript`) | Auto-detected (`typescript`) | Inherited from workspace, optional project-specific parser options |
|
|
79
|
+
| `angular` | Auto-detected (`@angular/core`) | Not auto-detected | Auto-detected (`@angular/core`) |
|
|
80
|
+
| `ngrx` | Auto-detected (`@ngrx/*`) | Not auto-detected | Auto-detected (`@ngrx/*`) |
|
|
81
|
+
| `vitest` | Auto-detected (`vitest`) | Not auto-detected | Auto-detected (`vitest`) |
|
|
82
|
+
| `jsdoc` | Default `true` only when `type: 'lib'` | Not included | Default `true` only when `type: 'lib'` |
|
|
83
|
+
| `tailwindcss` | Available, disabled by default | Not included | Available, disabled by default |
|
|
84
|
+
|
|
85
|
+
Monorepo notes:
|
|
86
|
+
|
|
87
|
+
- `defineWorkspaceConfig()` is for foundation-level rules and defaults (imports, unicorn, regexp, jsonc/yaml/toml/markdown, stylistic, ignores).
|
|
88
|
+
- `defineProjectConfig()` appends project-specific integrations on top of your workspace base config.
|
|
89
|
+
- `ngrx` requires `angular`; enabling NgRx without Angular throws.
|
|
90
|
+
- Project-specific `typescript` options require TypeScript support in workspace base config.
|
|
91
|
+
- Project-level `ignores` are additive for the project config only and do not re-apply workspace global ignore patterns.
|
|
92
|
+
- Final order in project configs is: workspace base configs -> project configs -> user-provided extra configs.
|
|
93
|
+
|
|
45
94
|
### Add the scripts for package.json
|
|
46
95
|
|
|
47
96
|
For example:
|
|
@@ -68,9 +117,9 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
68
117
|
|
|
69
118
|
```jsonc
|
|
70
119
|
{
|
|
71
|
-
//
|
|
72
|
-
"prettier.enable":
|
|
73
|
-
"editor.formatOnSave":
|
|
120
|
+
// Enable the default formatter, use eslint instead
|
|
121
|
+
"prettier.enable": true,
|
|
122
|
+
"editor.formatOnSave": true,
|
|
74
123
|
|
|
75
124
|
// Auto fix
|
|
76
125
|
"editor.codeActionsOnSave": {
|
|
@@ -78,8 +127,18 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
78
127
|
"source.organizeImports": "never"
|
|
79
128
|
},
|
|
80
129
|
|
|
81
|
-
// Silence
|
|
82
|
-
"eslint.rules.customizations": [
|
|
130
|
+
// Silence style rules in your IDE, while still fixing them automatically
|
|
131
|
+
"eslint.rules.customizations": [
|
|
132
|
+
{ "rule": "@stylistic/*", "severity": "off", "fixable": true },
|
|
133
|
+
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
134
|
+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
135
|
+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
136
|
+
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
137
|
+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
138
|
+
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
139
|
+
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
140
|
+
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
141
|
+
],
|
|
83
142
|
|
|
84
143
|
// Enable eslint for all supported languages
|
|
85
144
|
"eslint.validate": [
|
|
@@ -104,14 +163,160 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
104
163
|
|
|
105
164
|
</details>
|
|
106
165
|
|
|
166
|
+
<details>
|
|
167
|
+
<summary>🔲 Zed support</summary>
|
|
168
|
+
|
|
169
|
+
<br>
|
|
170
|
+
|
|
171
|
+
Add the following settings to your `.zed/settings.json`:
|
|
172
|
+
|
|
173
|
+
```jsonc
|
|
174
|
+
{
|
|
175
|
+
"format_on_save": "on",
|
|
176
|
+
"formatter": [
|
|
177
|
+
// Use ESLint's --fix:
|
|
178
|
+
{ "code_action": "source.fixAll.eslint" }
|
|
179
|
+
],
|
|
180
|
+
// Enable eslint for all supported languages
|
|
181
|
+
// Defaults only include https://github.com/search?q=repo%3Azed-industries%2Fzed%20eslint_languages&type=code
|
|
182
|
+
"languages": {
|
|
183
|
+
"HTML": {
|
|
184
|
+
"language_servers": ["...", "eslint"]
|
|
185
|
+
},
|
|
186
|
+
"Markdown": {
|
|
187
|
+
"language_servers": ["...", "eslint"]
|
|
188
|
+
},
|
|
189
|
+
"JSON": {
|
|
190
|
+
"language_servers": ["...", "eslint"]
|
|
191
|
+
},
|
|
192
|
+
"JSONC": {
|
|
193
|
+
"language_servers": ["...", "eslint"]
|
|
194
|
+
},
|
|
195
|
+
"YAML": {
|
|
196
|
+
"language_servers": ["...", "eslint"]
|
|
197
|
+
},
|
|
198
|
+
"CSS": {
|
|
199
|
+
"language_servers": ["...", "eslint"]
|
|
200
|
+
}
|
|
201
|
+
// Add other languages as needed
|
|
202
|
+
},
|
|
203
|
+
"lsp": {
|
|
204
|
+
"eslint": {
|
|
205
|
+
"settings": {
|
|
206
|
+
// Remove after https://github.com/zed-industries/zed/issues/49387
|
|
207
|
+
"experimental": {
|
|
208
|
+
"useFlatConfig": false
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
// Silent the stylistic rules in your IDE, but still auto fix them
|
|
212
|
+
"rulesCustomizations": [
|
|
213
|
+
{ "rule": "@stylistic/*", "severity": "off", "fixable": true },
|
|
214
|
+
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
215
|
+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
216
|
+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
217
|
+
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
218
|
+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
219
|
+
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
220
|
+
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
221
|
+
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
</details>
|
|
230
|
+
|
|
231
|
+
<details>
|
|
232
|
+
<summary>🟩 Neovim Support</summary>
|
|
233
|
+
|
|
234
|
+
<br>
|
|
235
|
+
|
|
236
|
+
Update your configuration to use the following:
|
|
237
|
+
|
|
238
|
+
```lua
|
|
239
|
+
local customizations = {
|
|
240
|
+
{ rule = '@stylistic/*', severity = 'off', fixable = true },
|
|
241
|
+
{ rule = '*-indent', severity = 'off', fixable = true },
|
|
242
|
+
{ rule = '*-spacing', severity = 'off', fixable = true },
|
|
243
|
+
{ rule = '*-spaces', severity = 'off', fixable = true },
|
|
244
|
+
{ rule = '*-order', severity = 'off', fixable = true },
|
|
245
|
+
{ rule = '*-dangle', severity = 'off', fixable = true },
|
|
246
|
+
{ rule = '*-newline', severity = 'off', fixable = true },
|
|
247
|
+
{ rule = '*quotes', severity = 'off', fixable = true },
|
|
248
|
+
{ rule = '*semi', severity = 'off', fixable = true },
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
local lspconfig = require('lspconfig')
|
|
252
|
+
-- Enable eslint for all supported languages
|
|
253
|
+
lspconfig.eslint.setup(
|
|
254
|
+
{
|
|
255
|
+
filetypes = {
|
|
256
|
+
"javascript",
|
|
257
|
+
"javascriptreact",
|
|
258
|
+
"javascript.jsx",
|
|
259
|
+
"typescript",
|
|
260
|
+
"typescriptreact",
|
|
261
|
+
"typescript.tsx",
|
|
262
|
+
"vue",
|
|
263
|
+
"html",
|
|
264
|
+
"markdown",
|
|
265
|
+
"json",
|
|
266
|
+
"jsonc",
|
|
267
|
+
"yaml",
|
|
268
|
+
"toml",
|
|
269
|
+
"xml",
|
|
270
|
+
"gql",
|
|
271
|
+
"graphql",
|
|
272
|
+
"astro",
|
|
273
|
+
"svelte",
|
|
274
|
+
"css",
|
|
275
|
+
"less",
|
|
276
|
+
"scss",
|
|
277
|
+
"pcss",
|
|
278
|
+
"postcss"
|
|
279
|
+
},
|
|
280
|
+
settings = {
|
|
281
|
+
-- Silent the stylistic rules in your IDE, but still auto fix them
|
|
282
|
+
rulesCustomizations = customizations,
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Neovim format on save
|
|
289
|
+
|
|
290
|
+
There's few ways you can achieve format on save in neovim:
|
|
291
|
+
|
|
292
|
+
- `nvim-lspconfig` has a `EslintFixAll` command predefined, you can create a autocmd to call this command after saving file.
|
|
293
|
+
|
|
294
|
+
```lua
|
|
295
|
+
lspconfig.eslint.setup({
|
|
296
|
+
--- ...
|
|
297
|
+
on_attach = function(client, bufnr)
|
|
298
|
+
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
299
|
+
buffer = bufnr,
|
|
300
|
+
command = "EslintFixAll",
|
|
301
|
+
})
|
|
302
|
+
end,
|
|
303
|
+
})
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
- Use [conform.nvim](https://github.com/stevearc/conform.nvim).
|
|
307
|
+
- Use [none-ls](https://github.com/nvimtools/none-ls.nvim)
|
|
308
|
+
- Use [nvim-lint](https://github.com/mfussenegger/nvim-lint)
|
|
309
|
+
|
|
310
|
+
</details>
|
|
311
|
+
|
|
107
312
|
## Customization
|
|
108
313
|
|
|
109
|
-
|
|
314
|
+
This project uses [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides better organization and composition.
|
|
110
315
|
|
|
111
316
|
Normally you only need to import the `defineConfig` function:
|
|
112
317
|
|
|
113
318
|
```js
|
|
114
|
-
// eslint.config.
|
|
319
|
+
// eslint.config.ts
|
|
115
320
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
116
321
|
|
|
117
322
|
export default defineConfig();
|
|
@@ -120,7 +325,7 @@ export default defineConfig();
|
|
|
120
325
|
And that's it! Or you can configure each integration individually, for example:
|
|
121
326
|
|
|
122
327
|
```js
|
|
123
|
-
// eslint.config.
|
|
328
|
+
// eslint.config.ts
|
|
124
329
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
125
330
|
|
|
126
331
|
export default defineConfig({
|
|
@@ -148,19 +353,19 @@ export default defineConfig({
|
|
|
148
353
|
});
|
|
149
354
|
```
|
|
150
355
|
|
|
151
|
-
The `defineConfig` factory function also accepts any number of
|
|
356
|
+
The `defineConfig` factory function also accepts any number of custom config overrides:
|
|
152
357
|
|
|
153
358
|
```js
|
|
154
|
-
// eslint.config.
|
|
359
|
+
// eslint.config.ts
|
|
155
360
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
156
361
|
|
|
157
362
|
export default defineConfig(
|
|
158
363
|
{
|
|
159
|
-
// Configure
|
|
364
|
+
// Configure @fabdeh/eslint-config
|
|
160
365
|
},
|
|
161
366
|
|
|
162
|
-
// From the second
|
|
163
|
-
//
|
|
367
|
+
// From the second argument onward, these are ESLint flat configs
|
|
368
|
+
// You can provide multiple config objects
|
|
164
369
|
{
|
|
165
370
|
files: ['**/*.ts'],
|
|
166
371
|
rules: {},
|
|
@@ -171,17 +376,17 @@ export default defineConfig(
|
|
|
171
376
|
);
|
|
172
377
|
```
|
|
173
378
|
|
|
174
|
-
|
|
379
|
+
For advanced usage, you can import fine-grained configs and compose them as needed:
|
|
175
380
|
|
|
176
381
|
<details>
|
|
177
382
|
<summary>Advanced Example</summary>
|
|
178
383
|
|
|
179
|
-
We
|
|
384
|
+
We don't recommend this style unless you know exactly what you're doing, since there are shared options between configs that may require extra care to keep consistent.
|
|
180
385
|
|
|
181
386
|
```js
|
|
182
|
-
import
|
|
387
|
+
import { defineConfig } from 'eslint/config';
|
|
183
388
|
|
|
184
|
-
// eslint.config.
|
|
389
|
+
// eslint.config.ts
|
|
185
390
|
import {
|
|
186
391
|
angular,
|
|
187
392
|
comments,
|
|
@@ -197,7 +402,7 @@ import {
|
|
|
197
402
|
vitest,
|
|
198
403
|
} from '@fabdeh/eslint-config';
|
|
199
404
|
|
|
200
|
-
export default
|
|
405
|
+
export default defineConfig(
|
|
201
406
|
ignores(),
|
|
202
407
|
javascript(/* Options */),
|
|
203
408
|
comments(),
|
|
@@ -215,17 +420,17 @@ export default tseslint.config(
|
|
|
215
420
|
|
|
216
421
|
</details>
|
|
217
422
|
|
|
218
|
-
Check out the [configs](https://github.com/FabienDehopre/eslint-config/blob/main/src/configs) and [factory](https://github.com/FabienDehopre/eslint-config/blob/main/src/
|
|
423
|
+
Check out the [configs](https://github.com/FabienDehopre/eslint-config/blob/main/src/configs) and [factory functions](https://github.com/FabienDehopre/eslint-config/blob/main/src/factories) for more details.
|
|
219
424
|
|
|
220
425
|
> Thanks to [antfu/eslint-config](https://github.com/antfu/eslint-config) for the inspiration and reference.
|
|
221
426
|
|
|
222
427
|
### Rules Overrides
|
|
223
428
|
|
|
224
|
-
All
|
|
225
|
-
If you want to override
|
|
429
|
+
All rules are bound to one or more file extensions (via minimatch patterns, e.g. `**/*.?([cm])[jt]s?(x)` for JS and TS file types, including JSX syntax).
|
|
430
|
+
If you want to override rules, you need to specify the file extension:
|
|
226
431
|
|
|
227
432
|
```js
|
|
228
|
-
// eslint.config.
|
|
433
|
+
// eslint.config.ts
|
|
229
434
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
230
435
|
|
|
231
436
|
export default defineConfig(
|
|
@@ -252,13 +457,13 @@ export default defineConfig(
|
|
|
252
457
|
We also provide the `overrides` option in each integration to make it easier:
|
|
253
458
|
|
|
254
459
|
```js
|
|
255
|
-
// eslint.config.
|
|
460
|
+
// eslint.config.ts
|
|
256
461
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
257
462
|
|
|
258
463
|
export default defineConfig({
|
|
259
464
|
typescript: {
|
|
260
465
|
overrides: {
|
|
261
|
-
'@typescript-eslint/
|
|
466
|
+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
|
262
467
|
},
|
|
263
468
|
},
|
|
264
469
|
angular: {
|
|
@@ -277,6 +482,34 @@ export default defineConfig({
|
|
|
277
482
|
});
|
|
278
483
|
```
|
|
279
484
|
|
|
485
|
+
### Other integrations and defaults
|
|
486
|
+
|
|
487
|
+
In addition to Angular/NgRx/TypeScript/Vitest, `defineConfig()` and `defineWorkspaceConfig()` support:
|
|
488
|
+
|
|
489
|
+
- `gitignore` (default: `true`)
|
|
490
|
+
- `stylistic` (default: `true`)
|
|
491
|
+
- `unicorn` (default: `true`)
|
|
492
|
+
- `regexp` (default: `true`)
|
|
493
|
+
- `jsonc`, `yaml`, `toml`, `markdown` (default: `true`)
|
|
494
|
+
- `pnpm` workspace/catalog rules (default: `false`, currently experimental)
|
|
495
|
+
|
|
496
|
+
Quick example:
|
|
497
|
+
|
|
498
|
+
```js
|
|
499
|
+
import { defineConfig } from '@fabdeh/eslint-config';
|
|
500
|
+
|
|
501
|
+
export default defineConfig({
|
|
502
|
+
gitignore: true,
|
|
503
|
+
unicorn: true,
|
|
504
|
+
regexp: true,
|
|
505
|
+
jsonc: true,
|
|
506
|
+
yaml: true,
|
|
507
|
+
toml: true,
|
|
508
|
+
markdown: true,
|
|
509
|
+
pnpm: false,
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
280
513
|
### Auto-detected integrations
|
|
281
514
|
|
|
282
515
|
The following integrations are automatically enabled if the corresponding package is installed in your project:
|
|
@@ -288,11 +521,11 @@ The following integrations are automatically enabled if the corresponding packag
|
|
|
288
521
|
|
|
289
522
|
#### TypeScript
|
|
290
523
|
|
|
291
|
-
Most
|
|
524
|
+
Most TypeScript rules are enabled automatically if the `typescript` package is installed in your project. Some `@typescript-eslint` rules are also enabled by default for JavaScript files.
|
|
292
525
|
You can explicitly enable/disable TypeScript integration manually:
|
|
293
526
|
|
|
294
527
|
```js
|
|
295
|
-
// eslint.config.
|
|
528
|
+
// eslint.config.ts
|
|
296
529
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
297
530
|
|
|
298
531
|
export default defineConfig({
|
|
@@ -302,7 +535,7 @@ export default defineConfig({
|
|
|
302
535
|
|
|
303
536
|
##### Erasable Syntax Only
|
|
304
537
|
|
|
305
|
-
The TypeScript integration also
|
|
538
|
+
The TypeScript integration also lets you enable/disable rules that report syntax not allowed by TypeScript's [--erasableSyntaxOnly option](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8-beta/#the---erasablesyntaxonly-option):
|
|
306
539
|
|
|
307
540
|
> Recently, Node.js 23.6 unflagged [experimental support for running TypeScript files directly](https://nodejs.org/api/typescript.html#type-stripping); however, only certain constructs are supported under this mode.
|
|
308
541
|
>
|
|
@@ -313,7 +546,7 @@ The TypeScript integration also allows you to turn on/off rules that will report
|
|
|
313
546
|
You can enable these rules as follows:
|
|
314
547
|
|
|
315
548
|
```js
|
|
316
|
-
// eslint.config.
|
|
549
|
+
// eslint.config.ts
|
|
317
550
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
318
551
|
|
|
319
552
|
export default defineConfig({
|
|
@@ -335,7 +568,7 @@ pnpm add -D eslint-plugin-erasable-syntax-only
|
|
|
335
568
|
Angular support is detected automatically by checking if `@angular/core` is installed in your project. You can also explicitly enable/disable it:
|
|
336
569
|
|
|
337
570
|
```js
|
|
338
|
-
// eslint.config.
|
|
571
|
+
// eslint.config.ts
|
|
339
572
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
340
573
|
|
|
341
574
|
export default defineConfig({
|
|
@@ -352,10 +585,10 @@ NgRx support is also detected automatically if any of the following packages is
|
|
|
352
585
|
- `@ngrx/signals`
|
|
353
586
|
- `@ngrx/operators`
|
|
354
587
|
|
|
355
|
-
As the Angular integration
|
|
588
|
+
As with the Angular integration, it can be explicitly enabled/disabled:
|
|
356
589
|
|
|
357
590
|
```js
|
|
358
|
-
// eslint.config.
|
|
591
|
+
// eslint.config.ts
|
|
359
592
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
360
593
|
|
|
361
594
|
export default defineConfig({
|
|
@@ -367,10 +600,10 @@ export default defineConfig({
|
|
|
367
600
|
|
|
368
601
|
#### Vitest
|
|
369
602
|
|
|
370
|
-
The
|
|
603
|
+
The Vitest integration is detected automatically by checking whether `vitest` is installed in your project. It can be enabled/disabled manually in the configuration:
|
|
371
604
|
|
|
372
605
|
```js
|
|
373
|
-
// eslint.config.
|
|
606
|
+
// eslint.config.ts
|
|
374
607
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
375
608
|
|
|
376
609
|
export default defineConfig({
|
|
@@ -378,42 +611,40 @@ export default defineConfig({
|
|
|
378
611
|
});
|
|
379
612
|
```
|
|
380
613
|
|
|
381
|
-
|
|
614
|
+
You can also configure Vitest helpers explicitly:
|
|
382
615
|
|
|
383
|
-
|
|
616
|
+
```js
|
|
617
|
+
import { defineConfig } from '@fabdeh/eslint-config';
|
|
618
|
+
|
|
619
|
+
export default defineConfig({
|
|
620
|
+
vitest: {
|
|
621
|
+
useJestDom: true,
|
|
622
|
+
useTestingLibrary: true,
|
|
623
|
+
},
|
|
624
|
+
});
|
|
625
|
+
```
|
|
384
626
|
|
|
385
|
-
|
|
627
|
+
### Editor Specific Disables
|
|
386
628
|
|
|
387
|
-
|
|
629
|
+
Auto-fixing for the following rules are disabled when ESLint is running in a code editor:
|
|
630
|
+
|
|
631
|
+
- [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
|
|
632
|
+
- [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports)
|
|
633
|
+
- [`pnpm/json-enforce-catalog`](https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm#rules)
|
|
634
|
+
- [`pnpm/json-prefer-workspace-settings`](https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm#rules)
|
|
635
|
+
- [`pnpm/json-valid-catalog`](https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm#rules)
|
|
636
|
+
|
|
637
|
+
This is to prevent unused imports from getting removed by the editor during refactoring to get a better developer experience. Those rules will be applied when you run ESLint in the terminal or [Lint Staged](#lint-staged). If you don't want this behavior, you can disable them:
|
|
388
638
|
|
|
389
639
|
```js
|
|
390
640
|
// eslint.config.js
|
|
391
641
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
392
642
|
|
|
393
643
|
export default defineConfig({
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Format CSS, LESS, SCSS files
|
|
397
|
-
*/
|
|
398
|
-
css: true,
|
|
399
|
-
/**
|
|
400
|
-
* Format HTML files
|
|
401
|
-
*/
|
|
402
|
-
html: true,
|
|
403
|
-
/**
|
|
404
|
-
* Format Markdown files
|
|
405
|
-
*/
|
|
406
|
-
markdown: true,
|
|
407
|
-
}
|
|
644
|
+
isInEditor: false
|
|
408
645
|
});
|
|
409
646
|
```
|
|
410
647
|
|
|
411
|
-
Running `npx eslint` should prompt you to install the required dependencies; otherwise, you can install them manually:
|
|
412
|
-
|
|
413
|
-
```bash
|
|
414
|
-
pnpm add -D eslint-plugin-format
|
|
415
|
-
```
|
|
416
|
-
|
|
417
648
|
### Lint Staged
|
|
418
649
|
|
|
419
650
|
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
@@ -429,7 +660,7 @@ If you want to apply lint and auto-fix before every commit, you can add the foll
|
|
|
429
660
|
}
|
|
430
661
|
```
|
|
431
662
|
|
|
432
|
-
|
|
663
|
+
Then run:
|
|
433
664
|
|
|
434
665
|
```bash
|
|
435
666
|
pnpm add -D nano-staged simple-git-hooks
|
|
@@ -438,6 +669,16 @@ pnpm add -D nano-staged simple-git-hooks
|
|
|
438
669
|
pnpm simple-git-hooks
|
|
439
670
|
```
|
|
440
671
|
|
|
672
|
+
## View what rules are enabled
|
|
673
|
+
|
|
674
|
+
Use [@eslint/config-inspector](https://github.com/eslint/config-inspector) to help you view what rules are enabled in your project and apply them to what files.
|
|
675
|
+
|
|
676
|
+
Go to your project root that contains `eslint.config.js` and run:
|
|
677
|
+
|
|
678
|
+
```bash
|
|
679
|
+
npx @eslint/config-inspector
|
|
680
|
+
```
|
|
681
|
+
|
|
441
682
|
## Versioning Policy
|
|
442
683
|
|
|
443
684
|
This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.
|