@fabdeh/eslint-config 0.10.0 → 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 +201 -15
- package/dist/index.d.mts +15442 -13862
- package/dist/index.mjs +413 -178
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ For monorepos, split your setup in two layers:
|
|
|
50
50
|
Root config example:
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
|
-
// eslint.config.
|
|
53
|
+
// eslint.config.ts (workspace root)
|
|
54
54
|
import { defineWorkspaceConfig } from '@fabdeh/eslint-config';
|
|
55
55
|
|
|
56
56
|
export default defineWorkspaceConfig({
|
|
@@ -63,8 +63,8 @@ Project config example:
|
|
|
63
63
|
```js
|
|
64
64
|
import { defineProjectConfig } from '@fabdeh/eslint-config';
|
|
65
65
|
|
|
66
|
-
// apps/my-app/eslint.config.
|
|
67
|
-
import baseConfig from '../../eslint.config.
|
|
66
|
+
// apps/my-app/eslint.config.ts
|
|
67
|
+
import baseConfig from '../../eslint.config.ts';
|
|
68
68
|
|
|
69
69
|
export default defineProjectConfig(baseConfig, {
|
|
70
70
|
type: 'app',
|
|
@@ -128,7 +128,17 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
128
128
|
},
|
|
129
129
|
|
|
130
130
|
// Silence style rules in your IDE, while still fixing them automatically
|
|
131
|
-
"eslint.rules.customizations": [
|
|
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
|
+
],
|
|
132
142
|
|
|
133
143
|
// Enable eslint for all supported languages
|
|
134
144
|
"eslint.validate": [
|
|
@@ -153,6 +163,152 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
153
163
|
|
|
154
164
|
</details>
|
|
155
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
|
+
|
|
156
312
|
## Customization
|
|
157
313
|
|
|
158
314
|
This project uses [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides better organization and composition.
|
|
@@ -160,7 +316,7 @@ This project uses [ESLint flat config](https://eslint.org/docs/latest/use/config
|
|
|
160
316
|
Normally you only need to import the `defineConfig` function:
|
|
161
317
|
|
|
162
318
|
```js
|
|
163
|
-
// eslint.config.
|
|
319
|
+
// eslint.config.ts
|
|
164
320
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
165
321
|
|
|
166
322
|
export default defineConfig();
|
|
@@ -169,7 +325,7 @@ export default defineConfig();
|
|
|
169
325
|
And that's it! Or you can configure each integration individually, for example:
|
|
170
326
|
|
|
171
327
|
```js
|
|
172
|
-
// eslint.config.
|
|
328
|
+
// eslint.config.ts
|
|
173
329
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
174
330
|
|
|
175
331
|
export default defineConfig({
|
|
@@ -200,7 +356,7 @@ export default defineConfig({
|
|
|
200
356
|
The `defineConfig` factory function also accepts any number of custom config overrides:
|
|
201
357
|
|
|
202
358
|
```js
|
|
203
|
-
// eslint.config.
|
|
359
|
+
// eslint.config.ts
|
|
204
360
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
205
361
|
|
|
206
362
|
export default defineConfig(
|
|
@@ -230,7 +386,7 @@ We don't recommend this style unless you know exactly what you're doing, since t
|
|
|
230
386
|
```js
|
|
231
387
|
import { defineConfig } from 'eslint/config';
|
|
232
388
|
|
|
233
|
-
// eslint.config.
|
|
389
|
+
// eslint.config.ts
|
|
234
390
|
import {
|
|
235
391
|
angular,
|
|
236
392
|
comments,
|
|
@@ -274,7 +430,7 @@ All rules are bound to one or more file extensions (via minimatch patterns, e.g.
|
|
|
274
430
|
If you want to override rules, you need to specify the file extension:
|
|
275
431
|
|
|
276
432
|
```js
|
|
277
|
-
// eslint.config.
|
|
433
|
+
// eslint.config.ts
|
|
278
434
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
279
435
|
|
|
280
436
|
export default defineConfig(
|
|
@@ -301,7 +457,7 @@ export default defineConfig(
|
|
|
301
457
|
We also provide the `overrides` option in each integration to make it easier:
|
|
302
458
|
|
|
303
459
|
```js
|
|
304
|
-
// eslint.config.
|
|
460
|
+
// eslint.config.ts
|
|
305
461
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
306
462
|
|
|
307
463
|
export default defineConfig({
|
|
@@ -369,7 +525,7 @@ Most TypeScript rules are enabled automatically if the `typescript` package is i
|
|
|
369
525
|
You can explicitly enable/disable TypeScript integration manually:
|
|
370
526
|
|
|
371
527
|
```js
|
|
372
|
-
// eslint.config.
|
|
528
|
+
// eslint.config.ts
|
|
373
529
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
374
530
|
|
|
375
531
|
export default defineConfig({
|
|
@@ -390,7 +546,7 @@ The TypeScript integration also lets you enable/disable rules that report syntax
|
|
|
390
546
|
You can enable these rules as follows:
|
|
391
547
|
|
|
392
548
|
```js
|
|
393
|
-
// eslint.config.
|
|
549
|
+
// eslint.config.ts
|
|
394
550
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
395
551
|
|
|
396
552
|
export default defineConfig({
|
|
@@ -412,7 +568,7 @@ pnpm add -D eslint-plugin-erasable-syntax-only
|
|
|
412
568
|
Angular support is detected automatically by checking if `@angular/core` is installed in your project. You can also explicitly enable/disable it:
|
|
413
569
|
|
|
414
570
|
```js
|
|
415
|
-
// eslint.config.
|
|
571
|
+
// eslint.config.ts
|
|
416
572
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
417
573
|
|
|
418
574
|
export default defineConfig({
|
|
@@ -432,7 +588,7 @@ NgRx support is also detected automatically if any of the following packages is
|
|
|
432
588
|
As with the Angular integration, it can be explicitly enabled/disabled:
|
|
433
589
|
|
|
434
590
|
```js
|
|
435
|
-
// eslint.config.
|
|
591
|
+
// eslint.config.ts
|
|
436
592
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
437
593
|
|
|
438
594
|
export default defineConfig({
|
|
@@ -447,7 +603,7 @@ export default defineConfig({
|
|
|
447
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:
|
|
448
604
|
|
|
449
605
|
```js
|
|
450
|
-
// eslint.config.
|
|
606
|
+
// eslint.config.ts
|
|
451
607
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
452
608
|
|
|
453
609
|
export default defineConfig({
|
|
@@ -468,6 +624,26 @@ export default defineConfig({
|
|
|
468
624
|
});
|
|
469
625
|
```
|
|
470
626
|
|
|
627
|
+
### Editor Specific Disables
|
|
628
|
+
|
|
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:
|
|
638
|
+
|
|
639
|
+
```js
|
|
640
|
+
// eslint.config.js
|
|
641
|
+
import { defineConfig } from '@fabdeh/eslint-config';
|
|
642
|
+
|
|
643
|
+
export default defineConfig({
|
|
644
|
+
isInEditor: false
|
|
645
|
+
});
|
|
646
|
+
```
|
|
471
647
|
|
|
472
648
|
### Lint Staged
|
|
473
649
|
|
|
@@ -493,6 +669,16 @@ pnpm add -D nano-staged simple-git-hooks
|
|
|
493
669
|
pnpm simple-git-hooks
|
|
494
670
|
```
|
|
495
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
|
+
|
|
496
682
|
## Versioning Policy
|
|
497
683
|
|
|
498
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.
|