@coderwyd/eslint-config 2.0.2 → 2.1.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 +157 -8
- package/dist/cli.cjs +10 -8
- package/dist/cli.js +16 -14
- package/dist/index.cjs +128 -41
- package/dist/index.d.cts +2 -9
- package/dist/index.d.ts +2 -9
- package/dist/index.js +134 -47
- package/package.json +35 -20
package/README.md
CHANGED
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
## Feature
|
|
8
8
|
|
|
9
|
-
- ✨ Single quotes, no semi
|
|
10
9
|
- 🛠️ Auto fix for formatting
|
|
10
|
+
- ✨ Support Vue, React, Svelte.
|
|
11
11
|
- 🎯 Designed to work with TypeScript, Vue out-of-box
|
|
12
|
-
- 🔍 Lints also for json
|
|
13
|
-
- 🧩 Sorted imports, dangling commas
|
|
14
12
|
- 🏆 Reasonable defaults, best practices, only one-line of config
|
|
15
|
-
-
|
|
16
|
-
- 🎨 Use ESlint and Prettier to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown.
|
|
13
|
+
- 🎨 Use ESlint and Prettier to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown, JSON, JSONC.
|
|
17
14
|
|
|
18
15
|
## Usage
|
|
19
16
|
|
|
@@ -60,8 +57,6 @@ For example:
|
|
|
60
57
|
|
|
61
58
|
## VS Code support (auto fix)
|
|
62
59
|
|
|
63
|
-
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
64
|
-
|
|
65
60
|
Add the following settings to your `.vscode/settings.json`:
|
|
66
61
|
|
|
67
62
|
```jsonc
|
|
@@ -109,12 +104,166 @@ If you want to apply lint and auto-fix before every commit, you can add the foll
|
|
|
109
104
|
}
|
|
110
105
|
}
|
|
111
106
|
```
|
|
112
|
-
|
|
113
107
|
and then
|
|
114
108
|
|
|
115
109
|
```bash
|
|
116
110
|
npm i -D lint-staged simple-git-hooks
|
|
117
111
|
```
|
|
112
|
+
## Options
|
|
113
|
+
|
|
114
|
+
### interface Options
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
interface OptionsConfig {
|
|
118
|
+
/**
|
|
119
|
+
* The current working directory
|
|
120
|
+
*
|
|
121
|
+
* @default process.cwd()
|
|
122
|
+
*/
|
|
123
|
+
cwd?: string
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Enable gitignore support.
|
|
127
|
+
*
|
|
128
|
+
* Passing an object to configure the options.
|
|
129
|
+
*
|
|
130
|
+
* @see https://github.com/antfu/eslint-config-flat-gitignore
|
|
131
|
+
* @default true
|
|
132
|
+
*/
|
|
133
|
+
gitignore?: boolean | FlatGitignoreOptions
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Core rules. Can't be disabled.
|
|
137
|
+
*/
|
|
138
|
+
javascript?: OptionsOverrides
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Enable TypeScript support.
|
|
142
|
+
*
|
|
143
|
+
* Passing an object to enable TypeScript Language Server support.
|
|
144
|
+
*
|
|
145
|
+
* @default auto-detect based on the dependencies
|
|
146
|
+
*/
|
|
147
|
+
typescript?: boolean | OptionsTypescript
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Enable test support.
|
|
151
|
+
*
|
|
152
|
+
* @default true
|
|
153
|
+
*/
|
|
154
|
+
test?: boolean | OptionsOverrides
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Enable Vue support.
|
|
158
|
+
*
|
|
159
|
+
* @default auto-detect based on the dependencies
|
|
160
|
+
*/
|
|
161
|
+
vue?: boolean | OptionsVue
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Enable JSONC support.
|
|
165
|
+
*
|
|
166
|
+
* @default true
|
|
167
|
+
*/
|
|
168
|
+
jsonc?: boolean | OptionsOverrides
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Enable react rules.
|
|
172
|
+
*
|
|
173
|
+
* Requires installing:
|
|
174
|
+
* - `eslint-plugin-react`
|
|
175
|
+
* - `eslint-plugin-react-hooks`
|
|
176
|
+
* - `eslint-plugin-react-refresh`
|
|
177
|
+
*
|
|
178
|
+
* @default false
|
|
179
|
+
*/
|
|
180
|
+
react?: boolean | OptionsOverrides
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Enable svelte rules.
|
|
184
|
+
*
|
|
185
|
+
* Requires installing:
|
|
186
|
+
* - `eslint-plugin-svelte`
|
|
187
|
+
*
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
svelte?: boolean | OptionsOverrides
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Enable unocss rules.
|
|
194
|
+
*
|
|
195
|
+
* Requires installing:
|
|
196
|
+
* - `@unocss/eslint-plugin`
|
|
197
|
+
*
|
|
198
|
+
* @default false
|
|
199
|
+
*/
|
|
200
|
+
unocss?: boolean | OptionsUnoCSS
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether to use prettierrc
|
|
204
|
+
*
|
|
205
|
+
* If true, the rules in prettierrc will override the default rules
|
|
206
|
+
*
|
|
207
|
+
* @default true
|
|
208
|
+
*/
|
|
209
|
+
usePrettierrc?: boolean
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Use external formatters to format files.
|
|
213
|
+
*
|
|
214
|
+
* Requires installing:
|
|
215
|
+
* - `eslint-plugin-prettier`
|
|
216
|
+
*
|
|
217
|
+
* @default
|
|
218
|
+
* {
|
|
219
|
+
* "html": true,
|
|
220
|
+
* "css": true,
|
|
221
|
+
* "graphql": true,
|
|
222
|
+
* "markdown": true
|
|
223
|
+
* "yaml": true
|
|
224
|
+
* "toml": true
|
|
225
|
+
* }
|
|
226
|
+
*/
|
|
227
|
+
formatter?: OptionsFormatters
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Default prettier rules
|
|
231
|
+
*
|
|
232
|
+
* @default
|
|
233
|
+
* ```json
|
|
234
|
+
* {
|
|
235
|
+
* "arrowParens": "avoid",
|
|
236
|
+
* "htmlWhitespaceSensitivity": "ignore"
|
|
237
|
+
* "printWidth": 120,
|
|
238
|
+
* "semi": false,
|
|
239
|
+
* "singleQuote": true,
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
prettierRules?: PartialPrettierExtendedOptions
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Control to disable some rules in editors.
|
|
247
|
+
* @default auto-detect based on the process.env
|
|
248
|
+
*/
|
|
249
|
+
isInEditor?: boolean
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Provide overrides for rules for each integration.
|
|
253
|
+
*
|
|
254
|
+
* @deprecated use `overrides` option in each integration key instead
|
|
255
|
+
*/
|
|
256
|
+
overrides?: {
|
|
257
|
+
javascript?: FlatConfigItem['rules']
|
|
258
|
+
typescript?: FlatConfigItem['rules']
|
|
259
|
+
test?: FlatConfigItem['rules']
|
|
260
|
+
vue?: FlatConfigItem['rules']
|
|
261
|
+
jsonc?: FlatConfigItem['rules']
|
|
262
|
+
react?: FlatConfigItem['rules']
|
|
263
|
+
svelte?: FlatConfigItem['rules']
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
118
267
|
|
|
119
268
|
## Thanks
|
|
120
269
|
|
package/dist/cli.cjs
CHANGED
|
@@ -46,21 +46,22 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
|
46
46
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
47
47
|
|
|
48
48
|
// package.json
|
|
49
|
-
var version = "2.0
|
|
49
|
+
var version = "2.1.0";
|
|
50
50
|
var devDependencies = {
|
|
51
51
|
"@antfu/ni": "^0.21.12",
|
|
52
|
-
"@types/eslint": "^8.56.
|
|
52
|
+
"@types/eslint": "^8.56.2",
|
|
53
53
|
"@types/fs-extra": "^11.0.4",
|
|
54
|
-
"@types/node": "^20.10.
|
|
54
|
+
"@types/node": "^20.10.8",
|
|
55
55
|
"@types/prompts": "^2.4.9",
|
|
56
56
|
"@types/yargs": "^17.0.32",
|
|
57
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
58
|
-
bumpp: "^9.
|
|
57
|
+
"@unocss/eslint-plugin": "^0.58.3",
|
|
58
|
+
bumpp: "^9.3.0",
|
|
59
59
|
eslint: "^8.56.0",
|
|
60
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
60
|
+
"eslint-flat-config-viewer": "^0.1.11",
|
|
61
61
|
"eslint-plugin-react": "^7.33.2",
|
|
62
62
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
63
63
|
"eslint-plugin-react-refresh": "^0.4.5",
|
|
64
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
64
65
|
esno: "^4.0.0",
|
|
65
66
|
execa: "^8.0.1",
|
|
66
67
|
"fast-glob": "^3.3.2",
|
|
@@ -68,6 +69,7 @@ var devDependencies = {
|
|
|
68
69
|
"lint-staged": "^15.2.0",
|
|
69
70
|
rimraf: "^5.0.5",
|
|
70
71
|
"simple-git-hooks": "^2.9.0",
|
|
72
|
+
"svelte-eslint-parser": "^0.33.1",
|
|
71
73
|
tsup: "^8.0.1",
|
|
72
74
|
typescript: "^5.3.3"
|
|
73
75
|
};
|
|
@@ -149,7 +151,7 @@ async function run(options = {}) {
|
|
|
149
151
|
console.log(import_picocolors2.default.cyan(`${ARROW} bumping @coderwyd/eslint-config to v${version}`));
|
|
150
152
|
const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf-8");
|
|
151
153
|
const pkg = JSON.parse(pkgContent);
|
|
152
|
-
pkg.devDependencies
|
|
154
|
+
pkg.devDependencies ??= {};
|
|
153
155
|
pkg.devDependencies["@coderwyd/eslint-config"] = `^${version}`;
|
|
154
156
|
if (!pkg.devDependencies.eslint)
|
|
155
157
|
pkg.devDependencies.eslint = eslintVersion;
|
|
@@ -224,7 +226,7 @@ ${coderwydConfig}
|
|
|
224
226
|
return;
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
|
-
if (
|
|
229
|
+
if (promptResult?.updateVscodeSettings ?? true) {
|
|
228
230
|
const dotVscodePath = import_node_path.default.join(cwd, ".vscode");
|
|
229
231
|
const settingsPath = import_node_path.default.join(dotVscodePath, "settings.json");
|
|
230
232
|
if (!import_node_fs.default.existsSync(dotVscodePath))
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/cli/index.ts
|
|
2
|
-
import process2 from "process";
|
|
2
|
+
import process2 from "node:process";
|
|
3
3
|
import c3 from "picocolors";
|
|
4
4
|
import { hideBin } from "yargs/helpers";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
|
|
7
7
|
// src/cli/run.ts
|
|
8
|
-
import fs from "fs";
|
|
9
|
-
import fsp from "fs/promises";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import process from "process";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import fsp from "node:fs/promises";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import process from "node:process";
|
|
12
12
|
import prompts from "prompts";
|
|
13
13
|
import c2 from "picocolors";
|
|
14
14
|
import parse from "parse-gitignore";
|
|
@@ -17,21 +17,22 @@ import parse from "parse-gitignore";
|
|
|
17
17
|
import c from "picocolors";
|
|
18
18
|
|
|
19
19
|
// package.json
|
|
20
|
-
var version = "2.0
|
|
20
|
+
var version = "2.1.0";
|
|
21
21
|
var devDependencies = {
|
|
22
22
|
"@antfu/ni": "^0.21.12",
|
|
23
|
-
"@types/eslint": "^8.56.
|
|
23
|
+
"@types/eslint": "^8.56.2",
|
|
24
24
|
"@types/fs-extra": "^11.0.4",
|
|
25
|
-
"@types/node": "^20.10.
|
|
25
|
+
"@types/node": "^20.10.8",
|
|
26
26
|
"@types/prompts": "^2.4.9",
|
|
27
27
|
"@types/yargs": "^17.0.32",
|
|
28
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
29
|
-
bumpp: "^9.
|
|
28
|
+
"@unocss/eslint-plugin": "^0.58.3",
|
|
29
|
+
bumpp: "^9.3.0",
|
|
30
30
|
eslint: "^8.56.0",
|
|
31
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
31
|
+
"eslint-flat-config-viewer": "^0.1.11",
|
|
32
32
|
"eslint-plugin-react": "^7.33.2",
|
|
33
33
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
34
34
|
"eslint-plugin-react-refresh": "^0.4.5",
|
|
35
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
35
36
|
esno: "^4.0.0",
|
|
36
37
|
execa: "^8.0.1",
|
|
37
38
|
"fast-glob": "^3.3.2",
|
|
@@ -39,6 +40,7 @@ var devDependencies = {
|
|
|
39
40
|
"lint-staged": "^15.2.0",
|
|
40
41
|
rimraf: "^5.0.5",
|
|
41
42
|
"simple-git-hooks": "^2.9.0",
|
|
43
|
+
"svelte-eslint-parser": "^0.33.1",
|
|
42
44
|
tsup: "^8.0.1",
|
|
43
45
|
typescript: "^5.3.3"
|
|
44
46
|
};
|
|
@@ -81,7 +83,7 @@ var vscodeSettingsString = `
|
|
|
81
83
|
`;
|
|
82
84
|
|
|
83
85
|
// src/cli/utils.ts
|
|
84
|
-
import { execSync } from "child_process";
|
|
86
|
+
import { execSync } from "node:child_process";
|
|
85
87
|
function isGitClean() {
|
|
86
88
|
try {
|
|
87
89
|
execSync("git diff-index --quiet HEAD --");
|
|
@@ -120,7 +122,7 @@ async function run(options = {}) {
|
|
|
120
122
|
console.log(c2.cyan(`${ARROW} bumping @coderwyd/eslint-config to v${version}`));
|
|
121
123
|
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
122
124
|
const pkg = JSON.parse(pkgContent);
|
|
123
|
-
pkg.devDependencies
|
|
125
|
+
pkg.devDependencies ??= {};
|
|
124
126
|
pkg.devDependencies["@coderwyd/eslint-config"] = `^${version}`;
|
|
125
127
|
if (!pkg.devDependencies.eslint)
|
|
126
128
|
pkg.devDependencies.eslint = eslintVersion;
|
|
@@ -195,7 +197,7 @@ ${coderwydConfig}
|
|
|
195
197
|
return;
|
|
196
198
|
}
|
|
197
199
|
}
|
|
198
|
-
if (
|
|
200
|
+
if (promptResult?.updateVscodeSettings ?? true) {
|
|
199
201
|
const dotVscodePath = path.join(cwd, ".vscode");
|
|
200
202
|
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
201
203
|
if (!fs.existsSync(dotVscodePath))
|
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var import_local_pkg3 = require("local-pkg");
|
|
|
41
41
|
var DEFAULT_PRETTIER_RULES = {
|
|
42
42
|
arrowParens: "avoid",
|
|
43
43
|
htmlWhitespaceSensitivity: "ignore",
|
|
44
|
-
printWidth:
|
|
44
|
+
printWidth: 120,
|
|
45
45
|
semi: false,
|
|
46
46
|
singleQuote: true
|
|
47
47
|
};
|
|
@@ -80,6 +80,7 @@ var GLOB_JSX = "**/*.?([cm])jsx";
|
|
|
80
80
|
var GLOB_TS = "**/*.?([cm])ts";
|
|
81
81
|
var GLOB_TSX = "**/*.?([cm])tsx";
|
|
82
82
|
var GLOB_VUE = "**/*.vue";
|
|
83
|
+
var GLOB_SVELTE = "**/*.svelte";
|
|
83
84
|
var GLOB_HTML = "**/*.htm?(l)";
|
|
84
85
|
var GLOB_CSS = "**/*.css";
|
|
85
86
|
var GLOB_POSTCSS = "**/*.{p,post}css";
|
|
@@ -530,11 +531,10 @@ function resolveSubOptions(options, key) {
|
|
|
530
531
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
531
532
|
}
|
|
532
533
|
function getOverrides(options, key) {
|
|
533
|
-
var _a;
|
|
534
534
|
const sub = resolveSubOptions(options, key);
|
|
535
535
|
return {
|
|
536
|
-
...
|
|
537
|
-
..."overrides" in sub ? sub.overrides : {}
|
|
536
|
+
...options.overrides?.[key],
|
|
537
|
+
..."overrides" in sub ? sub.overrides || {} : {}
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
540
|
|
|
@@ -544,7 +544,6 @@ async function jsdoc() {
|
|
|
544
544
|
{
|
|
545
545
|
name: "coderwyd:jsdoc",
|
|
546
546
|
plugins: {
|
|
547
|
-
// @ts-expect-error missing types
|
|
548
547
|
jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
|
|
549
548
|
},
|
|
550
549
|
rules: {
|
|
@@ -563,11 +562,6 @@ async function jsdoc() {
|
|
|
563
562
|
"jsdoc/require-returns-check": "warn",
|
|
564
563
|
"jsdoc/require-returns-description": "warn",
|
|
565
564
|
"jsdoc/require-yields-check": "warn"
|
|
566
|
-
// style
|
|
567
|
-
// ...{
|
|
568
|
-
// 'jsdoc/check-alignment': 'warn',
|
|
569
|
-
// 'jsdoc/multiline-blocks': 'warn',
|
|
570
|
-
// }
|
|
571
565
|
}
|
|
572
566
|
}
|
|
573
567
|
];
|
|
@@ -620,19 +614,6 @@ async function jsonc(options = {}) {
|
|
|
620
614
|
"jsonc/space-unary-ops": "error",
|
|
621
615
|
"jsonc/valid-json-number": "error",
|
|
622
616
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
623
|
-
// style
|
|
624
|
-
// ...{
|
|
625
|
-
// 'jsonc/array-bracket-spacing': ['error', 'never'],
|
|
626
|
-
// 'jsonc/comma-dangle': ['error', 'never'],
|
|
627
|
-
// 'jsonc/comma-style': ['error', 'last'],
|
|
628
|
-
// 'jsonc/indent': ['error', indent],
|
|
629
|
-
// 'jsonc/key-spacing': ['error', { afterColon: true, beforeColon: false }],
|
|
630
|
-
// 'jsonc/object-curly-newline': ['error', { consistent: true, multiline: true }],
|
|
631
|
-
// 'jsonc/object-curly-spacing': ['error', 'always'],
|
|
632
|
-
// 'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
|
|
633
|
-
// 'jsonc/quote-props': 'error',
|
|
634
|
-
// 'jsonc/quotes': 'error',
|
|
635
|
-
// },
|
|
636
617
|
...overrides
|
|
637
618
|
}
|
|
638
619
|
}
|
|
@@ -878,10 +859,14 @@ async function prettier(rules) {
|
|
|
878
859
|
};
|
|
879
860
|
const configs = [
|
|
880
861
|
{
|
|
881
|
-
|
|
862
|
+
name: "coderwyd:prettier:setup",
|
|
882
863
|
plugins: {
|
|
883
864
|
prettier: pluginPrettier
|
|
884
|
-
}
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
files: GLOB_PRETTIER_LINT,
|
|
869
|
+
name: "coderwyd:prettier:rules",
|
|
885
870
|
rules: {
|
|
886
871
|
...eslintRules,
|
|
887
872
|
"prettier/prettier": ["warn", pRules],
|
|
@@ -903,6 +888,8 @@ async function typescript(options = {}) {
|
|
|
903
888
|
...componentExts.map((ext) => `**/*.${ext}`)
|
|
904
889
|
];
|
|
905
890
|
const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
|
|
891
|
+
const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
|
|
892
|
+
const isTypeAware = !!tsconfigPath;
|
|
906
893
|
const typeAwareRules = {
|
|
907
894
|
"dot-notation": "off",
|
|
908
895
|
"no-implied-eval": "off",
|
|
@@ -924,34 +911,45 @@ async function typescript(options = {}) {
|
|
|
924
911
|
"ts/restrict-template-expressions": "error",
|
|
925
912
|
"ts/unbound-method": "error"
|
|
926
913
|
};
|
|
927
|
-
const tsconfigPath = (options == null ? void 0 : options.tsconfigPath) ? toArray(options.tsconfigPath) : void 0;
|
|
928
914
|
const [pluginTs, parserTs] = await Promise.all([
|
|
929
915
|
interopDefault(import("@typescript-eslint/eslint-plugin")),
|
|
930
916
|
interopDefault(import("@typescript-eslint/parser"))
|
|
931
917
|
]);
|
|
932
|
-
|
|
933
|
-
{
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
plugins: {
|
|
937
|
-
antfu: import_eslint_plugin_antfu.default,
|
|
938
|
-
ts: pluginTs
|
|
939
|
-
}
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
files,
|
|
918
|
+
function makeParser(typeAware, files2, ignores2) {
|
|
919
|
+
return {
|
|
920
|
+
files: files2,
|
|
921
|
+
...ignores2 ? { ignores: ignores2 } : {},
|
|
943
922
|
languageOptions: {
|
|
944
923
|
parser: parserTs,
|
|
945
924
|
parserOptions: {
|
|
946
925
|
extraFileExtensions: componentExts.map((ext) => `.${ext}`),
|
|
947
926
|
sourceType: "module",
|
|
948
|
-
...
|
|
927
|
+
...typeAware ? {
|
|
949
928
|
project: tsconfigPath,
|
|
950
929
|
tsconfigRootDir: import_node_process2.default.cwd()
|
|
951
930
|
} : {},
|
|
952
931
|
...parserOptions
|
|
953
932
|
}
|
|
954
933
|
},
|
|
934
|
+
name: `coderwyd:typescript:${typeAware ? "type-aware-parser" : "parser"}`
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
return [
|
|
938
|
+
{
|
|
939
|
+
// Install the plugins without globs, so they can be configured separately.
|
|
940
|
+
name: "coderwyd:typescript:setup",
|
|
941
|
+
plugins: {
|
|
942
|
+
antfu: import_eslint_plugin_antfu.default,
|
|
943
|
+
ts: pluginTs
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
// assign type-aware parser for type-aware files and type-unaware parser for the rest
|
|
947
|
+
...isTypeAware ? [
|
|
948
|
+
makeParser(true, filesTypeAware),
|
|
949
|
+
makeParser(false, files, filesTypeAware)
|
|
950
|
+
] : [makeParser(false, files)],
|
|
951
|
+
{
|
|
952
|
+
files,
|
|
955
953
|
name: "coderwyd:typescript:rules",
|
|
956
954
|
rules: {
|
|
957
955
|
...renameRules(
|
|
@@ -1081,11 +1079,11 @@ async function unicorn() {
|
|
|
1081
1079
|
// src/configs/vue.ts
|
|
1082
1080
|
async function vue(options = {}) {
|
|
1083
1081
|
const { files = [GLOB_VUE], overrides = {} } = options;
|
|
1084
|
-
const isVue3 = getVueVersion() === 3;
|
|
1085
1082
|
const [pluginVue, parserVue] = await Promise.all([
|
|
1086
1083
|
interopDefault(import("eslint-plugin-vue")),
|
|
1087
1084
|
interopDefault(import("vue-eslint-parser"))
|
|
1088
1085
|
]);
|
|
1086
|
+
const isVue3 = getVueVersion() === 3;
|
|
1089
1087
|
const configKeys = isVue3 ? ["vue3-essential", "vue3-strongly-recommended", "vue3-recommended"] : ["essential", "strongly-recommended", "recommended"];
|
|
1090
1088
|
const vueRules = configKeys.reduce((preRules, key) => {
|
|
1091
1089
|
const config = pluginVue.configs[key];
|
|
@@ -1376,7 +1374,7 @@ async function formatter(options = {}, prettierRules2 = {}) {
|
|
|
1376
1374
|
...prettierRules2,
|
|
1377
1375
|
parser
|
|
1378
1376
|
};
|
|
1379
|
-
if (plugins
|
|
1377
|
+
if (plugins?.length) {
|
|
1380
1378
|
rules.plugins = [...rules.plugins || [], ...plugins];
|
|
1381
1379
|
}
|
|
1382
1380
|
const config = {
|
|
@@ -1434,6 +1432,84 @@ async function formatter(options = {}, prettierRules2 = {}) {
|
|
|
1434
1432
|
return configs;
|
|
1435
1433
|
}
|
|
1436
1434
|
|
|
1435
|
+
// src/configs/svelte.ts
|
|
1436
|
+
async function svelte(options = {}) {
|
|
1437
|
+
const { files = [GLOB_SVELTE], overrides = {} } = options;
|
|
1438
|
+
await ensurePackages(["eslint-plugin-svelte"]);
|
|
1439
|
+
const [pluginSvelte, parserSvelte] = await Promise.all([
|
|
1440
|
+
interopDefault(import("eslint-plugin-svelte")),
|
|
1441
|
+
interopDefault(import("svelte-eslint-parser"))
|
|
1442
|
+
]);
|
|
1443
|
+
return [
|
|
1444
|
+
{
|
|
1445
|
+
name: "coderwyd:svelte:setup",
|
|
1446
|
+
plugins: {
|
|
1447
|
+
svelte: pluginSvelte
|
|
1448
|
+
}
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
files,
|
|
1452
|
+
languageOptions: {
|
|
1453
|
+
parser: parserSvelte,
|
|
1454
|
+
parserOptions: {
|
|
1455
|
+
extraFileExtensions: [".svelte"],
|
|
1456
|
+
parser: options.typescript ? await interopDefault(
|
|
1457
|
+
import("@typescript-eslint/parser")
|
|
1458
|
+
) : null
|
|
1459
|
+
}
|
|
1460
|
+
},
|
|
1461
|
+
name: "coderwyd:svelte:rules",
|
|
1462
|
+
processor: pluginSvelte.processors[".svelte"],
|
|
1463
|
+
rules: {
|
|
1464
|
+
"import/no-mutable-exports": "off",
|
|
1465
|
+
"no-undef": "off",
|
|
1466
|
+
// incompatible with most recent (attribute-form) generic types RFC
|
|
1467
|
+
"no-unused-vars": [
|
|
1468
|
+
"error",
|
|
1469
|
+
{
|
|
1470
|
+
args: "none",
|
|
1471
|
+
caughtErrors: "none",
|
|
1472
|
+
ignoreRestSiblings: true,
|
|
1473
|
+
vars: "all",
|
|
1474
|
+
varsIgnorePattern: "^\\$\\$Props$"
|
|
1475
|
+
}
|
|
1476
|
+
],
|
|
1477
|
+
"svelte/comment-directive": "error",
|
|
1478
|
+
"svelte/no-at-debug-tags": "warn",
|
|
1479
|
+
"svelte/no-at-html-tags": "error",
|
|
1480
|
+
"svelte/no-dupe-else-if-blocks": "error",
|
|
1481
|
+
"svelte/no-dupe-style-properties": "error",
|
|
1482
|
+
"svelte/no-dupe-use-directives": "error",
|
|
1483
|
+
"svelte/no-dynamic-slot-name": "error",
|
|
1484
|
+
"svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
|
|
1485
|
+
"svelte/no-inner-declarations": "error",
|
|
1486
|
+
"svelte/no-not-function-handler": "error",
|
|
1487
|
+
"svelte/no-object-in-text-mustaches": "error",
|
|
1488
|
+
"svelte/no-reactive-functions": "error",
|
|
1489
|
+
"svelte/no-reactive-literals": "error",
|
|
1490
|
+
"svelte/no-shorthand-style-property-overrides": "error",
|
|
1491
|
+
"svelte/no-unknown-style-directive-property": "error",
|
|
1492
|
+
"svelte/no-unused-svelte-ignore": "error",
|
|
1493
|
+
"svelte/no-useless-mustaches": "error",
|
|
1494
|
+
"svelte/require-store-callbacks-use-set-param": "error",
|
|
1495
|
+
"svelte/system": "error",
|
|
1496
|
+
"svelte/valid-compile": "error",
|
|
1497
|
+
"svelte/valid-each-key": "error",
|
|
1498
|
+
"unused-imports/no-unused-vars": [
|
|
1499
|
+
"error",
|
|
1500
|
+
{
|
|
1501
|
+
args: "after-used",
|
|
1502
|
+
argsIgnorePattern: "^_",
|
|
1503
|
+
vars: "all",
|
|
1504
|
+
varsIgnorePattern: "^(_|\\$\\$Props$)"
|
|
1505
|
+
}
|
|
1506
|
+
],
|
|
1507
|
+
...overrides
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
];
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1437
1513
|
// src/index.ts
|
|
1438
1514
|
var flatConfigProps = [
|
|
1439
1515
|
"files",
|
|
@@ -1452,6 +1528,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1452
1528
|
gitignore: enableGitignore = true,
|
|
1453
1529
|
isInEditor = !!((import_node_process3.default.env.VSCODE_PID || import_node_process3.default.env.JETBRAINS_IDE || import_node_process3.default.env.VIM) && !import_node_process3.default.env.CI),
|
|
1454
1530
|
react: enableReact = false,
|
|
1531
|
+
svelte: enableSvelte = false,
|
|
1455
1532
|
typescript: enableTypeScript = (0, import_local_pkg3.isPackageExists)("typescript"),
|
|
1456
1533
|
unocss: enableUnoCSS = false,
|
|
1457
1534
|
usePrettierrc = true,
|
|
@@ -1494,7 +1571,8 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1494
1571
|
configs.push(
|
|
1495
1572
|
typescript({
|
|
1496
1573
|
...resolveSubOptions(options, "typescript"),
|
|
1497
|
-
componentExts
|
|
1574
|
+
componentExts,
|
|
1575
|
+
overrides: getOverrides(options, "typescript")
|
|
1498
1576
|
})
|
|
1499
1577
|
);
|
|
1500
1578
|
}
|
|
@@ -1510,6 +1588,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1510
1588
|
configs.push(
|
|
1511
1589
|
vue({
|
|
1512
1590
|
...resolveSubOptions(options, "vue"),
|
|
1591
|
+
overrides: getOverrides(options, "typescript"),
|
|
1513
1592
|
typescript: !!enableTypeScript
|
|
1514
1593
|
})
|
|
1515
1594
|
);
|
|
@@ -1522,6 +1601,14 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1522
1601
|
})
|
|
1523
1602
|
);
|
|
1524
1603
|
}
|
|
1604
|
+
if (enableSvelte) {
|
|
1605
|
+
configs.push(
|
|
1606
|
+
svelte({
|
|
1607
|
+
overrides: getOverrides(options, "svelte"),
|
|
1608
|
+
typescript: !!enableTypeScript
|
|
1609
|
+
})
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1525
1612
|
if (enableUnoCSS) {
|
|
1526
1613
|
configs.push(
|
|
1527
1614
|
unocss({
|
package/dist/index.d.cts
CHANGED
|
@@ -38,22 +38,14 @@ type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (Opti
|
|
|
38
38
|
interface OptionsFormatters {
|
|
39
39
|
/**
|
|
40
40
|
* Enable formatting support for CSS, Less, Sass, and SCSS.
|
|
41
|
-
*
|
|
42
|
-
* Currently only support Prettier.
|
|
43
41
|
*/
|
|
44
42
|
css?: boolean;
|
|
45
43
|
/**
|
|
46
44
|
* Enable formatting support for HTML.
|
|
47
|
-
*
|
|
48
|
-
* Currently only support Prettier.
|
|
49
45
|
*/
|
|
50
46
|
html?: boolean;
|
|
51
47
|
/**
|
|
52
48
|
* Enable formatting support for Markdown.
|
|
53
|
-
*
|
|
54
|
-
* Support both Prettier.
|
|
55
|
-
*
|
|
56
|
-
* When set to `true`, it will use Prettier.
|
|
57
49
|
*/
|
|
58
50
|
markdown?: boolean;
|
|
59
51
|
/**
|
|
@@ -227,7 +219,7 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
227
219
|
* {
|
|
228
220
|
* "arrowParens": "avoid",
|
|
229
221
|
* "htmlWhitespaceSensitivity": "ignore"
|
|
230
|
-
* "printWidth":
|
|
222
|
+
* "printWidth": 120,
|
|
231
223
|
* "semi": false,
|
|
232
224
|
* "singleQuote": true,
|
|
233
225
|
* }
|
|
@@ -251,6 +243,7 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
251
243
|
vue?: FlatConfigItem['rules'];
|
|
252
244
|
jsonc?: FlatConfigItem['rules'];
|
|
253
245
|
react?: FlatConfigItem['rules'];
|
|
246
|
+
svelte?: FlatConfigItem['rules'];
|
|
254
247
|
};
|
|
255
248
|
}
|
|
256
249
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,22 +38,14 @@ type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (Opti
|
|
|
38
38
|
interface OptionsFormatters {
|
|
39
39
|
/**
|
|
40
40
|
* Enable formatting support for CSS, Less, Sass, and SCSS.
|
|
41
|
-
*
|
|
42
|
-
* Currently only support Prettier.
|
|
43
41
|
*/
|
|
44
42
|
css?: boolean;
|
|
45
43
|
/**
|
|
46
44
|
* Enable formatting support for HTML.
|
|
47
|
-
*
|
|
48
|
-
* Currently only support Prettier.
|
|
49
45
|
*/
|
|
50
46
|
html?: boolean;
|
|
51
47
|
/**
|
|
52
48
|
* Enable formatting support for Markdown.
|
|
53
|
-
*
|
|
54
|
-
* Support both Prettier.
|
|
55
|
-
*
|
|
56
|
-
* When set to `true`, it will use Prettier.
|
|
57
49
|
*/
|
|
58
50
|
markdown?: boolean;
|
|
59
51
|
/**
|
|
@@ -227,7 +219,7 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
227
219
|
* {
|
|
228
220
|
* "arrowParens": "avoid",
|
|
229
221
|
* "htmlWhitespaceSensitivity": "ignore"
|
|
230
|
-
* "printWidth":
|
|
222
|
+
* "printWidth": 120,
|
|
231
223
|
* "semi": false,
|
|
232
224
|
* "singleQuote": true,
|
|
233
225
|
* }
|
|
@@ -251,6 +243,7 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
251
243
|
vue?: FlatConfigItem['rules'];
|
|
252
244
|
jsonc?: FlatConfigItem['rules'];
|
|
253
245
|
react?: FlatConfigItem['rules'];
|
|
246
|
+
svelte?: FlatConfigItem['rules'];
|
|
254
247
|
};
|
|
255
248
|
}
|
|
256
249
|
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import process3 from "process";
|
|
3
|
-
import fs from "fs";
|
|
2
|
+
import process3 from "node:process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
4
|
import { isPackageExists as isPackageExists3 } from "local-pkg";
|
|
5
5
|
|
|
6
6
|
// src/constants/prettier.ts
|
|
7
7
|
var DEFAULT_PRETTIER_RULES = {
|
|
8
8
|
arrowParens: "avoid",
|
|
9
9
|
htmlWhitespaceSensitivity: "ignore",
|
|
10
|
-
printWidth:
|
|
10
|
+
printWidth: 120,
|
|
11
11
|
semi: false,
|
|
12
12
|
singleQuote: true
|
|
13
13
|
};
|
|
@@ -46,6 +46,7 @@ var GLOB_JSX = "**/*.?([cm])jsx";
|
|
|
46
46
|
var GLOB_TS = "**/*.?([cm])ts";
|
|
47
47
|
var GLOB_TSX = "**/*.?([cm])tsx";
|
|
48
48
|
var GLOB_VUE = "**/*.vue";
|
|
49
|
+
var GLOB_SVELTE = "**/*.svelte";
|
|
49
50
|
var GLOB_HTML = "**/*.htm?(l)";
|
|
50
51
|
var GLOB_CSS = "**/*.css";
|
|
51
52
|
var GLOB_POSTCSS = "**/*.{p,post}css";
|
|
@@ -412,9 +413,9 @@ async function javascript(options = {}) {
|
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
// src/shared/index.ts
|
|
415
|
-
import process from "process";
|
|
416
|
-
import { readFile } from "fs/promises";
|
|
417
|
-
import path from "path";
|
|
416
|
+
import process from "node:process";
|
|
417
|
+
import { readFile } from "node:fs/promises";
|
|
418
|
+
import path from "node:path";
|
|
418
419
|
import { getPackageInfoSync, isPackageExists } from "local-pkg";
|
|
419
420
|
var parserPlain = {
|
|
420
421
|
meta: {
|
|
@@ -496,11 +497,10 @@ function resolveSubOptions(options, key) {
|
|
|
496
497
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
497
498
|
}
|
|
498
499
|
function getOverrides(options, key) {
|
|
499
|
-
var _a;
|
|
500
500
|
const sub = resolveSubOptions(options, key);
|
|
501
501
|
return {
|
|
502
|
-
...
|
|
503
|
-
..."overrides" in sub ? sub.overrides : {}
|
|
502
|
+
...options.overrides?.[key],
|
|
503
|
+
..."overrides" in sub ? sub.overrides || {} : {}
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
|
|
@@ -510,7 +510,6 @@ async function jsdoc() {
|
|
|
510
510
|
{
|
|
511
511
|
name: "coderwyd:jsdoc",
|
|
512
512
|
plugins: {
|
|
513
|
-
// @ts-expect-error missing types
|
|
514
513
|
jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
|
|
515
514
|
},
|
|
516
515
|
rules: {
|
|
@@ -529,11 +528,6 @@ async function jsdoc() {
|
|
|
529
528
|
"jsdoc/require-returns-check": "warn",
|
|
530
529
|
"jsdoc/require-returns-description": "warn",
|
|
531
530
|
"jsdoc/require-yields-check": "warn"
|
|
532
|
-
// style
|
|
533
|
-
// ...{
|
|
534
|
-
// 'jsdoc/check-alignment': 'warn',
|
|
535
|
-
// 'jsdoc/multiline-blocks': 'warn',
|
|
536
|
-
// }
|
|
537
531
|
}
|
|
538
532
|
}
|
|
539
533
|
];
|
|
@@ -586,19 +580,6 @@ async function jsonc(options = {}) {
|
|
|
586
580
|
"jsonc/space-unary-ops": "error",
|
|
587
581
|
"jsonc/valid-json-number": "error",
|
|
588
582
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
589
|
-
// style
|
|
590
|
-
// ...{
|
|
591
|
-
// 'jsonc/array-bracket-spacing': ['error', 'never'],
|
|
592
|
-
// 'jsonc/comma-dangle': ['error', 'never'],
|
|
593
|
-
// 'jsonc/comma-style': ['error', 'last'],
|
|
594
|
-
// 'jsonc/indent': ['error', indent],
|
|
595
|
-
// 'jsonc/key-spacing': ['error', { afterColon: true, beforeColon: false }],
|
|
596
|
-
// 'jsonc/object-curly-newline': ['error', { consistent: true, multiline: true }],
|
|
597
|
-
// 'jsonc/object-curly-spacing': ['error', 'always'],
|
|
598
|
-
// 'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
|
|
599
|
-
// 'jsonc/quote-props': 'error',
|
|
600
|
-
// 'jsonc/quotes': 'error',
|
|
601
|
-
// },
|
|
602
583
|
...overrides
|
|
603
584
|
}
|
|
604
585
|
}
|
|
@@ -844,10 +825,14 @@ async function prettier(rules) {
|
|
|
844
825
|
};
|
|
845
826
|
const configs = [
|
|
846
827
|
{
|
|
847
|
-
|
|
828
|
+
name: "coderwyd:prettier:setup",
|
|
848
829
|
plugins: {
|
|
849
830
|
prettier: pluginPrettier
|
|
850
|
-
}
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
files: GLOB_PRETTIER_LINT,
|
|
835
|
+
name: "coderwyd:prettier:rules",
|
|
851
836
|
rules: {
|
|
852
837
|
...eslintRules,
|
|
853
838
|
"prettier/prettier": ["warn", pRules],
|
|
@@ -861,7 +846,7 @@ async function prettier(rules) {
|
|
|
861
846
|
}
|
|
862
847
|
|
|
863
848
|
// src/configs/typescript.ts
|
|
864
|
-
import process2 from "process";
|
|
849
|
+
import process2 from "node:process";
|
|
865
850
|
async function typescript(options = {}) {
|
|
866
851
|
const { componentExts = [], overrides = {}, parserOptions = {} } = options;
|
|
867
852
|
const files = options.files ?? [
|
|
@@ -869,6 +854,8 @@ async function typescript(options = {}) {
|
|
|
869
854
|
...componentExts.map((ext) => `**/*.${ext}`)
|
|
870
855
|
];
|
|
871
856
|
const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
|
|
857
|
+
const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
|
|
858
|
+
const isTypeAware = !!tsconfigPath;
|
|
872
859
|
const typeAwareRules = {
|
|
873
860
|
"dot-notation": "off",
|
|
874
861
|
"no-implied-eval": "off",
|
|
@@ -890,34 +877,45 @@ async function typescript(options = {}) {
|
|
|
890
877
|
"ts/restrict-template-expressions": "error",
|
|
891
878
|
"ts/unbound-method": "error"
|
|
892
879
|
};
|
|
893
|
-
const tsconfigPath = (options == null ? void 0 : options.tsconfigPath) ? toArray(options.tsconfigPath) : void 0;
|
|
894
880
|
const [pluginTs, parserTs] = await Promise.all([
|
|
895
881
|
interopDefault(import("@typescript-eslint/eslint-plugin")),
|
|
896
882
|
interopDefault(import("@typescript-eslint/parser"))
|
|
897
883
|
]);
|
|
898
|
-
|
|
899
|
-
{
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
plugins: {
|
|
903
|
-
antfu: default2,
|
|
904
|
-
ts: pluginTs
|
|
905
|
-
}
|
|
906
|
-
},
|
|
907
|
-
{
|
|
908
|
-
files,
|
|
884
|
+
function makeParser(typeAware, files2, ignores2) {
|
|
885
|
+
return {
|
|
886
|
+
files: files2,
|
|
887
|
+
...ignores2 ? { ignores: ignores2 } : {},
|
|
909
888
|
languageOptions: {
|
|
910
889
|
parser: parserTs,
|
|
911
890
|
parserOptions: {
|
|
912
891
|
extraFileExtensions: componentExts.map((ext) => `.${ext}`),
|
|
913
892
|
sourceType: "module",
|
|
914
|
-
...
|
|
893
|
+
...typeAware ? {
|
|
915
894
|
project: tsconfigPath,
|
|
916
895
|
tsconfigRootDir: process2.cwd()
|
|
917
896
|
} : {},
|
|
918
897
|
...parserOptions
|
|
919
898
|
}
|
|
920
899
|
},
|
|
900
|
+
name: `coderwyd:typescript:${typeAware ? "type-aware-parser" : "parser"}`
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
return [
|
|
904
|
+
{
|
|
905
|
+
// Install the plugins without globs, so they can be configured separately.
|
|
906
|
+
name: "coderwyd:typescript:setup",
|
|
907
|
+
plugins: {
|
|
908
|
+
antfu: default2,
|
|
909
|
+
ts: pluginTs
|
|
910
|
+
}
|
|
911
|
+
},
|
|
912
|
+
// assign type-aware parser for type-aware files and type-unaware parser for the rest
|
|
913
|
+
...isTypeAware ? [
|
|
914
|
+
makeParser(true, filesTypeAware),
|
|
915
|
+
makeParser(false, files, filesTypeAware)
|
|
916
|
+
] : [makeParser(false, files)],
|
|
917
|
+
{
|
|
918
|
+
files,
|
|
921
919
|
name: "coderwyd:typescript:rules",
|
|
922
920
|
rules: {
|
|
923
921
|
...renameRules(
|
|
@@ -1047,11 +1045,11 @@ async function unicorn() {
|
|
|
1047
1045
|
// src/configs/vue.ts
|
|
1048
1046
|
async function vue(options = {}) {
|
|
1049
1047
|
const { files = [GLOB_VUE], overrides = {} } = options;
|
|
1050
|
-
const isVue3 = getVueVersion() === 3;
|
|
1051
1048
|
const [pluginVue, parserVue] = await Promise.all([
|
|
1052
1049
|
interopDefault(import("eslint-plugin-vue")),
|
|
1053
1050
|
interopDefault(import("vue-eslint-parser"))
|
|
1054
1051
|
]);
|
|
1052
|
+
const isVue3 = getVueVersion() === 3;
|
|
1055
1053
|
const configKeys = isVue3 ? ["vue3-essential", "vue3-strongly-recommended", "vue3-recommended"] : ["essential", "strongly-recommended", "recommended"];
|
|
1056
1054
|
const vueRules = configKeys.reduce((preRules, key) => {
|
|
1057
1055
|
const config = pluginVue.configs[key];
|
|
@@ -1342,7 +1340,7 @@ async function formatter(options = {}, prettierRules2 = {}) {
|
|
|
1342
1340
|
...prettierRules2,
|
|
1343
1341
|
parser
|
|
1344
1342
|
};
|
|
1345
|
-
if (plugins
|
|
1343
|
+
if (plugins?.length) {
|
|
1346
1344
|
rules.plugins = [...rules.plugins || [], ...plugins];
|
|
1347
1345
|
}
|
|
1348
1346
|
const config = {
|
|
@@ -1400,6 +1398,84 @@ async function formatter(options = {}, prettierRules2 = {}) {
|
|
|
1400
1398
|
return configs;
|
|
1401
1399
|
}
|
|
1402
1400
|
|
|
1401
|
+
// src/configs/svelte.ts
|
|
1402
|
+
async function svelte(options = {}) {
|
|
1403
|
+
const { files = [GLOB_SVELTE], overrides = {} } = options;
|
|
1404
|
+
await ensurePackages(["eslint-plugin-svelte"]);
|
|
1405
|
+
const [pluginSvelte, parserSvelte] = await Promise.all([
|
|
1406
|
+
interopDefault(import("eslint-plugin-svelte")),
|
|
1407
|
+
interopDefault(import("svelte-eslint-parser"))
|
|
1408
|
+
]);
|
|
1409
|
+
return [
|
|
1410
|
+
{
|
|
1411
|
+
name: "coderwyd:svelte:setup",
|
|
1412
|
+
plugins: {
|
|
1413
|
+
svelte: pluginSvelte
|
|
1414
|
+
}
|
|
1415
|
+
},
|
|
1416
|
+
{
|
|
1417
|
+
files,
|
|
1418
|
+
languageOptions: {
|
|
1419
|
+
parser: parserSvelte,
|
|
1420
|
+
parserOptions: {
|
|
1421
|
+
extraFileExtensions: [".svelte"],
|
|
1422
|
+
parser: options.typescript ? await interopDefault(
|
|
1423
|
+
import("@typescript-eslint/parser")
|
|
1424
|
+
) : null
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
name: "coderwyd:svelte:rules",
|
|
1428
|
+
processor: pluginSvelte.processors[".svelte"],
|
|
1429
|
+
rules: {
|
|
1430
|
+
"import/no-mutable-exports": "off",
|
|
1431
|
+
"no-undef": "off",
|
|
1432
|
+
// incompatible with most recent (attribute-form) generic types RFC
|
|
1433
|
+
"no-unused-vars": [
|
|
1434
|
+
"error",
|
|
1435
|
+
{
|
|
1436
|
+
args: "none",
|
|
1437
|
+
caughtErrors: "none",
|
|
1438
|
+
ignoreRestSiblings: true,
|
|
1439
|
+
vars: "all",
|
|
1440
|
+
varsIgnorePattern: "^\\$\\$Props$"
|
|
1441
|
+
}
|
|
1442
|
+
],
|
|
1443
|
+
"svelte/comment-directive": "error",
|
|
1444
|
+
"svelte/no-at-debug-tags": "warn",
|
|
1445
|
+
"svelte/no-at-html-tags": "error",
|
|
1446
|
+
"svelte/no-dupe-else-if-blocks": "error",
|
|
1447
|
+
"svelte/no-dupe-style-properties": "error",
|
|
1448
|
+
"svelte/no-dupe-use-directives": "error",
|
|
1449
|
+
"svelte/no-dynamic-slot-name": "error",
|
|
1450
|
+
"svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
|
|
1451
|
+
"svelte/no-inner-declarations": "error",
|
|
1452
|
+
"svelte/no-not-function-handler": "error",
|
|
1453
|
+
"svelte/no-object-in-text-mustaches": "error",
|
|
1454
|
+
"svelte/no-reactive-functions": "error",
|
|
1455
|
+
"svelte/no-reactive-literals": "error",
|
|
1456
|
+
"svelte/no-shorthand-style-property-overrides": "error",
|
|
1457
|
+
"svelte/no-unknown-style-directive-property": "error",
|
|
1458
|
+
"svelte/no-unused-svelte-ignore": "error",
|
|
1459
|
+
"svelte/no-useless-mustaches": "error",
|
|
1460
|
+
"svelte/require-store-callbacks-use-set-param": "error",
|
|
1461
|
+
"svelte/system": "error",
|
|
1462
|
+
"svelte/valid-compile": "error",
|
|
1463
|
+
"svelte/valid-each-key": "error",
|
|
1464
|
+
"unused-imports/no-unused-vars": [
|
|
1465
|
+
"error",
|
|
1466
|
+
{
|
|
1467
|
+
args: "after-used",
|
|
1468
|
+
argsIgnorePattern: "^_",
|
|
1469
|
+
vars: "all",
|
|
1470
|
+
varsIgnorePattern: "^(_|\\$\\$Props$)"
|
|
1471
|
+
}
|
|
1472
|
+
],
|
|
1473
|
+
...overrides
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
];
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1403
1479
|
// src/index.ts
|
|
1404
1480
|
var flatConfigProps = [
|
|
1405
1481
|
"files",
|
|
@@ -1418,6 +1494,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1418
1494
|
gitignore: enableGitignore = true,
|
|
1419
1495
|
isInEditor = !!((process3.env.VSCODE_PID || process3.env.JETBRAINS_IDE || process3.env.VIM) && !process3.env.CI),
|
|
1420
1496
|
react: enableReact = false,
|
|
1497
|
+
svelte: enableSvelte = false,
|
|
1421
1498
|
typescript: enableTypeScript = isPackageExists3("typescript"),
|
|
1422
1499
|
unocss: enableUnoCSS = false,
|
|
1423
1500
|
usePrettierrc = true,
|
|
@@ -1460,7 +1537,8 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1460
1537
|
configs.push(
|
|
1461
1538
|
typescript({
|
|
1462
1539
|
...resolveSubOptions(options, "typescript"),
|
|
1463
|
-
componentExts
|
|
1540
|
+
componentExts,
|
|
1541
|
+
overrides: getOverrides(options, "typescript")
|
|
1464
1542
|
})
|
|
1465
1543
|
);
|
|
1466
1544
|
}
|
|
@@ -1476,6 +1554,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1476
1554
|
configs.push(
|
|
1477
1555
|
vue({
|
|
1478
1556
|
...resolveSubOptions(options, "vue"),
|
|
1557
|
+
overrides: getOverrides(options, "typescript"),
|
|
1479
1558
|
typescript: !!enableTypeScript
|
|
1480
1559
|
})
|
|
1481
1560
|
);
|
|
@@ -1488,6 +1567,14 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1488
1567
|
})
|
|
1489
1568
|
);
|
|
1490
1569
|
}
|
|
1570
|
+
if (enableSvelte) {
|
|
1571
|
+
configs.push(
|
|
1572
|
+
svelte({
|
|
1573
|
+
overrides: getOverrides(options, "svelte"),
|
|
1574
|
+
typescript: !!enableTypeScript
|
|
1575
|
+
})
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1491
1578
|
if (enableUnoCSS) {
|
|
1492
1579
|
configs.push(
|
|
1493
1580
|
unocss({
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderwyd/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
5
|
-
"packageManager": "pnpm@8.
|
|
4
|
+
"version": "2.1.0",
|
|
5
|
+
"packageManager": "pnpm@8.14.1",
|
|
6
6
|
"description": "Donny's ESLint config",
|
|
7
7
|
"author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"homepage": "https://github.com/coderwyd/eslint-config",
|
|
10
10
|
"keywords": [
|
|
11
|
-
"eslint
|
|
11
|
+
"eslint",
|
|
12
|
+
"eslint-config",
|
|
13
|
+
"eslint-config-vue",
|
|
14
|
+
"eslint-config-react",
|
|
15
|
+
"eslint-config-svelte",
|
|
16
|
+
"prettier"
|
|
12
17
|
],
|
|
13
18
|
"exports": {
|
|
14
19
|
".": {
|
|
@@ -36,7 +41,9 @@
|
|
|
36
41
|
"eslint": ">=8.40.0",
|
|
37
42
|
"eslint-plugin-react": "^7.33.2",
|
|
38
43
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
39
|
-
"eslint-plugin-react-refresh": "^0.4.4"
|
|
44
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
45
|
+
"eslint-plugin-svelte": "^2.34.1",
|
|
46
|
+
"svelte-eslint-parser": "^0.33.1"
|
|
40
47
|
},
|
|
41
48
|
"peerDependenciesMeta": {
|
|
42
49
|
"@unocss/eslint-plugin": {
|
|
@@ -50,57 +57,64 @@
|
|
|
50
57
|
},
|
|
51
58
|
"eslint-plugin-react-refresh": {
|
|
52
59
|
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"eslint-plugin-svelte": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"svelte-eslint-parser": {
|
|
65
|
+
"optional": true
|
|
53
66
|
}
|
|
54
67
|
},
|
|
55
68
|
"dependencies": {
|
|
56
69
|
"@antfu/eslint-define-config": "1.23.0-2",
|
|
57
70
|
"@antfu/install-pkg": "^0.3.1",
|
|
58
|
-
"@eslint-types/jsdoc": "
|
|
59
|
-
"@eslint-types/typescript-eslint": "^6.
|
|
71
|
+
"@eslint-types/jsdoc": "48.0.2",
|
|
72
|
+
"@eslint-types/typescript-eslint": "^6.18.1",
|
|
60
73
|
"@eslint-types/unicorn": "^50.0.1",
|
|
61
74
|
"@toml-tools/parser": "^1.0.0",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
63
|
-
"@typescript-eslint/parser": "^6.
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
76
|
+
"@typescript-eslint/parser": "^6.18.1",
|
|
64
77
|
"eslint-config-flat-gitignore": "^0.1.2",
|
|
65
78
|
"eslint-config-prettier": "^9.1.0",
|
|
66
79
|
"eslint-plugin-antfu": "^2.1.1",
|
|
67
80
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
68
81
|
"eslint-plugin-i": "^2.29.1",
|
|
69
|
-
"eslint-plugin-jsdoc": "^
|
|
70
|
-
"eslint-plugin-jsonc": "^2.
|
|
71
|
-
"eslint-plugin-n": "^16.6.
|
|
82
|
+
"eslint-plugin-jsdoc": "^48.0.2",
|
|
83
|
+
"eslint-plugin-jsonc": "^2.12.2",
|
|
84
|
+
"eslint-plugin-n": "^16.6.2",
|
|
72
85
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
73
86
|
"eslint-plugin-perfectionist": "^2.5.0",
|
|
74
|
-
"eslint-plugin-prettier": "^5.1.
|
|
87
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
75
88
|
"eslint-plugin-unicorn": "^50.0.1",
|
|
76
89
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
77
90
|
"eslint-plugin-vitest": "^0.3.20",
|
|
78
|
-
"eslint-plugin-vue": "^9.
|
|
91
|
+
"eslint-plugin-vue": "^9.20.1",
|
|
79
92
|
"globals": "^13.24.0",
|
|
80
93
|
"jsonc-eslint-parser": "^2.4.0",
|
|
81
94
|
"local-pkg": "^0.5.0",
|
|
82
95
|
"parse-gitignore": "^2.0.0",
|
|
83
96
|
"picocolors": "^1.0.0",
|
|
84
|
-
"prettier": "^3.
|
|
97
|
+
"prettier": "^3.2.4",
|
|
85
98
|
"prettier-plugin-toml": "^2.0.1",
|
|
86
99
|
"prompts": "^2.4.2",
|
|
87
|
-
"vue-eslint-parser": "^9.
|
|
100
|
+
"vue-eslint-parser": "^9.4.0",
|
|
88
101
|
"yargs": "^17.7.2"
|
|
89
102
|
},
|
|
90
103
|
"devDependencies": {
|
|
91
104
|
"@antfu/ni": "^0.21.12",
|
|
92
|
-
"@types/eslint": "^8.56.
|
|
105
|
+
"@types/eslint": "^8.56.2",
|
|
93
106
|
"@types/fs-extra": "^11.0.4",
|
|
94
|
-
"@types/node": "^20.10.
|
|
107
|
+
"@types/node": "^20.10.8",
|
|
95
108
|
"@types/prompts": "^2.4.9",
|
|
96
109
|
"@types/yargs": "^17.0.32",
|
|
97
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
98
|
-
"bumpp": "^9.
|
|
110
|
+
"@unocss/eslint-plugin": "^0.58.3",
|
|
111
|
+
"bumpp": "^9.3.0",
|
|
99
112
|
"eslint": "^8.56.0",
|
|
100
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
113
|
+
"eslint-flat-config-viewer": "^0.1.11",
|
|
101
114
|
"eslint-plugin-react": "^7.33.2",
|
|
102
115
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
103
116
|
"eslint-plugin-react-refresh": "^0.4.5",
|
|
117
|
+
"eslint-plugin-svelte": "^2.35.1",
|
|
104
118
|
"esno": "^4.0.0",
|
|
105
119
|
"execa": "^8.0.1",
|
|
106
120
|
"fast-glob": "^3.3.2",
|
|
@@ -108,6 +122,7 @@
|
|
|
108
122
|
"lint-staged": "^15.2.0",
|
|
109
123
|
"rimraf": "^5.0.5",
|
|
110
124
|
"simple-git-hooks": "^2.9.0",
|
|
125
|
+
"svelte-eslint-parser": "^0.33.1",
|
|
111
126
|
"tsup": "^8.0.1",
|
|
112
127
|
"typescript": "^5.3.3"
|
|
113
128
|
},
|