@infernodesign/eslint-config 1.0.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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/index.d.ts +14677 -0
- package/dist/index.js +2276 -0
- package/package.json +110 -0
package/README.md
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
# @infernodesign/eslint-config
|
|
2
|
+
|
|
3
|
+
Shared ESLint flat config presets for Inferno Design projects.
|
|
4
|
+
|
|
5
|
+
- Autofix for formatting (aimed to be used standalone **without** Prettier)
|
|
6
|
+
- Reasonable best practices and only one line of config.
|
|
7
|
+
- Designed to work with TypeScript, JSX, Vue, JSON, YAML, Toml, Markdown, etc. Out-of-box.
|
|
8
|
+
- Uses the [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files-new) for easy compilation.
|
|
9
|
+
- Optional [React](#react), [Next.js](#nextjs), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Solid](#solid) support.
|
|
10
|
+
- Optional [formatters](#formatters) support for formatting CSS, HTML, XML, etc.
|
|
11
|
+
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
12
|
+
- Sorted imports, dangling commas
|
|
13
|
+
- Single quotes, no semi
|
|
14
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
15
|
+
- Respects `.gitignore` by default
|
|
16
|
+
- Requires ESLint v9.5.0+
|
|
17
|
+
|
|
18
|
+
## Setup
|
|
19
|
+
|
|
20
|
+
> [!NOTE]
|
|
21
|
+
> Since this package is hosted in the GitHub Packages registry and is private to just Inferno Design, you must configure your `.npmrc` file to access the private registry.
|
|
22
|
+
|
|
23
|
+
### `.npmrc` Configuration
|
|
24
|
+
|
|
25
|
+
To configure your `.npmrc` file, add the following line:
|
|
26
|
+
|
|
27
|
+
```ini
|
|
28
|
+
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN
|
|
29
|
+
@infernodesign:registry=https://npm.pkg.github.com/
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then, create an environment variable `GITHUB_TOKEN` with a personal access token that has the `read:packages` scope. Alternatively, you can replace `$GITHUB_TOKEN` with your personal access token directly in the `.npmrc` file. Make sure you don't commit this file to VCS to avoid exposing your token.
|
|
33
|
+
|
|
34
|
+
### Registry Configuration
|
|
35
|
+
|
|
36
|
+
Alternatively, you can configure the registry for the `@infernodesign` packages registry scope using the following command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm config set @infernodesign:registry https://npm.pkg.github.com/
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This command sets the registry for the `@infernodesign` scope to the GitHub Packages registry.
|
|
43
|
+
|
|
44
|
+
### Authentication
|
|
45
|
+
|
|
46
|
+
Ensure that your authentication is set up correctly to access the packages. You can add your GitHub token to the `.npmrc` file as shown above or use the following command:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm config set //npm.pkg.github.com/:_authToken <your-personal-access-token>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Replace `<your-personal-access-token>` with your actual GitHub personal access token.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### Quick Start
|
|
57
|
+
|
|
58
|
+
To quickly set up ESLint with the Inferno Design configuration or migrate from the legacy config to the new flat config, run the following CLI command in the root of your project:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pnpm dlx @infernodesign/eslint-config@latest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Manual Installation
|
|
65
|
+
|
|
66
|
+
To manually install and configure ESLint with the Inferno Design configuration, follow these steps:
|
|
67
|
+
|
|
68
|
+
Install the necessary dependencies:
|
|
69
|
+
|
|
70
|
+
```shell
|
|
71
|
+
pnpm i -D eslint @infernodesign/eslint-config
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Create a `eslint.config.js` in your project root:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// eslint.config.mjs
|
|
78
|
+
import config from '@infernodesign/eslint-config'
|
|
79
|
+
|
|
80
|
+
export default config()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
That's it! You can now run ESLint in your project:
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
eslint . --fix
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
<details>
|
|
90
|
+
<summary>
|
|
91
|
+
Combine with legacy config:
|
|
92
|
+
</summary>
|
|
93
|
+
|
|
94
|
+
To use configs from the legacy `eslintrc` format, use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
// eslint.config.mjs
|
|
98
|
+
import { FlatCompat } from '@eslint/eslintrc'
|
|
99
|
+
import config from '@infernodesign/eslint-config'
|
|
100
|
+
|
|
101
|
+
const compat = new FlatCompat()
|
|
102
|
+
|
|
103
|
+
export default config(
|
|
104
|
+
{
|
|
105
|
+
ignores: [],
|
|
106
|
+
},
|
|
107
|
+
// Legacy config
|
|
108
|
+
...compat.config( {
|
|
109
|
+
extends: [
|
|
110
|
+
'eslint:recommended',
|
|
111
|
+
// Other extends...
|
|
112
|
+
],
|
|
113
|
+
} )
|
|
114
|
+
// Other flat configs...
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
> [!NOTE]
|
|
119
|
+
> `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
120
|
+
|
|
121
|
+
</details>
|
|
122
|
+
|
|
123
|
+
### Node Package Scripts
|
|
124
|
+
|
|
125
|
+
To lint your project, add the following scripts to your `package.json`:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"scripts": {
|
|
130
|
+
"lint": "eslint .",
|
|
131
|
+
"lint:fix": "eslint . --fix"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Precommit Hook
|
|
137
|
+
|
|
138
|
+
To lint your project before committing, use a precommit hook with [husky](https://typicode.github.io/husky/#/):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
pnpm install husky --save-dev
|
|
142
|
+
pnpx husky install
|
|
143
|
+
pnpx husky add .husky/pre-commit "eslint . --fix && git add ."
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
This will automatically lint and fix your code before each commit.
|
|
147
|
+
|
|
148
|
+
## VS Code Support (Autofix on Save)
|
|
149
|
+
|
|
150
|
+
Install the [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
|
|
151
|
+
|
|
152
|
+
Then, add the following settings to your `.vscode/settings.json`:
|
|
153
|
+
|
|
154
|
+
```json5
|
|
155
|
+
{
|
|
156
|
+
// Disable the default formatter, use eslint instead
|
|
157
|
+
"prettier.enable": false,
|
|
158
|
+
"editor.formatOnSave": false,
|
|
159
|
+
|
|
160
|
+
// Autofix on save
|
|
161
|
+
"editor.codeActionsOnSave": {
|
|
162
|
+
"source.fixAll.eslint": "explicit",
|
|
163
|
+
"source.organizeImports": "never"
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// (Optional) Silent the stylistic rules in the IDE, but still autofix them
|
|
167
|
+
"eslint.rules.customizations": [
|
|
168
|
+
{ "rule": "style/*", "severity": "off", "fixable": true },
|
|
169
|
+
{ "rule": "format/*", "severity": "off", "fixable": true },
|
|
170
|
+
{ "rule": "*-indent", "severity": "off", "fixable": true },
|
|
171
|
+
{ "rule": "*-spacing", "severity": "off", "fixable": true },
|
|
172
|
+
{ "rule": "*-spaces", "severity": "off", "fixable": true },
|
|
173
|
+
{ "rule": "*-order", "severity": "off", "fixable": true },
|
|
174
|
+
{ "rule": "*-dangle", "severity": "off", "fixable": true },
|
|
175
|
+
{ "rule": "*-newline", "severity": "off", "fixable": true },
|
|
176
|
+
{ "rule": "*quotes", "severity": "off", "fixable": true },
|
|
177
|
+
{ "rule": "*semi", "severity": "off", "fixable": true }
|
|
178
|
+
],
|
|
179
|
+
|
|
180
|
+
// Enable eslint for all supported languages
|
|
181
|
+
"eslint.validate": [
|
|
182
|
+
"javascript",
|
|
183
|
+
"javascriptreact",
|
|
184
|
+
"typescript",
|
|
185
|
+
"typescriptreact",
|
|
186
|
+
"vue",
|
|
187
|
+
"html",
|
|
188
|
+
"markdown",
|
|
189
|
+
"json",
|
|
190
|
+
"jsonc",
|
|
191
|
+
"yaml",
|
|
192
|
+
"toml",
|
|
193
|
+
"xml",
|
|
194
|
+
"gql",
|
|
195
|
+
"graphql",
|
|
196
|
+
"astro",
|
|
197
|
+
"svelte",
|
|
198
|
+
"css",
|
|
199
|
+
"less",
|
|
200
|
+
"scss",
|
|
201
|
+
"pcss",
|
|
202
|
+
"postcss"
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Customization
|
|
208
|
+
|
|
209
|
+
This package uses the new [ESLint Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition.
|
|
210
|
+
|
|
211
|
+
Normally you only need to import the `config` preset:
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
// eslint.config.js
|
|
215
|
+
import config from '@infernodesign/eslint-config'
|
|
216
|
+
|
|
217
|
+
export default config()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
And that's it! Or you can configure each integration individually, for example:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
// eslint.config.js
|
|
224
|
+
import config from '@infernodesign/eslint-config'
|
|
225
|
+
|
|
226
|
+
export default config( {
|
|
227
|
+
// Type of the project. 'lib' for libraries, the default is 'app'
|
|
228
|
+
type: 'lib',
|
|
229
|
+
|
|
230
|
+
// Enable stylistic formatting rules
|
|
231
|
+
// stylistic: true,
|
|
232
|
+
|
|
233
|
+
// Or, customize the stylistic rules
|
|
234
|
+
stylistic: {
|
|
235
|
+
indent: 2, // 4, or 'tab'
|
|
236
|
+
quotes: 'single', // or 'double'
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
|
|
240
|
+
typescript: true,
|
|
241
|
+
vue: true,
|
|
242
|
+
|
|
243
|
+
// Enable React
|
|
244
|
+
react: true,
|
|
245
|
+
|
|
246
|
+
// Enable Next.js
|
|
247
|
+
next: true,
|
|
248
|
+
|
|
249
|
+
// Disable jsonc and yaml support
|
|
250
|
+
jsonc: false,
|
|
251
|
+
yaml: false,
|
|
252
|
+
|
|
253
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
254
|
+
ignores: [
|
|
255
|
+
'**/fixtures',
|
|
256
|
+
// ... Additional globs
|
|
257
|
+
]
|
|
258
|
+
} )
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The `config` factory function accepts any amount of custom config overrides:
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
// eslint.config.js
|
|
265
|
+
import config from '@infernodesign/eslint-config'
|
|
266
|
+
|
|
267
|
+
export default config(
|
|
268
|
+
{
|
|
269
|
+
// Configurations for `config`
|
|
270
|
+
},
|
|
271
|
+
// ESLint Flat Configs
|
|
272
|
+
{
|
|
273
|
+
files: [ '**/*.ts' ],
|
|
274
|
+
rules: {},
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
files: [ '**/*.vue' ],
|
|
278
|
+
rules: {},
|
|
279
|
+
},
|
|
280
|
+
)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
A more advanced usage, import fine-grained configs and compose them together:
|
|
284
|
+
|
|
285
|
+
### Advanced Example
|
|
286
|
+
|
|
287
|
+
Using this style is not recommended as the shared options between configs might need extra care to be consistent.
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
// eslint.config.js
|
|
291
|
+
import {
|
|
292
|
+
combine,
|
|
293
|
+
comments,
|
|
294
|
+
ignores,
|
|
295
|
+
imports,
|
|
296
|
+
javascript,
|
|
297
|
+
jsdoc,
|
|
298
|
+
jsonc,
|
|
299
|
+
markdown,
|
|
300
|
+
next,
|
|
301
|
+
node,
|
|
302
|
+
react,
|
|
303
|
+
sortPackageJson,
|
|
304
|
+
sortTsconfig,
|
|
305
|
+
stylistic,
|
|
306
|
+
toml,
|
|
307
|
+
typescript,
|
|
308
|
+
unicorn,
|
|
309
|
+
vue,
|
|
310
|
+
yaml,
|
|
311
|
+
} from '@infernodesign/eslint-config'
|
|
312
|
+
|
|
313
|
+
export default combine(
|
|
314
|
+
combine(),
|
|
315
|
+
comments(),
|
|
316
|
+
ignores(),
|
|
317
|
+
imports(),
|
|
318
|
+
javascript( /* options */ ),
|
|
319
|
+
jsdoc(),
|
|
320
|
+
jsonc(),
|
|
321
|
+
markdown(),
|
|
322
|
+
next(),
|
|
323
|
+
node(),
|
|
324
|
+
react( /* options */ ),
|
|
325
|
+
sortPackageJson(),
|
|
326
|
+
sortTsconfig(),
|
|
327
|
+
stylistic(),
|
|
328
|
+
toml(),
|
|
329
|
+
typescript( /* options */ ),
|
|
330
|
+
unicorn(),
|
|
331
|
+
vue(),
|
|
332
|
+
yaml(),
|
|
333
|
+
)
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Refer to the [configs](https://github.com/infernodesign/tooling/tree/main/tooling/eslint/src/configs) and [factory](https://github.com/infernodesign/tooling/tree/main/tooling/eslint/src/factory.ts) source files for more details.
|
|
337
|
+
|
|
338
|
+
### Plugin Renaming
|
|
339
|
+
|
|
340
|
+
Since ESLint Flat Config requires explicitly providing the plugin names (instead of the mandatory convention from npm package name), some plugins have been renamed to make the overall scope more consistent and easier to write.
|
|
341
|
+
|
|
342
|
+
| New Prefix | Original Prefix | Source Plugin |
|
|
343
|
+
|------------|------------------------|----------------------------------------------------------------------------------------------------------------------|
|
|
344
|
+
| `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
|
|
345
|
+
| `next/*` | `@next/next/*` | [@next/eslint-plugin-next](https://nextjs.org/docs/pages/building-your-application/configuring/eslint#eslint-plugin) |
|
|
346
|
+
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
347
|
+
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
348
|
+
| `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
|
|
349
|
+
| `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
350
|
+
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
351
|
+
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
352
|
+
|
|
353
|
+
To override rules, or disable them inline, use the new prefix:
|
|
354
|
+
|
|
355
|
+
```diff
|
|
356
|
+
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
357
|
+
+// eslint-disable-next-line ts/consistent-type-definitions
|
|
358
|
+
type foo = { bar: 2 }
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
> [!NOTE]
|
|
362
|
+
> This preset will automatically rename the plugins for your custom configs. Use the original prefix to override the rules directly.
|
|
363
|
+
|
|
364
|
+
### Rules Overrides
|
|
365
|
+
|
|
366
|
+
Certain rules would only be enabled for specific files. For example, `ts/*` rules would only be enabled in
|
|
367
|
+
`.ts` files and `vue/*` rules would only be enabled in `.vue` files. To override the rules, specify the file extension:
|
|
368
|
+
|
|
369
|
+
```js
|
|
370
|
+
// eslint.config.js
|
|
371
|
+
import config from '@infernodesign/eslint-config'
|
|
372
|
+
|
|
373
|
+
export default config(
|
|
374
|
+
{
|
|
375
|
+
typescript: true,
|
|
376
|
+
vue: true
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
380
|
+
files: [ '**/*.vue' ],
|
|
381
|
+
rules: {
|
|
382
|
+
'vue/operator-linebreak': [ 'error', 'before' ],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
// Without `files`, they are general rules for all files
|
|
387
|
+
rules: {
|
|
388
|
+
'style/semi': [ 'error', 'never' ],
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
)
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Use the provided `overrides` options in each integration to make overrides easier:
|
|
395
|
+
|
|
396
|
+
```js
|
|
397
|
+
// eslint.config.js
|
|
398
|
+
import config from '@infernodesign/eslint-config'
|
|
399
|
+
|
|
400
|
+
export default config( {
|
|
401
|
+
typescript: {
|
|
402
|
+
overrides: {
|
|
403
|
+
'ts/consistent-type-definitions': [ 'error', 'interface' ],
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
vue: {
|
|
407
|
+
overrides: {
|
|
408
|
+
'vue/operator-linebreak': [ 'error', 'before' ],
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
yaml: {
|
|
412
|
+
overrides: {
|
|
413
|
+
// ...
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
} )
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Config Composer
|
|
420
|
+
|
|
421
|
+
The factory function `config()` returns a [`FlatConfigComposer` object from
|
|
422
|
+
`eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer) where you can chain the methods to compose the config more flexibly.
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
// eslint.config.js
|
|
426
|
+
import config from '@infernodesign/eslint-config'
|
|
427
|
+
|
|
428
|
+
export default config()
|
|
429
|
+
.prepend(
|
|
430
|
+
// some configs before the main config
|
|
431
|
+
)
|
|
432
|
+
// overrides any named configs
|
|
433
|
+
.override(
|
|
434
|
+
'config/imports',
|
|
435
|
+
{
|
|
436
|
+
rules: {
|
|
437
|
+
'import/order': [ 'error', { 'newlines-between': 'always' } ],
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
)
|
|
441
|
+
// rename plugin prefixes
|
|
442
|
+
.renamePlugins( {
|
|
443
|
+
'old-prefix': 'new-prefix',
|
|
444
|
+
// ...
|
|
445
|
+
} )
|
|
446
|
+
// ...
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Vue
|
|
450
|
+
|
|
451
|
+
Vue support is detected automatically by checking if
|
|
452
|
+
`vue` is installed in your project. To explicitly enable/disable it:
|
|
453
|
+
|
|
454
|
+
```js
|
|
455
|
+
// eslint.config.js
|
|
456
|
+
import config from '@infernodesign/eslint-config'
|
|
457
|
+
|
|
458
|
+
export default config( {
|
|
459
|
+
vue: true
|
|
460
|
+
} )
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
#### Vue 2
|
|
464
|
+
|
|
465
|
+
Limited support for Vue 2 is available since it has [reached EOL](https://v2.vuejs.org/eol/). To use Vue 2, configure it manually by setting
|
|
466
|
+
`vueVersion` to `2`:
|
|
467
|
+
|
|
468
|
+
```js
|
|
469
|
+
// eslint.config.js
|
|
470
|
+
import config from '@infernodesign/eslint-config'
|
|
471
|
+
|
|
472
|
+
export default config( {
|
|
473
|
+
vue: {
|
|
474
|
+
vueVersion: 2
|
|
475
|
+
},
|
|
476
|
+
} )
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Optional Configs
|
|
480
|
+
|
|
481
|
+
Some optional configs are available for specific use cases. Their dependencies are not provided by default.
|
|
482
|
+
|
|
483
|
+
#### Formatters
|
|
484
|
+
|
|
485
|
+
Use external formatters to format files that ESLint can't handle yet (`.css`, `.html`, etc). Powered by [`eslint-plugin-format`](https://github.com/antfu/eslint-plugin-format).
|
|
486
|
+
|
|
487
|
+
```js
|
|
488
|
+
// eslint.config.js
|
|
489
|
+
import config from '@infernodesign/eslint-config'
|
|
490
|
+
|
|
491
|
+
export default config( {
|
|
492
|
+
formatters: {
|
|
493
|
+
/**
|
|
494
|
+
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
|
|
495
|
+
* By default uses Prettier
|
|
496
|
+
*/
|
|
497
|
+
css: true,
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Format HTML files
|
|
501
|
+
* By default uses Prettier
|
|
502
|
+
*/
|
|
503
|
+
html: true,
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Format Markdown files
|
|
507
|
+
* Supports Prettier and dprint
|
|
508
|
+
* By default uses Prettier
|
|
509
|
+
*/
|
|
510
|
+
markdown: 'prettier'
|
|
511
|
+
}
|
|
512
|
+
} )
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
Then, install the required dependencies:
|
|
516
|
+
|
|
517
|
+
```shell
|
|
518
|
+
pnpm i -D eslint-plugin-format
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
#### Next.js
|
|
522
|
+
|
|
523
|
+
To enable Next.js support, explicitly turn it on:
|
|
524
|
+
|
|
525
|
+
```js
|
|
526
|
+
// eslint.config.js
|
|
527
|
+
import config from '@infernodesign/eslint-config'
|
|
528
|
+
|
|
529
|
+
export default config( {
|
|
530
|
+
next: true,
|
|
531
|
+
} )
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
Then, install the required dependencies:
|
|
535
|
+
|
|
536
|
+
```shell
|
|
537
|
+
pnpm i -D @next/eslint-next-plugin
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### React
|
|
541
|
+
|
|
542
|
+
To enable React support, explicitly turn it on:
|
|
543
|
+
|
|
544
|
+
```js
|
|
545
|
+
// eslint.config.js
|
|
546
|
+
import config from '@infernodesign/eslint-config'
|
|
547
|
+
|
|
548
|
+
export default config( {
|
|
549
|
+
react: true,
|
|
550
|
+
} )
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
Then, install the required dependencies:
|
|
554
|
+
|
|
555
|
+
```shell
|
|
556
|
+
pnpm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
#### Svelte
|
|
560
|
+
|
|
561
|
+
To enable svelte support, explicitly turn it on:
|
|
562
|
+
|
|
563
|
+
```js
|
|
564
|
+
// eslint.config.js
|
|
565
|
+
import config from '@infernodesign/eslint-config'
|
|
566
|
+
|
|
567
|
+
export default config( {
|
|
568
|
+
svelte: true,
|
|
569
|
+
} )
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
Then, install the required dependencies:
|
|
573
|
+
|
|
574
|
+
```shell
|
|
575
|
+
pnpm i -D eslint-plugin-svelte
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
#### Astro
|
|
579
|
+
|
|
580
|
+
To enable astro support, explicitly turn it on:
|
|
581
|
+
|
|
582
|
+
```js
|
|
583
|
+
// eslint.config.js
|
|
584
|
+
import config from '@infernodesign/eslint-config'
|
|
585
|
+
|
|
586
|
+
export default config( {
|
|
587
|
+
astro: true,
|
|
588
|
+
} )
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
Then, install the required dependencies:
|
|
592
|
+
|
|
593
|
+
```shell
|
|
594
|
+
pnpm i -D eslint-plugin-astro
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
#### Solid
|
|
598
|
+
|
|
599
|
+
To enable Solid support, explicitly turn it on:
|
|
600
|
+
|
|
601
|
+
```js
|
|
602
|
+
// eslint.config.js
|
|
603
|
+
import config from '@infernodesign/eslint-config'
|
|
604
|
+
|
|
605
|
+
export default config( {
|
|
606
|
+
solid: true,
|
|
607
|
+
} )
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
Then, install the required dependencies:
|
|
611
|
+
|
|
612
|
+
```shell
|
|
613
|
+
pnpm i -D eslint-plugin-solid
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
#### UnoCSS
|
|
617
|
+
|
|
618
|
+
To enable UnoCSS support, explicitly turn it on:
|
|
619
|
+
|
|
620
|
+
```js
|
|
621
|
+
// eslint.config.js
|
|
622
|
+
import config from '@infernodesign/eslint-config'
|
|
623
|
+
|
|
624
|
+
export default config( {
|
|
625
|
+
unocss: true,
|
|
626
|
+
} )
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
Then, install the required dependencies:
|
|
630
|
+
|
|
631
|
+
```shell
|
|
632
|
+
pnpm i -D @unocss/eslint-plugin
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### Type-Aware Rules
|
|
636
|
+
|
|
637
|
+
You can optionally enable the [type-aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the
|
|
638
|
+
`typescript` config:
|
|
639
|
+
|
|
640
|
+
```js
|
|
641
|
+
// eslint.config.js
|
|
642
|
+
import config from '@infernodesign/eslint-config'
|
|
643
|
+
|
|
644
|
+
export default config( {
|
|
645
|
+
typescript: {
|
|
646
|
+
tsconfigPath: 'tsconfig.json',
|
|
647
|
+
},
|
|
648
|
+
} )
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### Command-Line Interface (CLI)
|
|
652
|
+
|
|
653
|
+
Powered by [`eslint-plugin-command`](https://github.com/antfu/eslint-plugin-command). It is not a typical rule for linting, but an on-demand micro-codemod tool that triggers by specific comments.
|
|
654
|
+
|
|
655
|
+
For a few triggers, for example:
|
|
656
|
+
|
|
657
|
+
- `/// to-function` - converts an arrow function to a normal function
|
|
658
|
+
- `/// to-arrow` - converts a normal function to an arrow function
|
|
659
|
+
- `/// to-for-each` - converts a for-in/for-of loop to `.forEach()`
|
|
660
|
+
- `/// to-for-of` - converts a `.forEach()` to a for-of loop
|
|
661
|
+
- `/// keep-sorted` - sorts an object/array/interface
|
|
662
|
+
- ... etc. - refer to the [documentation](https://github.com/antfu/eslint-plugin-command#built-in-commands)
|
|
663
|
+
|
|
664
|
+
You can add the trigger comment one line above the code you want to transform, for example (note the triple slash):
|
|
665
|
+
|
|
666
|
+
<!-- eslint-skip -->
|
|
667
|
+
|
|
668
|
+
```ts
|
|
669
|
+
/// to-function
|
|
670
|
+
const foo = async ( msg: string ): void => {
|
|
671
|
+
console.log( msg )
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
Will be transformed to this when you hit save with your editor or run `eslint . --fix`:
|
|
676
|
+
|
|
677
|
+
```ts
|
|
678
|
+
async function foo( msg: string ): void {
|
|
679
|
+
console.log( msg )
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
The command comments are usually one-off and will be removed along with the transformation.
|
|
684
|
+
|
|
685
|
+
### Editor Specific Disables
|
|
686
|
+
|
|
687
|
+
Some rules are disabled when inside ESLint IDE integrations, namely [`unused-imports/no-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) [`test/no-only-tests`](https://github.com/levibuzolic/eslint-plugin-no-only-tests).
|
|
688
|
+
|
|
689
|
+
This is to prevent unused imports from getting removed by the IDE during refactoring to get a better DX. Those rules will be applied when running ESLint in the terminal or [Lint Staged](#lint-staged). To disable this behavior:
|
|
690
|
+
|
|
691
|
+
```js
|
|
692
|
+
// eslint.config.js
|
|
693
|
+
import config from '@infernodesign/eslint-config'
|
|
694
|
+
|
|
695
|
+
export default config( {
|
|
696
|
+
isInEditor: false
|
|
697
|
+
} )
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
### Lint Staged
|
|
701
|
+
|
|
702
|
+
To apply linting and auto fixing before every commit, add the following to your `package.json`:
|
|
703
|
+
|
|
704
|
+
```json
|
|
705
|
+
{
|
|
706
|
+
"simple-git-hooks": {
|
|
707
|
+
"pre-commit": "pnpm lint-staged"
|
|
708
|
+
},
|
|
709
|
+
"lint-staged": {
|
|
710
|
+
"*": "eslint --fix"
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
Then, install the required dependencies:
|
|
716
|
+
|
|
717
|
+
```shell
|
|
718
|
+
pnpm i -D lint-staged simple-git-hooks
|
|
719
|
+
|
|
720
|
+
# to activate the hooks
|
|
721
|
+
npx simple-git-hooks
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
## View what rules are enabled
|
|
725
|
+
|
|
726
|
+
Use the [`@eslint/config-inspector`](https://github.com/eslint/config-inspector) visual tool to view the enabled rules in your project and applied to each file.
|
|
727
|
+
|
|
728
|
+
In the project root that contains the `eslint.config.js`file, run:
|
|
729
|
+
|
|
730
|
+
```shell
|
|
731
|
+
pnpx @eslint/config-inspector
|
|
732
|
+
|
|
733
|
+
# or specify the config file
|
|
734
|
+
pnpx @eslint/config-inspector --config ./eslint.config.js
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
## License
|
|
738
|
+
|
|
739
|
+
Licensed under the [MIT License](./LICENSE).
|
|
740
|
+
|
|
741
|
+
## Credits
|
|
742
|
+
|
|
743
|
+
- Inspired by [Antfu's eslint-config](https://github.com/antfu/eslint-config)
|