@ivanmaxlogiudice/eslint-config 1.0.0-beta.8 → 1.0.6
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 +20 -20
- package/README.md +282 -25
- package/bin/index.js +3 -0
- package/dist/cli.cjs +283 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +254 -0
- package/dist/index.cjs +1944 -0
- package/dist/index.d.cts +267 -0
- package/dist/index.d.ts +267 -0
- package/dist/index.js +1840 -0
- package/package.json +75 -33
- package/index.cjs +0 -1
- package/index.js +0 -9
- package/src/eslint-comments.js +0 -17
- package/src/js.js +0 -539
- package/src/jsonc.js +0 -116
- package/src/markdown.js +0 -43
- package/src/presets.js +0 -69
- package/src/shared.js +0 -67
- package/src/typescript.js +0 -155
- package/src/unocss.js +0 -13
- package/src/vue.js +0 -198
- package/src/yml.js +0 -26
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022-PRESENT Iván M. Lo Giudice<https://github.com/ivanmaxlogiudice>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-PRESENT Iván M. Lo Giudice<https://github.com/ivanmaxlogiudice>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,66 +1,112 @@
|
|
|
1
1
|
# @ivanmaxlogiudice/eslint-config [](https://npmjs.com/package/@ivanmaxlogiudice/eslint-config) [](https://npmjs.com/package/@ivanmaxlogiudice/eslint-config) #
|
|
2
2
|
|
|
3
|
-
Personal Flat ESLint configuration for Javascript, TypeScript, Vue
|
|
3
|
+
Personal Flat ESLint configuration for Javascript, TypeScript, Vue 3.
|
|
4
4
|
|
|
5
|
-
based on [@
|
|
5
|
+
based on [@antfu/eslint-config](https://github.com/antfu/eslint-config)
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
- Single quotes, no semi
|
|
9
|
-
- Auto fix for formatting (aimed to be used standalone without Prettier)
|
|
10
|
-
- Designed to work with TypeScript, Vue
|
|
9
|
+
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
|
|
10
|
+
- Designed to work with TypeScript, JSX, Vue out-of-box
|
|
11
11
|
- Lint also for json, yaml, markdown
|
|
12
12
|
- Sorted imports, dangling commas
|
|
13
13
|
- Reasonable defaults, best practices, only one-line of config
|
|
14
|
+
- Respects `.gitignore` by default
|
|
15
|
+
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
|
|
16
|
+
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
|
|
17
|
+
- Using [ESLint Perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist) for sorting
|
|
18
|
+
- **Style principle**: Minimal for reading, stable for diff, consistent
|
|
14
19
|
|
|
15
|
-
##
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Install
|
|
16
23
|
```bash
|
|
17
|
-
pnpm
|
|
24
|
+
pnpm i -D @ivanmaxlogiudice/eslint-config
|
|
18
25
|
```
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
### Create config file
|
|
28
|
+
|
|
29
|
+
With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json` (recommended):
|
|
30
|
+
|
|
21
31
|
```js
|
|
22
32
|
// eslint.config.js
|
|
23
|
-
import
|
|
33
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
24
34
|
|
|
25
|
-
export default
|
|
35
|
+
export default config()
|
|
26
36
|
```
|
|
27
37
|
|
|
28
|
-
|
|
38
|
+
With CJS:
|
|
29
39
|
|
|
30
40
|
```js
|
|
31
41
|
// eslint.config.js
|
|
32
|
-
|
|
42
|
+
const config = require('@ivanmaxlogiudice/eslint-config').default
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
[
|
|
36
|
-
/* your custom config */
|
|
37
|
-
],
|
|
38
|
-
{ vue: true, markdown: true, unocss: true }
|
|
39
|
-
)
|
|
44
|
+
module.exports = config()
|
|
40
45
|
```
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
### Add script for package.json
|
|
50
|
+
|
|
51
|
+
For example:
|
|
52
|
+
|
|
53
|
+
```json
|
|
45
54
|
{
|
|
46
|
-
|
|
55
|
+
"scripts": {
|
|
56
|
+
"lint": "eslint .",
|
|
57
|
+
"lint:fix": "eslint . --fix"
|
|
58
|
+
}
|
|
47
59
|
}
|
|
48
60
|
```
|
|
49
61
|
|
|
50
|
-
###
|
|
62
|
+
### Migration
|
|
63
|
+
|
|
64
|
+
We provided an experimental cli tool to help you migrate from the legacy config to the new flat config.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# npm
|
|
68
|
+
npx @ivanmaxlogiudice/eslint-config migrate
|
|
69
|
+
|
|
70
|
+
# pnpm
|
|
71
|
+
pnpm dlx @ivanmaxlogiudice/eslint-config migrate
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Before running the migration, make sure to commit your changes first.
|
|
75
|
+
|
|
76
|
+
## VS Code support (auto fix)
|
|
77
|
+
|
|
51
78
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
52
79
|
|
|
53
80
|
Add the following settings to your `settings.json`:
|
|
54
81
|
|
|
55
82
|
```jsonc
|
|
56
83
|
{
|
|
84
|
+
// Enable the flat config support
|
|
85
|
+
"eslint.experimental.useFlatConfig": true,
|
|
86
|
+
|
|
87
|
+
// Disable the default formatter
|
|
57
88
|
"prettier.enable": false,
|
|
58
89
|
"editor.formatOnSave": false,
|
|
90
|
+
|
|
91
|
+
// Auto fix
|
|
59
92
|
"editor.codeActionsOnSave": {
|
|
60
|
-
"source.fixAll.eslint":
|
|
61
|
-
"source.organizeImports":
|
|
93
|
+
"source.fixAll.eslint": "explicit",
|
|
94
|
+
"source.organizeImports": "never"
|
|
62
95
|
},
|
|
63
|
-
|
|
96
|
+
|
|
97
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
98
|
+
"eslint.rules.customizations": [
|
|
99
|
+
{ "rule": "style/*", "severity": "off" },
|
|
100
|
+
{ "rule": "*-indent", "severity": "off" },
|
|
101
|
+
{ "rule": "*-spacing", "severity": "off" },
|
|
102
|
+
{ "rule": "*-spaces", "severity": "off" },
|
|
103
|
+
{ "rule": "*-order", "severity": "off" },
|
|
104
|
+
{ "rule": "*-dangle", "severity": "off" },
|
|
105
|
+
{ "rule": "*-newline", "severity": "off" },
|
|
106
|
+
{ "rule": "*quotes", "severity": "off" },
|
|
107
|
+
{ "rule": "*semi", "severity": "off" }
|
|
108
|
+
],
|
|
109
|
+
|
|
64
110
|
// The following is optional.
|
|
65
111
|
// It's better to put under project setting `.vscode/settings.json`
|
|
66
112
|
// to avoid conflicts with working with different eslint configs
|
|
@@ -80,6 +126,217 @@ Add the following settings to your `settings.json`:
|
|
|
80
126
|
}
|
|
81
127
|
```
|
|
82
128
|
|
|
129
|
+
## Customization
|
|
130
|
+
|
|
131
|
+
Normally you only need to import the `config` preset:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
// eslint.config.js
|
|
135
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
136
|
+
|
|
137
|
+
export default config()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
And that's it! Or you can configure each integration individually, for example:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
// eslint.config.js
|
|
144
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
145
|
+
|
|
146
|
+
export default config({
|
|
147
|
+
// Enable stylistic formatting rules
|
|
148
|
+
// stylistic: true,
|
|
149
|
+
|
|
150
|
+
// Or customize the stylistic rules
|
|
151
|
+
stylistic: {
|
|
152
|
+
indent: 2, // 4, or 'tab'
|
|
153
|
+
quotes: 'single', // or 'double'
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
|
|
157
|
+
typescript: true,
|
|
158
|
+
vue: true,
|
|
159
|
+
|
|
160
|
+
// Disable jsonc and yaml support
|
|
161
|
+
jsonc: false,
|
|
162
|
+
yaml: false,
|
|
163
|
+
|
|
164
|
+
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
|
|
165
|
+
ignores: [
|
|
166
|
+
'./fixtures',
|
|
167
|
+
// ...globs
|
|
168
|
+
]
|
|
169
|
+
})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The `config` factory function also accepts any number of arbitrary custom config overrides:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
// eslint.config.js
|
|
176
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
177
|
+
|
|
178
|
+
export default config(
|
|
179
|
+
{
|
|
180
|
+
// Configuration
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
// From the second arguments they are ESLint Flat Configs
|
|
184
|
+
// you can have multiple configs
|
|
185
|
+
{
|
|
186
|
+
files: ['**/*.ts'],
|
|
187
|
+
rules: {},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
rules: {},
|
|
191
|
+
},
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Going more advanced, you can also import fine-grained configs and compose them as you wish:
|
|
196
|
+
|
|
197
|
+
<details>
|
|
198
|
+
<summary>Advanced Example</summary>
|
|
199
|
+
|
|
200
|
+
We don't recommend using this style in general usages, as there are shared options between configs and might need extra care to make them consistent.
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
// eslint.config.js
|
|
204
|
+
import {
|
|
205
|
+
comments,
|
|
206
|
+
ignores,
|
|
207
|
+
imports,
|
|
208
|
+
javascript,
|
|
209
|
+
jsdoc,
|
|
210
|
+
jsonc,
|
|
211
|
+
markdown,
|
|
212
|
+
node,
|
|
213
|
+
perfectionist,
|
|
214
|
+
sortPackageJson,
|
|
215
|
+
sortTsconfig,
|
|
216
|
+
stylistic,
|
|
217
|
+
test,
|
|
218
|
+
typescript,
|
|
219
|
+
unicorn,
|
|
220
|
+
unocss,
|
|
221
|
+
vue,
|
|
222
|
+
yaml,
|
|
223
|
+
} from '@ivanmaxlogiudice/eslint-config'
|
|
224
|
+
|
|
225
|
+
export default [
|
|
226
|
+
...comments(),
|
|
227
|
+
...ignores(),
|
|
228
|
+
...imports(),
|
|
229
|
+
...javascript(/* options */),
|
|
230
|
+
...jsdoc(),
|
|
231
|
+
...jsonc(),
|
|
232
|
+
...markdown(),
|
|
233
|
+
...node(),
|
|
234
|
+
...perfectionist(),
|
|
235
|
+
...sortPackageJson(),
|
|
236
|
+
...sortTsconfig(),
|
|
237
|
+
...stylistic(),
|
|
238
|
+
...test(),
|
|
239
|
+
...typescript(/* options */),
|
|
240
|
+
...unicorn(),
|
|
241
|
+
...unocss(),
|
|
242
|
+
...vue(),
|
|
243
|
+
...yaml(),
|
|
244
|
+
]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
</details>
|
|
248
|
+
|
|
249
|
+
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.
|
|
250
|
+
|
|
251
|
+
### Plugins Renaming
|
|
252
|
+
|
|
253
|
+
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.
|
|
254
|
+
|
|
255
|
+
| New Prefix | Original Prefix | Source Plugin |
|
|
256
|
+
| --- | --- | --- |
|
|
257
|
+
| `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
|
|
258
|
+
| `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
|
|
259
|
+
| `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
|
|
260
|
+
| `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
|
|
261
|
+
| `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
|
|
262
|
+
| `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
|
|
263
|
+
| `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
|
|
264
|
+
|
|
265
|
+
When you want to override rules, or disable them inline, you need to update to the new prefix:
|
|
266
|
+
|
|
267
|
+
```diff
|
|
268
|
+
-// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
269
|
+
+// eslint-disable-next-line ts/consistent-type-definitions
|
|
270
|
+
type foo = { bar: 2 }
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Rules Overrides
|
|
274
|
+
|
|
275
|
+
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:
|
|
276
|
+
|
|
277
|
+
```js
|
|
278
|
+
// eslint.config.js
|
|
279
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
280
|
+
|
|
281
|
+
export default config(
|
|
282
|
+
{
|
|
283
|
+
typescript: true,
|
|
284
|
+
vue: true
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
|
|
288
|
+
files: ['**/*.vue'],
|
|
289
|
+
rules: {
|
|
290
|
+
'vue/operator-linebreak': ['error', 'before'],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
// Without `files`, they are general rules for all files
|
|
295
|
+
rules: {
|
|
296
|
+
'style/semi': ['error', 'never'],
|
|
297
|
+
},
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
We also provided an `overrides` options to make it easier:
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
// eslint.config.js
|
|
306
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
307
|
+
|
|
308
|
+
export default config({
|
|
309
|
+
overrides: {
|
|
310
|
+
typescript: {
|
|
311
|
+
'ts/consistent-type-definitions': ['error', 'interface'],
|
|
312
|
+
},
|
|
313
|
+
vue: {
|
|
314
|
+
'vue/operator-linebreak': ['error', 'before'],
|
|
315
|
+
},
|
|
316
|
+
yaml: {},
|
|
317
|
+
// ...
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Type Aware Rules
|
|
323
|
+
|
|
324
|
+
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
// eslint.config.js
|
|
328
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
329
|
+
|
|
330
|
+
export default config({
|
|
331
|
+
typescript: {
|
|
332
|
+
tsconfigPath: 'tsconfig.json',
|
|
333
|
+
|
|
334
|
+
// or if you have multiple tsconfigs
|
|
335
|
+
tsconfigPath: ['tsconfig.json', 'tsconfig.node.json', 'packages/*/tsconfig.json']
|
|
336
|
+
},
|
|
337
|
+
})
|
|
338
|
+
```
|
|
339
|
+
|
|
83
340
|
### Lint Staged
|
|
84
341
|
|
|
85
342
|
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
|
|
@@ -103,4 +360,4 @@ pnpm i -D lint-staged simple-git-hooks
|
|
|
103
360
|
|
|
104
361
|
## License
|
|
105
362
|
|
|
106
|
-
[MIT](./LICENSE) License © 2022-PRESENT [Iván M. Lo Giudice](https://github.com/ivanmaxlogiudice)
|
|
363
|
+
[MIT](./LICENSE) License © 2022-PRESENT [Iván M. Lo Giudice](https://github.com/ivanmaxlogiudice)
|
package/bin/index.js
ADDED
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/cli.ts
|
|
27
|
+
var cli_exports = {};
|
|
28
|
+
module.exports = __toCommonJS(cli_exports);
|
|
29
|
+
|
|
30
|
+
// src/cli/index.ts
|
|
31
|
+
var import_cac = require("cac");
|
|
32
|
+
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
33
|
+
|
|
34
|
+
// src/cli/constants.ts
|
|
35
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
36
|
+
|
|
37
|
+
// package.json
|
|
38
|
+
var version = "1.0.6";
|
|
39
|
+
var devDependencies = {
|
|
40
|
+
"@stylistic/eslint-plugin-migrate": "^1.2.0",
|
|
41
|
+
"@types/eslint": "^8.44.7",
|
|
42
|
+
"@types/fs-extra": "^11.0.4",
|
|
43
|
+
"@types/node": "^20.9.0",
|
|
44
|
+
"@types/prompts": "^2.4.8",
|
|
45
|
+
bumpp: "^9.2.0",
|
|
46
|
+
eslint: "^8.53.0",
|
|
47
|
+
"eslint-flat-config-viewer": "^0.1.1",
|
|
48
|
+
execa: "^8.0.1",
|
|
49
|
+
"fast-glob": "^3.3.2",
|
|
50
|
+
"fs-extra": "^11.1.1",
|
|
51
|
+
"lint-staged": "^15.1.0",
|
|
52
|
+
"simple-git-hooks": "^2.9.0",
|
|
53
|
+
tsup: "^7.2.0",
|
|
54
|
+
typescript: "^5.2.2",
|
|
55
|
+
vitest: "^0.34.6"
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/cli/constants.ts
|
|
59
|
+
var ARROW = import_picocolors.default.cyan("\u2192");
|
|
60
|
+
var CHECK = import_picocolors.default.green("\u2714");
|
|
61
|
+
var CROSS = import_picocolors.default.red("\u2718");
|
|
62
|
+
var WARN = import_picocolors.default.yellow("\u2139");
|
|
63
|
+
var vscodeSettingsString = `
|
|
64
|
+
// Enable the ESlint flat config support
|
|
65
|
+
"eslint.experimental.useFlatConfig": true,
|
|
66
|
+
|
|
67
|
+
// Disable the default formatter, use eslint instead
|
|
68
|
+
"prettier.enable": false,
|
|
69
|
+
"editor.formatOnSave": false,
|
|
70
|
+
|
|
71
|
+
// Auto fix
|
|
72
|
+
"editor.codeActionsOnSave": {
|
|
73
|
+
"source.fixAll.eslint": "explicit",
|
|
74
|
+
"source.organizeImports": "never"
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// Silent the stylistic rules in you IDE, but still auto fix them
|
|
78
|
+
"eslint.rules.customizations": [
|
|
79
|
+
{ "rule": "style/*", "severity": "off" },
|
|
80
|
+
{ "rule": "*-indent", "severity": "off" },
|
|
81
|
+
{ "rule": "*-spacing", "severity": "off" },
|
|
82
|
+
{ "rule": "*-spaces", "severity": "off" },
|
|
83
|
+
{ "rule": "*-order", "severity": "off" },
|
|
84
|
+
{ "rule": "*-dangle", "severity": "off" },
|
|
85
|
+
{ "rule": "*-newline", "severity": "off" },
|
|
86
|
+
{ "rule": "*quotes", "severity": "off" },
|
|
87
|
+
{ "rule": "*semi", "severity": "off" }
|
|
88
|
+
],
|
|
89
|
+
|
|
90
|
+
// Enable eslint for all supported languages
|
|
91
|
+
"eslint.validate": [
|
|
92
|
+
"javascript",
|
|
93
|
+
"javascriptreact",
|
|
94
|
+
"typescript",
|
|
95
|
+
"typescriptreact",
|
|
96
|
+
"vue",
|
|
97
|
+
"html",
|
|
98
|
+
"markdown",
|
|
99
|
+
"json",
|
|
100
|
+
"jsonc",
|
|
101
|
+
"yaml"
|
|
102
|
+
]
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
// src/cli/migrate.ts
|
|
106
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
107
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
108
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
109
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
110
|
+
var import_detect_indent = __toESM(require("detect-indent"), 1);
|
|
111
|
+
var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
112
|
+
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
113
|
+
var import_prompts = __toESM(require("prompts"), 1);
|
|
114
|
+
|
|
115
|
+
// src/cli/utils.ts
|
|
116
|
+
var import_node_child_process = require("child_process");
|
|
117
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
118
|
+
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
119
|
+
function throwError(level, message) {
|
|
120
|
+
console.error(`
|
|
121
|
+
${import_picocolors2.default.inverse(import_picocolors2.default.red(` Failed to migrate `))}`);
|
|
122
|
+
console.error(level, message);
|
|
123
|
+
import_node_process.default.exit(1);
|
|
124
|
+
}
|
|
125
|
+
function isGitClean() {
|
|
126
|
+
try {
|
|
127
|
+
(0, import_node_child_process.execSync)("git diff-index --quiet HEAD --");
|
|
128
|
+
return true;
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/cli/migrate.ts
|
|
135
|
+
var SKIP_PROMPT = !!import_node_process2.default.env.SKIP_PROMPT;
|
|
136
|
+
var SKIP_GIT_CHECK = !!import_node_process2.default.env.SKIP_GIT_CHECK;
|
|
137
|
+
async function migrate() {
|
|
138
|
+
const cwd = import_node_process2.default.cwd();
|
|
139
|
+
const pathPackageJSON = import_node_path.default.join(import_node_process2.default.cwd(), "package.json");
|
|
140
|
+
const pathESLintConfig = import_node_path.default.join(import_node_process2.default.cwd(), "eslint.config.js");
|
|
141
|
+
const pathESLintIngore = import_node_path.default.join(import_node_process2.default.cwd(), ".eslintignore");
|
|
142
|
+
if (import_node_fs.default.existsSync(pathESLintConfig))
|
|
143
|
+
throwError(WARN, "eslint.config.js already exists, migration wizard exited.");
|
|
144
|
+
if (!SKIP_GIT_CHECK && !isGitClean())
|
|
145
|
+
throwError(CROSS, "There are uncommitted changes in the current repository, please commit them and try again.");
|
|
146
|
+
console.log(`
|
|
147
|
+
${ARROW} Installing ${import_picocolors3.default.green("@ivanmaxlogiudice/eslint-config")} to v${import_picocolors3.default.yellow(version)}.
|
|
148
|
+
`);
|
|
149
|
+
const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf-8");
|
|
150
|
+
const pkgIndent = (0, import_detect_indent.default)(pkgContent).indent || 2;
|
|
151
|
+
const pkg = JSON.parse(pkgContent);
|
|
152
|
+
pkg.devDependencies ??= {};
|
|
153
|
+
pkg.devDependencies["@ivanmaxlogiudice/eslint-config"] = `^${version}`;
|
|
154
|
+
await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, pkgIndent));
|
|
155
|
+
console.log(`${CHECK} Changes wrote to package.json`);
|
|
156
|
+
const eslintIgnores = [];
|
|
157
|
+
if (import_node_fs.default.existsSync(pathESLintIngore)) {
|
|
158
|
+
console.log(`${ARROW} Migrating existing .eslintignore.`);
|
|
159
|
+
const content = await import_promises.default.readFile(pathESLintIngore, "utf-8");
|
|
160
|
+
const parsed = (0, import_parse_gitignore.default)(content);
|
|
161
|
+
const globs = parsed.globs();
|
|
162
|
+
for (const glob of globs) {
|
|
163
|
+
if (glob.type === "ignore")
|
|
164
|
+
eslintIgnores.push(...glob.patterns);
|
|
165
|
+
else if (glob.type === "unignore")
|
|
166
|
+
eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let configContent = `${eslintIgnores.length > 0 ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
|
|
170
|
+
if (pkg.type === "module") {
|
|
171
|
+
configContent = `
|
|
172
|
+
import config from '@ivanmaxlogiudice/eslint-config'
|
|
173
|
+
|
|
174
|
+
export default config({
|
|
175
|
+
${configContent}
|
|
176
|
+
})
|
|
177
|
+
`.trimStart();
|
|
178
|
+
} else {
|
|
179
|
+
configContent = `
|
|
180
|
+
const config = require('@ivanmaxlogiudice/eslint-config').default
|
|
181
|
+
|
|
182
|
+
module.exports = config({
|
|
183
|
+
${configContent}
|
|
184
|
+
})
|
|
185
|
+
`.trimStart();
|
|
186
|
+
}
|
|
187
|
+
await import_promises.default.writeFile(pathESLintConfig, configContent);
|
|
188
|
+
console.log(`${CHECK} Created ${import_picocolors3.default.green("eslint.config.js")} successfully.`);
|
|
189
|
+
const files = import_node_fs.default.readdirSync(cwd);
|
|
190
|
+
const legacyFiles = [];
|
|
191
|
+
files.forEach((file) => {
|
|
192
|
+
if (file !== "eslint.config.js" && (file.includes("eslint") || file.includes("prettier")))
|
|
193
|
+
legacyFiles.push(file);
|
|
194
|
+
});
|
|
195
|
+
if (legacyFiles.length > 0) {
|
|
196
|
+
console.log(`
|
|
197
|
+
${WARN} You can now remove those files manually: `);
|
|
198
|
+
console.log(` ${import_picocolors3.default.red("-")} ${import_picocolors3.default.dim(legacyFiles.join(", "))}`);
|
|
199
|
+
}
|
|
200
|
+
const dependencies = { ...pkg.devDependencies, ...pkg?.dependencies };
|
|
201
|
+
const legacyDependencies = [];
|
|
202
|
+
Object.keys(dependencies).forEach((dep) => {
|
|
203
|
+
if (dep.includes("prettier"))
|
|
204
|
+
legacyDependencies.push(dep);
|
|
205
|
+
});
|
|
206
|
+
if (legacyDependencies.length > 0) {
|
|
207
|
+
console.log(`
|
|
208
|
+
${WARN} You can now remove those dependencies: `);
|
|
209
|
+
console.log(` ${import_picocolors3.default.red("-")} ${import_picocolors3.default.dim(legacyDependencies.join(", "))}`);
|
|
210
|
+
}
|
|
211
|
+
const updateESLintVersion = pkg.devDependencies?.eslint ? pkg.devDependencies.eslint !== "latest" && pkg.devDependencies.eslint.match(/\d+/)?.[0] < 8 : true;
|
|
212
|
+
let prompResult = {
|
|
213
|
+
updateESLintVersion,
|
|
214
|
+
updateVscodeSettings: true
|
|
215
|
+
};
|
|
216
|
+
if (!SKIP_PROMPT) {
|
|
217
|
+
console.log();
|
|
218
|
+
try {
|
|
219
|
+
prompResult = await (0, import_prompts.default)([
|
|
220
|
+
{
|
|
221
|
+
initial: true,
|
|
222
|
+
message: "Update .vscode/settings.json for better VSCode experience?",
|
|
223
|
+
name: "updateVscodeSettings",
|
|
224
|
+
type: "confirm"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
initial: true,
|
|
228
|
+
message: "Update ESLint to the latest version?",
|
|
229
|
+
name: "updateESLintVersion",
|
|
230
|
+
type: "confirm"
|
|
231
|
+
}
|
|
232
|
+
], {
|
|
233
|
+
onCancel() {
|
|
234
|
+
throw new Error("Cancelled");
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.log(error.message);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (prompResult.updateVscodeSettings ?? true) {
|
|
243
|
+
const dotVSCodePath = import_node_path.default.join(cwd, ".vscode");
|
|
244
|
+
const settingsPath = import_node_path.default.join(dotVSCodePath, "settings.json");
|
|
245
|
+
if (!import_node_fs.default.existsSync(dotVSCodePath))
|
|
246
|
+
await import_promises.default.mkdir(dotVSCodePath, { recursive: true });
|
|
247
|
+
if (!import_node_fs.default.existsSync(settingsPath)) {
|
|
248
|
+
await import_promises.default.writeFile(settingsPath, `{${vscodeSettingsString}}
|
|
249
|
+
`);
|
|
250
|
+
console.log(`${CHECK} Created ${import_picocolors3.default.green(".vscode/settings.json")} successfully.`);
|
|
251
|
+
} else {
|
|
252
|
+
let settingsContent = await import_promises.default.readFile(settingsPath, "utf-8");
|
|
253
|
+
settingsContent = settingsContent.trim().replace(/\s*}$/, "");
|
|
254
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
255
|
+
settingsContent += `${vscodeSettingsString}}
|
|
256
|
+
`;
|
|
257
|
+
await import_promises.default.writeFile(settingsPath, settingsContent, "utf-8");
|
|
258
|
+
console.log(`${CHECK} Updated ${import_picocolors3.default.green(".vscode/settings.json")} successfully.`);
|
|
259
|
+
console.log(`${WARN} You need to check if there is any conflict between duplicate keys.
|
|
260
|
+
`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (prompResult.updateESLintVersion) {
|
|
264
|
+
pkg.devDependencies.eslint = devDependencies.eslint;
|
|
265
|
+
await import_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, pkgIndent));
|
|
266
|
+
console.log(`${CHECK} Updated ${import_picocolors3.default.green("eslint")} to the version ${import_picocolors3.default.yellow(devDependencies.eslint)}.
|
|
267
|
+
`);
|
|
268
|
+
}
|
|
269
|
+
console.log(`${CHECK} Migration completed!`);
|
|
270
|
+
console.log(`${import_picocolors3.default.green("-")} Now you can update the dependencies and run ${import_picocolors3.default.blue("eslint . --fix")}
|
|
271
|
+
`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/cli/index.ts
|
|
275
|
+
var cli = (0, import_cac.cac)(
|
|
276
|
+
import_picocolors4.default.green("@ivanmaxlogiudice/eslint-config")
|
|
277
|
+
);
|
|
278
|
+
cli.command("migrate", "Migrate from legacy config to new flat config").action(migrate);
|
|
279
|
+
cli.help();
|
|
280
|
+
cli.version(`${import_picocolors4.default.bold(version)}`);
|
|
281
|
+
cli.parse();
|
|
282
|
+
if (!cli.matchedCommand)
|
|
283
|
+
cli.outputHelp();
|
package/dist/cli.d.cts
ADDED