@ivanmaxlogiudice/eslint-config 2.0.2 → 3.0.0-beta.2
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 +2 -2
- package/README.md +28 -543
- package/bin/index.js +1 -1
- package/dist/cli.js +116 -156
- package/dist/index.d.ts +1369 -1540
- package/dist/index.js +929 -1542
- package/package.json +118 -123
- package/dist/cli.cjs +0 -513
- package/dist/cli.d.cts +0 -2
- package/dist/index.cjs +0 -2095
- package/dist/index.d.cts +0 -13618
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-PRESENT Iván
|
|
3
|
+
Copyright (c) 2022-PRESENT Iván Máximiliano, Lo Giudice<https://github.com/ivanmaxlogiudice>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,569 +1,54 @@
|
|
|
1
|
-
# @ivanmaxlogiudice/eslint-config
|
|
1
|
+
# @ivanmaxlogiudice/eslint-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![License][license-src]][license-href]
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
## 🌟 Features
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
- Auto fix for formatting (aimed to be used standalone **without** Prettier).
|
|
10
|
+
- Reasonable defaults, best practices, only one line of config.
|
|
11
|
+
- Designed to work with TypeScript, Vue, JSON, YAML, Markdown, etc. Out-of-box.
|
|
12
|
+
- Sort imports, `package.json`, `tsconfig.json`...
|
|
13
|
+
- Ignores common files like `dist`, `node_modules`, `coverage`, and files in `.gitignore`.
|
|
14
|
+
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
15
|
+
- Sorted imports, dangling commas
|
|
16
|
+
- Single quotes, no semi
|
|
17
|
+
- Indentation 4 spaces.
|
|
18
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
8
19
|
|
|
9
|
-
|
|
10
|
-
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
11
|
-
- Designed to work with TypeScript, JSX, Vue out-of-box
|
|
12
|
-
- Lint also for json, yaml, markdown
|
|
13
|
-
- Sorted imports, dangling commas
|
|
14
|
-
- Reasonable defaults, best practices, only one-line of config
|
|
15
|
-
- Respects `.gitignore` by default
|
|
16
|
-
- Optional [formatters](#formatters) support for CSS, HTML, etc.
|
|
17
|
-
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
18
|
-
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
19
|
-
- Using [ESLint Perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist) for sorting
|
|
20
|
-
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
20
|
+
## 🛠️ Install
|
|
23
21
|
|
|
24
22
|
### Starter Wizard
|
|
25
23
|
|
|
26
|
-
We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
|
|
27
|
-
|
|
28
24
|
```bash
|
|
29
|
-
|
|
25
|
+
bunx @ivanmaxlogiudice/eslint-config@latest
|
|
30
26
|
```
|
|
31
27
|
|
|
32
|
-
### Manual
|
|
33
|
-
|
|
34
|
-
If you prefer to set up manually:
|
|
28
|
+
### Manual instalation
|
|
35
29
|
|
|
36
30
|
```bash
|
|
37
|
-
|
|
31
|
+
bun add -D eslint @ivanmaxlogiudice/eslint-config
|
|
38
32
|
```
|
|
39
33
|
|
|
40
34
|
And create `eslint.config.mjs` in your project root:
|
|
41
35
|
|
|
42
|
-
```js
|
|
43
|
-
// eslint.config.mjs
|
|
44
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
45
|
-
|
|
46
|
-
export default config()
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
<details>
|
|
50
|
-
<summary>
|
|
51
|
-
Combined with legacy config:
|
|
52
|
-
</summary>
|
|
53
|
-
|
|
54
|
-
If you still use some configs from the legacy eslintrc format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
|
|
55
|
-
|
|
56
|
-
```js
|
|
57
|
-
// eslint.config.mjs
|
|
58
|
-
import { FlatCompat } from '@eslint/eslintrc'
|
|
59
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
60
|
-
|
|
61
|
-
const compat = new FlatCompat()
|
|
62
|
-
|
|
63
|
-
export default config(
|
|
64
|
-
{
|
|
65
|
-
ignores: [],
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
// Legacy config
|
|
69
|
-
...compat.config({
|
|
70
|
-
extends: [
|
|
71
|
-
'eslint:recommended',
|
|
72
|
-
// Other extends...
|
|
73
|
-
],
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
// Other flat configs...
|
|
77
|
-
)
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
81
|
-
|
|
82
|
-
</details>
|
|
83
|
-
|
|
84
|
-
### Add script for package.json
|
|
85
|
-
|
|
86
|
-
For example:
|
|
87
|
-
|
|
88
|
-
```json
|
|
89
|
-
{
|
|
90
|
-
"scripts": {
|
|
91
|
-
"lint": "eslint .",
|
|
92
|
-
"lint:fix": "eslint . --fix"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Migration
|
|
98
|
-
|
|
99
|
-
We provided an experimental CLI tool to help you migrate from the legacy config to the new flat config.
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# pnpm
|
|
103
|
-
pnpx @ivanmaxlogiudice/eslint-config@latest
|
|
104
|
-
|
|
105
|
-
Options:
|
|
106
|
-
-y, --yes Skip prompts and use default values
|
|
107
|
-
-i, --ignore-git Skip uncommitted changes
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Before running the migration, make sure to commit your unsaved changes first.
|
|
111
|
-
|
|
112
|
-
## VS Code support (auto fix on save)
|
|
113
|
-
|
|
114
|
-
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
115
|
-
|
|
116
|
-
Add the following settings to your `settings.json`:
|
|
117
|
-
|
|
118
|
-
```jsonc
|
|
119
|
-
{
|
|
120
|
-
// Enable the flat config support
|
|
121
|
-
// (remove this if your ESLint extension above v3.0.5)
|
|
122
|
-
"eslint.useFlatConfig": true,
|
|
123
|
-
|
|
124
|
-
// Disable the default formatter
|
|
125
|
-
"prettier.enable": false,
|
|
126
|
-
"editor.formatOnSave": false,
|
|
127
|
-
|
|
128
|
-
// Auto fix
|
|
129
|
-
"editor.codeActionsOnSave": {
|
|
130
|
-
"source.fixAll.eslint": "explicit",
|
|
131
|
-
"source.organizeImports": "never"
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
135
|
-
"eslint.rules.customizations": [
|
|
136
|
-
{ "rule": "style/*", "severity": "off" },
|
|
137
|
-
{ "rule": "format/*", "severity": "off" },
|
|
138
|
-
{ "rule": "*-indent", "severity": "off" },
|
|
139
|
-
{ "rule": "*-spacing", "severity": "off" },
|
|
140
|
-
{ "rule": "*-spaces", "severity": "off" },
|
|
141
|
-
{ "rule": "*-order", "severity": "off" },
|
|
142
|
-
{ "rule": "*-dangle", "severity": "off" },
|
|
143
|
-
{ "rule": "*-newline", "severity": "off" },
|
|
144
|
-
{ "rule": "*quotes", "severity": "off" },
|
|
145
|
-
{ "rule": "*semi", "severity": "off" }
|
|
146
|
-
],
|
|
147
|
-
|
|
148
|
-
// The following is optional.
|
|
149
|
-
// It's better to put under project setting `.vscode/settings.json`
|
|
150
|
-
// to avoid conflicts with working with different eslint configs
|
|
151
|
-
// that does not support all formats.
|
|
152
|
-
"eslint.validate": [
|
|
153
|
-
"javascript",
|
|
154
|
-
"javascriptreact",
|
|
155
|
-
"typescript",
|
|
156
|
-
"typescriptreact",
|
|
157
|
-
"vue",
|
|
158
|
-
"html",
|
|
159
|
-
"markdown",
|
|
160
|
-
"json",
|
|
161
|
-
"jsonc",
|
|
162
|
-
"gql",
|
|
163
|
-
"graphql"
|
|
164
|
-
]
|
|
165
|
-
}
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Customization
|
|
169
|
-
|
|
170
|
-
Normally you only need to import the `config` preset:
|
|
171
|
-
|
|
172
|
-
```js
|
|
173
|
-
// eslint.config.js
|
|
174
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
175
|
-
|
|
176
|
-
export default config()
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
And that's it! Or you can configure each integration individually, for example:
|
|
180
|
-
|
|
181
|
-
```js
|
|
182
|
-
// eslint.config.js
|
|
183
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
184
|
-
|
|
185
|
-
export default config({
|
|
186
|
-
// Enable stylistic formatting rules
|
|
187
|
-
// stylistic: true,
|
|
188
|
-
|
|
189
|
-
// Or customize the stylistic rules
|
|
190
|
-
stylistic: {
|
|
191
|
-
indent: 2, // 4, or 'tab'
|
|
192
|
-
quotes: 'single', // or 'double'
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
|
|
196
|
-
typescript: true,
|
|
197
|
-
vue: true,
|
|
198
|
-
|
|
199
|
-
// Disable jsonc and yaml support
|
|
200
|
-
jsonc: false,
|
|
201
|
-
yaml: false,
|
|
202
|
-
|
|
203
|
-
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
204
|
-
ignores: [
|
|
205
|
-
'**/fixtures',
|
|
206
|
-
// ...globs
|
|
207
|
-
]
|
|
208
|
-
})
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
The `config` factory function also accepts any number of arbitrary custom config overrides:
|
|
212
|
-
|
|
213
|
-
```js
|
|
214
|
-
// eslint.config.js
|
|
215
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
216
|
-
|
|
217
|
-
export default config(
|
|
218
|
-
{
|
|
219
|
-
// Configuration
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
// From the second arguments they are ESLint Flat Configs
|
|
223
|
-
// you can have multiple configs
|
|
224
|
-
{
|
|
225
|
-
files: ['**/*.ts'],
|
|
226
|
-
rules: {},
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
rules: {},
|
|
230
|
-
},
|
|
231
|
-
)
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
Going more advanced, you can also import fine-grained configs and compose them as you wish:
|
|
235
|
-
|
|
236
|
-
<details>
|
|
237
|
-
<summary>Advanced Example</summary>
|
|
238
|
-
|
|
239
|
-
We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
|
|
240
|
-
|
|
241
|
-
```js
|
|
242
|
-
// eslint.config.js
|
|
243
|
-
import {
|
|
244
|
-
comments,
|
|
245
|
-
ignores,
|
|
246
|
-
imports,
|
|
247
|
-
javascript,
|
|
248
|
-
jsdoc,
|
|
249
|
-
jsonc,
|
|
250
|
-
markdown,
|
|
251
|
-
node,
|
|
252
|
-
perfectionist,
|
|
253
|
-
sortPackageJson,
|
|
254
|
-
sortTsconfig,
|
|
255
|
-
stylistic,
|
|
256
|
-
test,
|
|
257
|
-
typescript,
|
|
258
|
-
unicorn,
|
|
259
|
-
unocss,
|
|
260
|
-
vue,
|
|
261
|
-
yaml,
|
|
262
|
-
} from '@ivanmaxlogiudice/eslint-config'
|
|
263
|
-
|
|
264
|
-
export default [
|
|
265
|
-
...comments(),
|
|
266
|
-
...ignores(),
|
|
267
|
-
...imports(),
|
|
268
|
-
...javascript(/* options */),
|
|
269
|
-
...jsdoc(),
|
|
270
|
-
...jsonc(),
|
|
271
|
-
...markdown(),
|
|
272
|
-
...node(),
|
|
273
|
-
...perfectionist(),
|
|
274
|
-
...sortPackageJson(),
|
|
275
|
-
...sortTsconfig(),
|
|
276
|
-
...stylistic(),
|
|
277
|
-
...test(),
|
|
278
|
-
...typescript(/* options */),
|
|
279
|
-
...unicorn(),
|
|
280
|
-
...unocss(),
|
|
281
|
-
...vue(),
|
|
282
|
-
...yaml(),
|
|
283
|
-
]
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
</details>
|
|
287
|
-
|
|
288
|
-
Check out the [configs](https://github.com/ivanmaxlogiudice/eslint-config/blob/main/src/configs) and [factory](https://github.com/ivanmaxlogiudice/eslint-config/blob/main/src/factory.ts) for more details.
|
|
289
|
-
|
|
290
|
-
### Plugins Renaming
|
|
291
|
-
|
|
292
|
-
Since flat config requires us to explicitly provide the plugin names (instead of mandatory convention from npm package name), we renamed some plugins to make overall scope more consistent and easier to write.
|
|
293
|
-
|
|
294
|
-
| New Prefix | Original Prefix | Source Plugin |
|
|
295
|
-
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
296
|
-
| `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
|
|
297
|
-
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
298
|
-
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
299
|
-
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
300
|
-
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
301
|
-
| `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
|
|
302
|
-
| `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
303
|
-
|
|
304
|
-
When you want to override rules, or disable them inline, you need to update to the new prefix:
|
|
305
|
-
|
|
306
|
-
```diff
|
|
307
|
-
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
308
|
-
+// eslint-disable-next-line ts/consistent-type-definitions
|
|
309
|
-
type foo = { bar: 2 }
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Since v2.0.0, this preset will automatically rename the plugins also for your custom configs. You can use the original prefix to override the rules directly.
|
|
313
|
-
|
|
314
|
-
### Rules Overrides
|
|
315
|
-
|
|
316
|
-
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
|
|
317
|
-
|
|
318
|
-
```js
|
|
319
|
-
// eslint.config.js
|
|
320
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
321
|
-
|
|
322
|
-
export default config(
|
|
323
|
-
{
|
|
324
|
-
vue: true,
|
|
325
|
-
typescript: true
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
329
|
-
files: ['**/*.vue'],
|
|
330
|
-
rules: {
|
|
331
|
-
'vue/operator-linebreak': ['error', 'before'],
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
// Without `files`, they are general rules for all files
|
|
336
|
-
rules: {
|
|
337
|
-
'style/semi': ['error', 'never'],
|
|
338
|
-
},
|
|
339
|
-
}
|
|
340
|
-
)
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
We also provided the `overrides` options in each integration to make it easier:
|
|
344
|
-
|
|
345
|
-
```js
|
|
346
|
-
// eslint.config.js
|
|
347
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
348
|
-
|
|
349
|
-
export default config({
|
|
350
|
-
vue: {
|
|
351
|
-
overrides: {
|
|
352
|
-
'vue/operator-linebreak': ['error', 'before'],
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
typescript: {
|
|
356
|
-
overrides: {
|
|
357
|
-
'ts/consistent-type-definitions': ['error', 'interface'],
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
yaml: {
|
|
361
|
-
overrides: {
|
|
362
|
-
// ...
|
|
363
|
-
},
|
|
364
|
-
},
|
|
365
|
-
})
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Config Composer
|
|
369
|
-
|
|
370
|
-
Since v2.0.0, the factory function `config()` returns a [`FlatConfigComposer` object from `eslint-flat-config-utils`](https://github.com/antfu/eslint-flat-config-utils#composer) where you can chain the methods to compose the config even more flexibly.
|
|
371
|
-
|
|
372
36
|
```js
|
|
373
37
|
// eslint.config.js
|
|
374
38
|
import config from '@ivanmaxlogiudice/eslint-config'
|
|
375
39
|
|
|
376
40
|
export default config()
|
|
377
|
-
.prepend(
|
|
378
|
-
// some configs before the main config
|
|
379
|
-
)
|
|
380
|
-
// overrides any named configs
|
|
381
|
-
.override(
|
|
382
|
-
'antfu/imports',
|
|
383
|
-
{
|
|
384
|
-
rules: {
|
|
385
|
-
'import/order': ['error', { 'newlines-between': 'always' }],
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
)
|
|
389
|
-
// rename plugin prefixes
|
|
390
|
-
.renamePlugins({
|
|
391
|
-
'old-prefix': 'new-prefix',
|
|
392
|
-
// ...
|
|
393
|
-
})
|
|
394
|
-
// ...
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
### Optional Configs
|
|
398
|
-
|
|
399
|
-
We provide some optional configs for specific use cases, that we don't include their dependencies by default.
|
|
400
|
-
|
|
401
|
-
#### Formatters
|
|
402
|
-
|
|
403
|
-
> [!WARNING]
|
|
404
|
-
> Experimental feature, changes might not follow semver.
|
|
405
|
-
> 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).
|
|
406
|
-
|
|
407
|
-
```js
|
|
408
|
-
// eslint.config.js
|
|
409
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
410
|
-
|
|
411
|
-
export default config({
|
|
412
|
-
// Enable all formatters
|
|
413
|
-
// formatters: true,
|
|
414
|
-
|
|
415
|
-
// Or customize the formatters
|
|
416
|
-
formatters: {
|
|
417
|
-
/**
|
|
418
|
-
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
|
|
419
|
-
* By default uses Prettier
|
|
420
|
-
*/
|
|
421
|
-
css: true,
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Format HTML files
|
|
425
|
-
* By default uses Prettier
|
|
426
|
-
*/
|
|
427
|
-
html: true,
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Format Markdown files
|
|
431
|
-
* Supports Prettier and dprint
|
|
432
|
-
* By default uses Prettier
|
|
433
|
-
*/
|
|
434
|
-
markdown: 'prettier'
|
|
435
|
-
}
|
|
436
|
-
})
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
Running `pnpx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
440
|
-
|
|
441
|
-
```bash
|
|
442
|
-
pnpm add -D eslint-plugin-format
|
|
443
41
|
```
|
|
444
42
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
UnoCSS is auto-detected, you can also explicitly enable them:
|
|
448
|
-
|
|
449
|
-
```js
|
|
450
|
-
// eslint.config.js
|
|
451
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
452
|
-
|
|
453
|
-
export default config({
|
|
454
|
-
unocss: true,
|
|
455
|
-
})
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
Running `pnpx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
|
|
459
|
-
|
|
460
|
-
```bash
|
|
461
|
-
pnpm add -D @unocss/eslint-plugin
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
### Optional Rules
|
|
465
|
-
|
|
466
|
-
This config also provides some optional plugins/rules for extended usage.
|
|
467
|
-
|
|
468
|
-
#### `perfectionist` (sorting)
|
|
469
|
-
|
|
470
|
-
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sort object keys, imports, etc, with auto-fix.
|
|
471
|
-
|
|
472
|
-
The plugin is installed, you can check the [enabled rules](/src/configs/perfectionist.ts) for more info.
|
|
473
|
-
|
|
474
|
-
It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
|
|
475
|
-
|
|
476
|
-
```js
|
|
477
|
-
/* eslint perfectionist/sort-objects: "error" */
|
|
478
|
-
const objectWantedToSort = {
|
|
479
|
-
a: 2,
|
|
480
|
-
b: 1,
|
|
481
|
-
c: 3,
|
|
482
|
-
}
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
### Type Aware Rules
|
|
486
|
-
|
|
487
|
-
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
|
|
488
|
-
|
|
489
|
-
```js
|
|
490
|
-
// eslint.config.js
|
|
491
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
492
|
-
|
|
493
|
-
export default config({
|
|
494
|
-
typescript: {
|
|
495
|
-
tsconfigPath: 'tsconfig.json',
|
|
496
|
-
|
|
497
|
-
// or if you have multiple tsconfigs
|
|
498
|
-
tsconfigPath: ['tsconfig.json', 'tsconfig.node.json', 'packages/*/tsconfig.json']
|
|
499
|
-
},
|
|
500
|
-
})
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
### Editor Specific Disables
|
|
504
|
-
|
|
505
|
-
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)
|
|
506
|
-
|
|
507
|
-
This is to prevent unused imports from getting removed by the IDE 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:
|
|
508
|
-
|
|
509
|
-
```js
|
|
510
|
-
// eslint.config.js
|
|
511
|
-
import config from '@ivanmaxlogiudice/eslint-config'
|
|
512
|
-
|
|
513
|
-
export default config({
|
|
514
|
-
isInEditor: false
|
|
515
|
-
})
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
### Lint Staged
|
|
519
|
-
|
|
520
|
-
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
521
|
-
|
|
522
|
-
```json
|
|
523
|
-
{
|
|
524
|
-
"simple-git-hooks": {
|
|
525
|
-
"pre-commit": "pnpm lint-staged"
|
|
526
|
-
},
|
|
527
|
-
"lint-staged": {
|
|
528
|
-
"*": "eslint --fix"
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
and then
|
|
534
|
-
|
|
535
|
-
```bash
|
|
536
|
-
pnpm add -D lint-staged simple-git-hooks
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
## View what rules are enabled
|
|
540
|
-
|
|
541
|
-
Use [@eslint/config-inspector](https://github.com/eslint/config-inspector) to view what rules are enabled in your project and apply them to what files,
|
|
542
|
-
|
|
543
|
-
Go to your project root that contains `eslint.config.js` and run:
|
|
544
|
-
|
|
545
|
-
```bash
|
|
546
|
-
pnpx @eslint/config-inspector
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
## FAQ
|
|
550
|
-
|
|
551
|
-
### Prettier?
|
|
552
|
-
|
|
553
|
-
Why I don't use Prettier ? [Check @antfu post](https://antfu.me/posts/why-not-prettier)
|
|
554
|
-
|
|
555
|
-
Well, you can still use Prettier to format files that are not supported well by ESLint yet, such as `.css`, `.html`, etc. See [formatters](#formatters) for more details.
|
|
556
|
-
|
|
557
|
-
### dprint?
|
|
558
|
-
|
|
559
|
-
[dprint](https://dprint.dev/) is also a great formatter that with more abilities to customize. However, it's in the same model as Prettier which reads the AST and reprints the code from scratch. This means it's similar to Prettier, which ignores the original line breaks and might also cause the inconsistent diff. So in general, we prefer to use ESLint to format and lint JavaScript/TypeScript code.
|
|
560
|
-
|
|
561
|
-
Meanwhile, we do have dprint integrations for formatting other files such as `.md`. See [formatters](#formatters) for more details.
|
|
562
|
-
|
|
563
|
-
### How to format CSS?
|
|
43
|
+
## License
|
|
564
44
|
|
|
565
|
-
|
|
45
|
+
[MIT](./LICENSE) License © 2022-PRESENT [Iván Máximiliano, Lo Giudice](https://github.com/ivanmaxlogiudice)
|
|
566
46
|
|
|
567
|
-
|
|
47
|
+
<!-- Badges -->
|
|
568
48
|
|
|
569
|
-
[
|
|
49
|
+
[npm-version-src]: https://img.shields.io/npm/v/@ivanmaxlogiudice/eslint-config?style=flat&colorA=080f12&colorB=1fa669
|
|
50
|
+
[npm-version-href]: https://npmjs.com/package/@ivanmaxlogiudice/eslint-config
|
|
51
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@ivanmaxlogiudice/eslint-config?style=flat&colorA=080f12&colorB=1fa669
|
|
52
|
+
[npm-downloads-href]: https://npmjs.com/package/@ivanmaxlogiudice/eslint-config
|
|
53
|
+
[license-src]: https://img.shields.io/github/license/ivanmaxlogiudice/eslint-config.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
54
|
+
[license-href]: https://github.com/ivanmaxlogiudice/eslint-config/blob/main/LICENSE
|
package/bin/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
2
|
import '../dist/cli.js'
|