@fabdeh/eslint-config 0.9.1 → 0.10.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 +115 -60
- package/dist/index.d.mts +660 -345
- package/dist/index.mjs +209 -241
- package/package.json +21 -34
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.js (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.js
|
|
67
|
+
import baseConfig from '../../eslint.config.js';
|
|
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,7 +127,7 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
78
127
|
"source.organizeImports": "never"
|
|
79
128
|
},
|
|
80
129
|
|
|
81
|
-
// Silence
|
|
130
|
+
// Silence style rules in your IDE, while still fixing them automatically
|
|
82
131
|
"eslint.rules.customizations": [{ "rule": "@stylistic/*", "severity": "off", "fixable": true }],
|
|
83
132
|
|
|
84
133
|
// Enable eslint for all supported languages
|
|
@@ -106,7 +155,7 @@ Add the following settings to your `.vscode/settings.json`:
|
|
|
106
155
|
|
|
107
156
|
## Customization
|
|
108
157
|
|
|
109
|
-
|
|
158
|
+
This project uses [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides better organization and composition.
|
|
110
159
|
|
|
111
160
|
Normally you only need to import the `defineConfig` function:
|
|
112
161
|
|
|
@@ -148,7 +197,7 @@ export default defineConfig({
|
|
|
148
197
|
});
|
|
149
198
|
```
|
|
150
199
|
|
|
151
|
-
The `defineConfig` factory function also accepts any number of
|
|
200
|
+
The `defineConfig` factory function also accepts any number of custom config overrides:
|
|
152
201
|
|
|
153
202
|
```js
|
|
154
203
|
// eslint.config.js
|
|
@@ -156,11 +205,11 @@ import { defineConfig } from '@fabdeh/eslint-config';
|
|
|
156
205
|
|
|
157
206
|
export default defineConfig(
|
|
158
207
|
{
|
|
159
|
-
// Configure
|
|
208
|
+
// Configure @fabdeh/eslint-config
|
|
160
209
|
},
|
|
161
210
|
|
|
162
|
-
// From the second
|
|
163
|
-
//
|
|
211
|
+
// From the second argument onward, these are ESLint flat configs
|
|
212
|
+
// You can provide multiple config objects
|
|
164
213
|
{
|
|
165
214
|
files: ['**/*.ts'],
|
|
166
215
|
rules: {},
|
|
@@ -171,15 +220,15 @@ export default defineConfig(
|
|
|
171
220
|
);
|
|
172
221
|
```
|
|
173
222
|
|
|
174
|
-
|
|
223
|
+
For advanced usage, you can import fine-grained configs and compose them as needed:
|
|
175
224
|
|
|
176
225
|
<details>
|
|
177
226
|
<summary>Advanced Example</summary>
|
|
178
227
|
|
|
179
|
-
We
|
|
228
|
+
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
229
|
|
|
181
230
|
```js
|
|
182
|
-
import
|
|
231
|
+
import { defineConfig } from 'eslint/config';
|
|
183
232
|
|
|
184
233
|
// eslint.config.js
|
|
185
234
|
import {
|
|
@@ -197,7 +246,7 @@ import {
|
|
|
197
246
|
vitest,
|
|
198
247
|
} from '@fabdeh/eslint-config';
|
|
199
248
|
|
|
200
|
-
export default
|
|
249
|
+
export default defineConfig(
|
|
201
250
|
ignores(),
|
|
202
251
|
javascript(/* Options */),
|
|
203
252
|
comments(),
|
|
@@ -215,14 +264,14 @@ export default tseslint.config(
|
|
|
215
264
|
|
|
216
265
|
</details>
|
|
217
266
|
|
|
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/
|
|
267
|
+
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
268
|
|
|
220
269
|
> Thanks to [antfu/eslint-config](https://github.com/antfu/eslint-config) for the inspiration and reference.
|
|
221
270
|
|
|
222
271
|
### Rules Overrides
|
|
223
272
|
|
|
224
|
-
All
|
|
225
|
-
If you want to override
|
|
273
|
+
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).
|
|
274
|
+
If you want to override rules, you need to specify the file extension:
|
|
226
275
|
|
|
227
276
|
```js
|
|
228
277
|
// eslint.config.js
|
|
@@ -258,7 +307,7 @@ import { defineConfig } from '@fabdeh/eslint-config';
|
|
|
258
307
|
export default defineConfig({
|
|
259
308
|
typescript: {
|
|
260
309
|
overrides: {
|
|
261
|
-
'@typescript-eslint/
|
|
310
|
+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
|
262
311
|
},
|
|
263
312
|
},
|
|
264
313
|
angular: {
|
|
@@ -277,6 +326,34 @@ export default defineConfig({
|
|
|
277
326
|
});
|
|
278
327
|
```
|
|
279
328
|
|
|
329
|
+
### Other integrations and defaults
|
|
330
|
+
|
|
331
|
+
In addition to Angular/NgRx/TypeScript/Vitest, `defineConfig()` and `defineWorkspaceConfig()` support:
|
|
332
|
+
|
|
333
|
+
- `gitignore` (default: `true`)
|
|
334
|
+
- `stylistic` (default: `true`)
|
|
335
|
+
- `unicorn` (default: `true`)
|
|
336
|
+
- `regexp` (default: `true`)
|
|
337
|
+
- `jsonc`, `yaml`, `toml`, `markdown` (default: `true`)
|
|
338
|
+
- `pnpm` workspace/catalog rules (default: `false`, currently experimental)
|
|
339
|
+
|
|
340
|
+
Quick example:
|
|
341
|
+
|
|
342
|
+
```js
|
|
343
|
+
import { defineConfig } from '@fabdeh/eslint-config';
|
|
344
|
+
|
|
345
|
+
export default defineConfig({
|
|
346
|
+
gitignore: true,
|
|
347
|
+
unicorn: true,
|
|
348
|
+
regexp: true,
|
|
349
|
+
jsonc: true,
|
|
350
|
+
yaml: true,
|
|
351
|
+
toml: true,
|
|
352
|
+
markdown: true,
|
|
353
|
+
pnpm: false,
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
280
357
|
### Auto-detected integrations
|
|
281
358
|
|
|
282
359
|
The following integrations are automatically enabled if the corresponding package is installed in your project:
|
|
@@ -288,7 +365,7 @@ The following integrations are automatically enabled if the corresponding packag
|
|
|
288
365
|
|
|
289
366
|
#### TypeScript
|
|
290
367
|
|
|
291
|
-
Most
|
|
368
|
+
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
369
|
You can explicitly enable/disable TypeScript integration manually:
|
|
293
370
|
|
|
294
371
|
```js
|
|
@@ -302,7 +379,7 @@ export default defineConfig({
|
|
|
302
379
|
|
|
303
380
|
##### Erasable Syntax Only
|
|
304
381
|
|
|
305
|
-
The TypeScript integration also
|
|
382
|
+
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
383
|
|
|
307
384
|
> 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
385
|
>
|
|
@@ -352,7 +429,7 @@ NgRx support is also detected automatically if any of the following packages is
|
|
|
352
429
|
- `@ngrx/signals`
|
|
353
430
|
- `@ngrx/operators`
|
|
354
431
|
|
|
355
|
-
As the Angular integration
|
|
432
|
+
As with the Angular integration, it can be explicitly enabled/disabled:
|
|
356
433
|
|
|
357
434
|
```js
|
|
358
435
|
// eslint.config.js
|
|
@@ -367,7 +444,7 @@ export default defineConfig({
|
|
|
367
444
|
|
|
368
445
|
#### Vitest
|
|
369
446
|
|
|
370
|
-
The
|
|
447
|
+
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
448
|
|
|
372
449
|
```js
|
|
373
450
|
// eslint.config.js
|
|
@@ -378,41 +455,19 @@ export default defineConfig({
|
|
|
378
455
|
});
|
|
379
456
|
```
|
|
380
457
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
We provide some optional integrations for specific use cases, that we don't include their dependencies by default.
|
|
384
|
-
|
|
385
|
-
#### Formatters
|
|
386
|
-
|
|
387
|
-
Use external formatters to format files that ESLint cannot handle yet (`.css`, `.html`, etc.). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
|
|
458
|
+
You can also configure Vitest helpers explicitly:
|
|
388
459
|
|
|
389
460
|
```js
|
|
390
|
-
// eslint.config.js
|
|
391
461
|
import { defineConfig } from '@fabdeh/eslint-config';
|
|
392
462
|
|
|
393
463
|
export default defineConfig({
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
css: true,
|
|
399
|
-
/**
|
|
400
|
-
* Format HTML files
|
|
401
|
-
*/
|
|
402
|
-
html: true,
|
|
403
|
-
/**
|
|
404
|
-
* Format Markdown files
|
|
405
|
-
*/
|
|
406
|
-
markdown: true,
|
|
407
|
-
}
|
|
464
|
+
vitest: {
|
|
465
|
+
useJestDom: true,
|
|
466
|
+
useTestingLibrary: true,
|
|
467
|
+
},
|
|
408
468
|
});
|
|
409
469
|
```
|
|
410
470
|
|
|
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
471
|
|
|
417
472
|
### Lint Staged
|
|
418
473
|
|
|
@@ -429,7 +484,7 @@ If you want to apply lint and auto-fix before every commit, you can add the foll
|
|
|
429
484
|
}
|
|
430
485
|
```
|
|
431
486
|
|
|
432
|
-
|
|
487
|
+
Then run:
|
|
433
488
|
|
|
434
489
|
```bash
|
|
435
490
|
pnpm add -D nano-staged simple-git-hooks
|