@coderwyd/eslint-config 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -230
- package/dist/cli.cjs +66 -56
- package/dist/cli.js +66 -56
- package/dist/index.cjs +440 -538
- package/dist/index.d.cts +127 -147
- package/dist/index.d.ts +127 -147
- package/dist/index.js +440 -490
- package/package.json +40 -41
package/dist/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/index.ts
|
|
2
2
|
import process3 from "process";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { isPackageExists as isPackageExists3 } from "local-pkg";
|
|
5
5
|
|
|
6
|
-
// src/
|
|
6
|
+
// src/constants/prettier.ts
|
|
7
|
+
var DEFAULT_PRETTIER_RULES = {
|
|
8
|
+
arrowParens: "avoid",
|
|
9
|
+
htmlWhitespaceSensitivity: "ignore",
|
|
10
|
+
printWidth: 80,
|
|
11
|
+
semi: false,
|
|
12
|
+
singleQuote: true
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/plugins/index.ts
|
|
7
16
|
import { default as default2 } from "eslint-plugin-antfu";
|
|
8
17
|
import { default as default3 } from "eslint-plugin-eslint-comments";
|
|
9
18
|
import * as pluginImport from "eslint-plugin-i";
|
|
@@ -30,24 +39,26 @@ async function comments() {
|
|
|
30
39
|
];
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
// src/
|
|
42
|
+
// src/constants/glob.ts
|
|
34
43
|
var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
35
44
|
var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
|
|
36
|
-
var GLOB_JS = "**/*.?([cm])js";
|
|
37
45
|
var GLOB_JSX = "**/*.?([cm])jsx";
|
|
38
46
|
var GLOB_TS = "**/*.?([cm])ts";
|
|
39
47
|
var GLOB_TSX = "**/*.?([cm])tsx";
|
|
40
|
-
var
|
|
48
|
+
var GLOB_VUE = "**/*.vue";
|
|
49
|
+
var GLOB_HTML = "**/*.htm?(l)";
|
|
41
50
|
var GLOB_CSS = "**/*.css";
|
|
51
|
+
var GLOB_POSTCSS = "**/*.{p,post}css";
|
|
42
52
|
var GLOB_LESS = "**/*.less";
|
|
43
53
|
var GLOB_SCSS = "**/*.scss";
|
|
44
54
|
var GLOB_JSON = "**/*.json";
|
|
45
55
|
var GLOB_JSON5 = "**/*.json5";
|
|
46
56
|
var GLOB_JSONC = "**/*.jsonc";
|
|
47
57
|
var GLOB_MARKDOWN = "**/*.md";
|
|
48
|
-
var GLOB_VUE = "**/*.vue";
|
|
49
58
|
var GLOB_YAML = "**/*.y?(a)ml";
|
|
50
|
-
var
|
|
59
|
+
var GLOB_TOML = "**/*.toml";
|
|
60
|
+
var GLOB_GRAPHQL = "**/*.graphql";
|
|
61
|
+
var GLOB_PRETTIER_LINT = [GLOB_SRC, GLOB_VUE];
|
|
51
62
|
var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
52
63
|
var GLOB_TESTS = [
|
|
53
64
|
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
|
|
@@ -56,16 +67,6 @@ var GLOB_TESTS = [
|
|
|
56
67
|
`**/*.bench.${GLOB_SRC_EXT}`,
|
|
57
68
|
`**/*.benchmark.${GLOB_SRC_EXT}`
|
|
58
69
|
];
|
|
59
|
-
var GLOB_ALL_SRC = [
|
|
60
|
-
GLOB_SRC,
|
|
61
|
-
GLOB_STYLE,
|
|
62
|
-
GLOB_JSON,
|
|
63
|
-
GLOB_JSON5,
|
|
64
|
-
GLOB_MARKDOWN,
|
|
65
|
-
GLOB_VUE,
|
|
66
|
-
GLOB_YAML,
|
|
67
|
-
GLOB_HTML
|
|
68
|
-
];
|
|
69
70
|
var GLOB_EXCLUDE = [
|
|
70
71
|
"**/node_modules",
|
|
71
72
|
"**/dist",
|
|
@@ -107,10 +108,7 @@ async function ignores() {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
// src/configs/imports.ts
|
|
110
|
-
async function imports(
|
|
111
|
-
const {
|
|
112
|
-
stylistic: stylistic2 = true
|
|
113
|
-
} = options;
|
|
111
|
+
async function imports() {
|
|
114
112
|
return [
|
|
115
113
|
{
|
|
116
114
|
name: "coderwyd:imports",
|
|
@@ -120,17 +118,61 @@ async function imports(options = {}) {
|
|
|
120
118
|
},
|
|
121
119
|
rules: {
|
|
122
120
|
"antfu/import-dedupe": "error",
|
|
121
|
+
"antfu/no-import-dist": "error",
|
|
123
122
|
"antfu/no-import-node-modules-by-path": "error",
|
|
124
123
|
"import/first": "error",
|
|
124
|
+
"import/newline-after-import": [
|
|
125
|
+
"error",
|
|
126
|
+
{ considerComments: true, count: 1 }
|
|
127
|
+
],
|
|
128
|
+
"import/no-default-export": "error",
|
|
125
129
|
"import/no-duplicates": "error",
|
|
126
130
|
"import/no-mutable-exports": "error",
|
|
127
131
|
"import/no-named-default": "error",
|
|
128
132
|
"import/no-self-import": "error",
|
|
129
133
|
"import/no-webpack-loader-syntax": "error",
|
|
130
|
-
"import/order":
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
"import/order": [
|
|
135
|
+
"error",
|
|
136
|
+
{
|
|
137
|
+
groups: [
|
|
138
|
+
"builtin",
|
|
139
|
+
"external",
|
|
140
|
+
"internal",
|
|
141
|
+
"parent",
|
|
142
|
+
"sibling",
|
|
143
|
+
"index",
|
|
144
|
+
"object",
|
|
145
|
+
"type"
|
|
146
|
+
],
|
|
147
|
+
pathGroups: [{ group: "internal", pattern: "{{@,~}/,#}**" }],
|
|
148
|
+
pathGroupsExcludedImportTypes: ["type"]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
files: [
|
|
155
|
+
`**/*config*.${GLOB_SRC_EXT}`,
|
|
156
|
+
`**/views/${GLOB_SRC}`,
|
|
157
|
+
`**/pages/${GLOB_SRC}`,
|
|
158
|
+
`**/{index,vite,esbuild,rollup,webpack,rspack}.ts`,
|
|
159
|
+
"**/*.d.ts",
|
|
160
|
+
`${GLOB_MARKDOWN}/**`,
|
|
161
|
+
"**/.prettierrc*"
|
|
162
|
+
],
|
|
163
|
+
plugins: {
|
|
164
|
+
import: pluginImport
|
|
165
|
+
},
|
|
166
|
+
rules: {
|
|
167
|
+
"import/no-default-export": "off"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
|
|
172
|
+
name: "antfu:imports:bin",
|
|
173
|
+
rules: {
|
|
174
|
+
"antfu/no-import-dist": "off",
|
|
175
|
+
"antfu/no-import-node-modules-by-path": "off"
|
|
134
176
|
}
|
|
135
177
|
}
|
|
136
178
|
];
|
|
@@ -139,10 +181,7 @@ async function imports(options = {}) {
|
|
|
139
181
|
// src/configs/javascript.ts
|
|
140
182
|
import globals from "globals";
|
|
141
183
|
async function javascript(options = {}) {
|
|
142
|
-
const {
|
|
143
|
-
isInEditor = false,
|
|
144
|
-
overrides = {}
|
|
145
|
-
} = options;
|
|
184
|
+
const { isInEditor = false, overrides = {} } = options;
|
|
146
185
|
return [
|
|
147
186
|
{
|
|
148
187
|
languageOptions: {
|
|
@@ -169,18 +208,23 @@ async function javascript(options = {}) {
|
|
|
169
208
|
},
|
|
170
209
|
name: "coderwyd:javascript",
|
|
171
210
|
plugins: {
|
|
172
|
-
"antfu": default2,
|
|
173
211
|
"unused-imports": default6
|
|
174
212
|
},
|
|
175
213
|
rules: {
|
|
176
|
-
"accessor-pairs": [
|
|
214
|
+
"accessor-pairs": [
|
|
215
|
+
"error",
|
|
216
|
+
{ enforceForClassMembers: true, setWithoutGet: true }
|
|
217
|
+
],
|
|
177
218
|
"array-callback-return": "error",
|
|
178
219
|
"block-scoped-var": "error",
|
|
179
220
|
"constructor-super": "error",
|
|
180
221
|
"default-case-last": "error",
|
|
181
222
|
"dot-notation": ["error", { allowKeywords: true }],
|
|
182
|
-
|
|
183
|
-
"new-cap": [
|
|
223
|
+
eqeqeq: ["error", "smart"],
|
|
224
|
+
"new-cap": [
|
|
225
|
+
"error",
|
|
226
|
+
{ capIsNew: false, newIsCap: true, properties: true }
|
|
227
|
+
],
|
|
184
228
|
"no-alert": "error",
|
|
185
229
|
"no-array-constructor": "error",
|
|
186
230
|
"no-async-promise-executor": "error",
|
|
@@ -238,11 +282,26 @@ async function javascript(options = {}) {
|
|
|
238
282
|
],
|
|
239
283
|
"no-restricted-properties": [
|
|
240
284
|
"error",
|
|
241
|
-
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{
|
|
285
|
+
{
|
|
286
|
+
message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
|
|
287
|
+
property: "__proto__"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
message: "Use `Object.defineProperty` instead.",
|
|
291
|
+
property: "__defineGetter__"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
message: "Use `Object.defineProperty` instead.",
|
|
295
|
+
property: "__defineSetter__"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
message: "Use `Object.getOwnPropertyDescriptor` instead.",
|
|
299
|
+
property: "__lookupGetter__"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
message: "Use `Object.getOwnPropertyDescriptor` instead.",
|
|
303
|
+
property: "__lookupSetter__"
|
|
304
|
+
}
|
|
246
305
|
],
|
|
247
306
|
"no-restricted-syntax": [
|
|
248
307
|
"error",
|
|
@@ -269,18 +328,27 @@ async function javascript(options = {}) {
|
|
|
269
328
|
"no-unreachable-loop": "error",
|
|
270
329
|
"no-unsafe-finally": "error",
|
|
271
330
|
"no-unsafe-negation": "error",
|
|
272
|
-
"no-unused-expressions": [
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
331
|
+
"no-unused-expressions": [
|
|
332
|
+
"error",
|
|
333
|
+
{
|
|
334
|
+
allowShortCircuit: true,
|
|
335
|
+
allowTaggedTemplates: true,
|
|
336
|
+
allowTernary: true
|
|
337
|
+
}
|
|
338
|
+
],
|
|
339
|
+
"no-unused-vars": [
|
|
340
|
+
"error",
|
|
341
|
+
{
|
|
342
|
+
args: "none",
|
|
343
|
+
caughtErrors: "none",
|
|
344
|
+
ignoreRestSiblings: true,
|
|
345
|
+
vars: "all"
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
"no-use-before-define": [
|
|
349
|
+
"error",
|
|
350
|
+
{ classes: false, functions: false, variables: true }
|
|
351
|
+
],
|
|
284
352
|
"no-useless-backreference": "error",
|
|
285
353
|
"no-useless-call": "error",
|
|
286
354
|
"no-useless-catch": "error",
|
|
@@ -334,12 +402,20 @@ async function javascript(options = {}) {
|
|
|
334
402
|
"unused-imports/no-unused-imports": isInEditor ? "off" : "error",
|
|
335
403
|
"unused-imports/no-unused-vars": [
|
|
336
404
|
"error",
|
|
337
|
-
{
|
|
405
|
+
{
|
|
406
|
+
args: "after-used",
|
|
407
|
+
argsIgnorePattern: "^_",
|
|
408
|
+
vars: "all",
|
|
409
|
+
varsIgnorePattern: "^_"
|
|
410
|
+
}
|
|
411
|
+
],
|
|
412
|
+
"use-isnan": [
|
|
413
|
+
"error",
|
|
414
|
+
{ enforceForIndexOf: true, enforceForSwitchCase: true }
|
|
338
415
|
],
|
|
339
|
-
"use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
|
|
340
416
|
"valid-typeof": ["error", { requireStringLiterals: true }],
|
|
341
417
|
"vars-on-top": "error",
|
|
342
|
-
|
|
418
|
+
yoda: ["error", "never"],
|
|
343
419
|
...overrides
|
|
344
420
|
}
|
|
345
421
|
},
|
|
@@ -353,9 +429,31 @@ async function javascript(options = {}) {
|
|
|
353
429
|
];
|
|
354
430
|
}
|
|
355
431
|
|
|
356
|
-
// src/
|
|
432
|
+
// src/shared/index.ts
|
|
357
433
|
import process from "process";
|
|
434
|
+
import { readFile } from "fs/promises";
|
|
435
|
+
import path from "path";
|
|
358
436
|
import { getPackageInfoSync, isPackageExists } from "local-pkg";
|
|
437
|
+
var parserPlain = {
|
|
438
|
+
meta: {
|
|
439
|
+
name: "parser-plain"
|
|
440
|
+
},
|
|
441
|
+
parseForESLint: (code) => ({
|
|
442
|
+
ast: {
|
|
443
|
+
body: [],
|
|
444
|
+
comments: [],
|
|
445
|
+
loc: { end: code.length, start: 0 },
|
|
446
|
+
range: [0, code.length],
|
|
447
|
+
tokens: [],
|
|
448
|
+
type: "Program"
|
|
449
|
+
},
|
|
450
|
+
scopeManager: null,
|
|
451
|
+
services: { isPlain: true },
|
|
452
|
+
visitorKeys: {
|
|
453
|
+
Program: []
|
|
454
|
+
}
|
|
455
|
+
})
|
|
456
|
+
};
|
|
359
457
|
async function combine(...configs) {
|
|
360
458
|
const resolved = await Promise.all(configs);
|
|
361
459
|
return resolved.flat();
|
|
@@ -391,20 +489,41 @@ async function ensurePackages(packages) {
|
|
|
391
489
|
const { default: prompts } = await import("prompts");
|
|
392
490
|
const { result } = await prompts([
|
|
393
491
|
{
|
|
394
|
-
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
|
|
492
|
+
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
|
|
493
|
+
", "
|
|
494
|
+
)}. Do you want to install them?`,
|
|
395
495
|
name: "result",
|
|
396
496
|
type: "confirm"
|
|
397
497
|
}
|
|
398
498
|
]);
|
|
399
499
|
if (result)
|
|
400
|
-
await import("@antfu/install-pkg").then(
|
|
500
|
+
await import("@antfu/install-pkg").then(
|
|
501
|
+
(i) => i.installPackage(nonExistingPackages, { dev: true })
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
async function loadPrettierConfig(cwd) {
|
|
505
|
+
let prettierConfig = {};
|
|
506
|
+
try {
|
|
507
|
+
const prettierrc = await readFile(path.join(cwd, ".prettierrc"), "utf-8");
|
|
508
|
+
prettierConfig = JSON.parse(prettierrc);
|
|
509
|
+
} catch {
|
|
510
|
+
}
|
|
511
|
+
return prettierConfig;
|
|
512
|
+
}
|
|
513
|
+
function resolveSubOptions(options, key) {
|
|
514
|
+
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
515
|
+
}
|
|
516
|
+
function getOverrides(options, key) {
|
|
517
|
+
var _a;
|
|
518
|
+
const sub = resolveSubOptions(options, key);
|
|
519
|
+
return {
|
|
520
|
+
...(_a = options.overrides) == null ? void 0 : _a[key],
|
|
521
|
+
..."overrides" in sub ? sub.overrides : {}
|
|
522
|
+
};
|
|
401
523
|
}
|
|
402
524
|
|
|
403
525
|
// src/configs/jsdoc.ts
|
|
404
|
-
async function jsdoc(
|
|
405
|
-
const {
|
|
406
|
-
stylistic: stylistic2 = true
|
|
407
|
-
} = options;
|
|
526
|
+
async function jsdoc() {
|
|
408
527
|
return [
|
|
409
528
|
{
|
|
410
529
|
name: "coderwyd:jsdoc",
|
|
@@ -427,11 +546,12 @@ async function jsdoc(options = {}) {
|
|
|
427
546
|
"jsdoc/require-property-name": "warn",
|
|
428
547
|
"jsdoc/require-returns-check": "warn",
|
|
429
548
|
"jsdoc/require-returns-description": "warn",
|
|
430
|
-
"jsdoc/require-yields-check": "warn"
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
549
|
+
"jsdoc/require-yields-check": "warn"
|
|
550
|
+
// style
|
|
551
|
+
// ...{
|
|
552
|
+
// 'jsdoc/check-alignment': 'warn',
|
|
553
|
+
// 'jsdoc/multiline-blocks': 'warn',
|
|
554
|
+
// }
|
|
435
555
|
}
|
|
436
556
|
}
|
|
437
557
|
];
|
|
@@ -439,18 +559,8 @@ async function jsdoc(options = {}) {
|
|
|
439
559
|
|
|
440
560
|
// src/configs/jsonc.ts
|
|
441
561
|
async function jsonc(options = {}) {
|
|
442
|
-
const {
|
|
443
|
-
|
|
444
|
-
overrides = {},
|
|
445
|
-
stylistic: stylistic2 = true
|
|
446
|
-
} = options;
|
|
447
|
-
const {
|
|
448
|
-
indent = 2
|
|
449
|
-
} = typeof stylistic2 === "boolean" ? {} : stylistic2;
|
|
450
|
-
const [
|
|
451
|
-
pluginJsonc,
|
|
452
|
-
parserJsonc
|
|
453
|
-
] = await Promise.all([
|
|
562
|
+
const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = options || {};
|
|
563
|
+
const [pluginJsonc, parserJsonc] = await Promise.all([
|
|
454
564
|
interopDefault(import("eslint-plugin-jsonc")),
|
|
455
565
|
interopDefault(import("jsonc-eslint-parser"))
|
|
456
566
|
]);
|
|
@@ -494,101 +604,19 @@ async function jsonc(options = {}) {
|
|
|
494
604
|
"jsonc/space-unary-ops": "error",
|
|
495
605
|
"jsonc/valid-json-number": "error",
|
|
496
606
|
"jsonc/vue-custom-block/no-parsing-error": "error",
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
];
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// src/configs/markdown.ts
|
|
516
|
-
async function markdown(options = {}) {
|
|
517
|
-
const {
|
|
518
|
-
componentExts = [],
|
|
519
|
-
files = [GLOB_MARKDOWN],
|
|
520
|
-
overrides = {}
|
|
521
|
-
} = options;
|
|
522
|
-
return [
|
|
523
|
-
{
|
|
524
|
-
name: "coderwyd:markdown:setup",
|
|
525
|
-
plugins: {
|
|
526
|
-
// @ts-expect-error missing types
|
|
527
|
-
markdown: await interopDefault(import("eslint-plugin-markdown"))
|
|
528
|
-
}
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
files,
|
|
532
|
-
name: "coderwyd:markdown:processor",
|
|
533
|
-
processor: "markdown/markdown"
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
files: [
|
|
537
|
-
GLOB_MARKDOWN_CODE,
|
|
538
|
-
...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`)
|
|
539
|
-
],
|
|
540
|
-
languageOptions: {
|
|
541
|
-
parserOptions: {
|
|
542
|
-
ecmaFeatures: {
|
|
543
|
-
impliedStrict: true
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
name: "coderwyd:markdown:rules",
|
|
548
|
-
rules: {
|
|
549
|
-
"antfu/no-ts-export-equal": "off",
|
|
550
|
-
"import/newline-after-import": "off",
|
|
551
|
-
"no-alert": "off",
|
|
552
|
-
"no-console": "off",
|
|
553
|
-
"no-labels": "off",
|
|
554
|
-
"no-lone-blocks": "off",
|
|
555
|
-
"no-restricted-syntax": "off",
|
|
556
|
-
"no-undef": "off",
|
|
557
|
-
"no-unused-expressions": "off",
|
|
558
|
-
"no-unused-labels": "off",
|
|
559
|
-
"no-unused-vars": "off",
|
|
560
|
-
"node/prefer-global/process": "off",
|
|
561
|
-
"style/comma-dangle": "off",
|
|
562
|
-
"style/eol-last": "off",
|
|
563
|
-
"ts/consistent-type-imports": "off",
|
|
564
|
-
"ts/no-namespace": "off",
|
|
565
|
-
"ts/no-redeclare": "off",
|
|
566
|
-
"ts/no-require-imports": "off",
|
|
567
|
-
"ts/no-unused-vars": "off",
|
|
568
|
-
"ts/no-use-before-define": "off",
|
|
569
|
-
"ts/no-var-requires": "off",
|
|
570
|
-
"unicode-bom": "off",
|
|
571
|
-
"unused-imports/no-unused-imports": "off",
|
|
572
|
-
"unused-imports/no-unused-vars": "off",
|
|
573
|
-
// Type aware rules
|
|
574
|
-
...{
|
|
575
|
-
"ts/await-thenable": "off",
|
|
576
|
-
"ts/dot-notation": "off",
|
|
577
|
-
"ts/no-floating-promises": "off",
|
|
578
|
-
"ts/no-for-in-array": "off",
|
|
579
|
-
"ts/no-implied-eval": "off",
|
|
580
|
-
"ts/no-misused-promises": "off",
|
|
581
|
-
"ts/no-throw-literal": "off",
|
|
582
|
-
"ts/no-unnecessary-type-assertion": "off",
|
|
583
|
-
"ts/no-unsafe-argument": "off",
|
|
584
|
-
"ts/no-unsafe-assignment": "off",
|
|
585
|
-
"ts/no-unsafe-call": "off",
|
|
586
|
-
"ts/no-unsafe-member-access": "off",
|
|
587
|
-
"ts/no-unsafe-return": "off",
|
|
588
|
-
"ts/restrict-plus-operands": "off",
|
|
589
|
-
"ts/restrict-template-expressions": "off",
|
|
590
|
-
"ts/unbound-method": "off"
|
|
591
|
-
},
|
|
607
|
+
// style
|
|
608
|
+
// ...{
|
|
609
|
+
// 'jsonc/array-bracket-spacing': ['error', 'never'],
|
|
610
|
+
// 'jsonc/comma-dangle': ['error', 'never'],
|
|
611
|
+
// 'jsonc/comma-style': ['error', 'last'],
|
|
612
|
+
// 'jsonc/indent': ['error', indent],
|
|
613
|
+
// 'jsonc/key-spacing': ['error', { afterColon: true, beforeColon: false }],
|
|
614
|
+
// 'jsonc/object-curly-newline': ['error', { consistent: true, multiline: true }],
|
|
615
|
+
// 'jsonc/object-curly-spacing': ['error', 'always'],
|
|
616
|
+
// 'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
|
|
617
|
+
// 'jsonc/quote-props': 'error',
|
|
618
|
+
// 'jsonc/quotes': 'error',
|
|
619
|
+
// },
|
|
592
620
|
...overrides
|
|
593
621
|
}
|
|
594
622
|
}
|
|
@@ -683,23 +711,14 @@ async function sortPackageJson() {
|
|
|
683
711
|
},
|
|
684
712
|
{
|
|
685
713
|
order: { type: "asc" },
|
|
686
|
-
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies
|
|
714
|
+
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
|
|
687
715
|
},
|
|
688
716
|
{
|
|
689
717
|
order: { type: "asc" },
|
|
690
|
-
pathPattern: "^resolutions$"
|
|
718
|
+
pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
|
|
691
719
|
},
|
|
692
720
|
{
|
|
693
|
-
order:
|
|
694
|
-
pathPattern: "^pnpm.overrides$"
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
order: [
|
|
698
|
-
"types",
|
|
699
|
-
"import",
|
|
700
|
-
"require",
|
|
701
|
-
"default"
|
|
702
|
-
],
|
|
721
|
+
order: ["types", "import", "require", "default"],
|
|
703
722
|
pathPattern: "^exports.*$"
|
|
704
723
|
}
|
|
705
724
|
]
|
|
@@ -833,54 +852,40 @@ function sortTsconfig() {
|
|
|
833
852
|
];
|
|
834
853
|
}
|
|
835
854
|
|
|
836
|
-
// src/configs/
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
}
|
|
844
|
-
const
|
|
845
|
-
const config = pluginStylistic.configs.customize({
|
|
846
|
-
flat: true,
|
|
847
|
-
indent,
|
|
848
|
-
jsx,
|
|
849
|
-
pluginName: "style",
|
|
850
|
-
quotes,
|
|
851
|
-
semi
|
|
852
|
-
});
|
|
853
|
-
return [
|
|
855
|
+
// src/configs/prettier.ts
|
|
856
|
+
import prettierRules from "eslint-config-prettier";
|
|
857
|
+
var { rules: eslintRules } = prettierRules;
|
|
858
|
+
async function prettier(rules) {
|
|
859
|
+
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
860
|
+
const pRules = {
|
|
861
|
+
...rules
|
|
862
|
+
};
|
|
863
|
+
const configs = [
|
|
854
864
|
{
|
|
855
|
-
|
|
865
|
+
files: GLOB_PRETTIER_LINT,
|
|
856
866
|
plugins: {
|
|
857
|
-
|
|
858
|
-
style: pluginStylistic
|
|
867
|
+
prettier: pluginPrettier
|
|
859
868
|
},
|
|
860
869
|
rules: {
|
|
861
|
-
...
|
|
862
|
-
"
|
|
863
|
-
"
|
|
864
|
-
"
|
|
865
|
-
"antfu/top-level-function": "error",
|
|
866
|
-
"curly": ["error", "multi-or-nest", "consistent"]
|
|
870
|
+
...eslintRules,
|
|
871
|
+
"arrow-body-style": "off",
|
|
872
|
+
"prefer-arrow-callback": "off",
|
|
873
|
+
"prettier/prettier": ["warn", pRules]
|
|
867
874
|
}
|
|
868
875
|
}
|
|
869
876
|
];
|
|
877
|
+
return configs;
|
|
870
878
|
}
|
|
871
879
|
|
|
872
880
|
// src/configs/typescript.ts
|
|
873
881
|
import process2 from "process";
|
|
874
882
|
async function typescript(options = {}) {
|
|
875
|
-
const {
|
|
876
|
-
componentExts = [],
|
|
877
|
-
overrides = {},
|
|
878
|
-
parserOptions = {}
|
|
879
|
-
} = options;
|
|
883
|
+
const { componentExts = [], overrides = {}, parserOptions = {} } = options;
|
|
880
884
|
const files = options.files ?? [
|
|
881
885
|
GLOB_SRC,
|
|
882
886
|
...componentExts.map((ext) => `**/*.${ext}`)
|
|
883
887
|
];
|
|
888
|
+
const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
|
|
884
889
|
const typeAwareRules = {
|
|
885
890
|
"dot-notation": "off",
|
|
886
891
|
"no-implied-eval": "off",
|
|
@@ -902,11 +907,8 @@ async function typescript(options = {}) {
|
|
|
902
907
|
"ts/restrict-template-expressions": "error",
|
|
903
908
|
"ts/unbound-method": "error"
|
|
904
909
|
};
|
|
905
|
-
const tsconfigPath = options
|
|
906
|
-
const [
|
|
907
|
-
pluginTs,
|
|
908
|
-
parserTs
|
|
909
|
-
] = await Promise.all([
|
|
910
|
+
const tsconfigPath = (options == null ? void 0 : options.tsconfigPath) ? toArray(options.tsconfigPath) : void 0;
|
|
911
|
+
const [pluginTs, parserTs] = await Promise.all([
|
|
910
912
|
interopDefault(import("@typescript-eslint/eslint-plugin")),
|
|
911
913
|
interopDefault(import("@typescript-eslint/parser"))
|
|
912
914
|
]);
|
|
@@ -945,17 +947,21 @@ async function typescript(options = {}) {
|
|
|
945
947
|
"@typescript-eslint/",
|
|
946
948
|
"ts/"
|
|
947
949
|
),
|
|
948
|
-
"antfu/generic-spacing": "error",
|
|
949
|
-
"antfu/named-tuple-spacing": "error",
|
|
950
950
|
"no-dupe-class-members": "off",
|
|
951
951
|
"no-loss-of-precision": "off",
|
|
952
952
|
"no-redeclare": "off",
|
|
953
953
|
"no-use-before-define": "off",
|
|
954
954
|
"no-useless-constructor": "off",
|
|
955
|
-
"ts/ban-ts-comment": [
|
|
955
|
+
"ts/ban-ts-comment": [
|
|
956
|
+
"error",
|
|
957
|
+
{ "ts-ignore": "allow-with-description" }
|
|
958
|
+
],
|
|
956
959
|
"ts/ban-types": ["error", { types: { Function: false } }],
|
|
957
960
|
"ts/consistent-type-definitions": ["error", "interface"],
|
|
958
|
-
"ts/consistent-type-imports": [
|
|
961
|
+
"ts/consistent-type-imports": [
|
|
962
|
+
"error",
|
|
963
|
+
{ disallowTypeAnnotations: false, prefer: "type-imports" }
|
|
964
|
+
],
|
|
959
965
|
"ts/no-dupe-class-members": "error",
|
|
960
966
|
"ts/no-dynamic-delete": "off",
|
|
961
967
|
"ts/no-explicit-any": "off",
|
|
@@ -967,11 +973,21 @@ async function typescript(options = {}) {
|
|
|
967
973
|
"ts/no-redeclare": "error",
|
|
968
974
|
"ts/no-require-imports": "error",
|
|
969
975
|
"ts/no-unused-vars": "off",
|
|
970
|
-
"ts/no-use-before-define": [
|
|
976
|
+
"ts/no-use-before-define": [
|
|
977
|
+
"error",
|
|
978
|
+
{ classes: false, functions: false, variables: true }
|
|
979
|
+
],
|
|
971
980
|
"ts/no-useless-constructor": "off",
|
|
972
981
|
"ts/prefer-ts-expect-error": "error",
|
|
973
982
|
"ts/triple-slash-reference": "off",
|
|
974
983
|
"ts/unified-signatures": "off",
|
|
984
|
+
...overrides
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
files: filesTypeAware,
|
|
989
|
+
name: "coderwyd:typescript:rules-type-aware",
|
|
990
|
+
rules: {
|
|
975
991
|
...tsconfigPath ? typeAwareRules : {},
|
|
976
992
|
...overrides
|
|
977
993
|
}
|
|
@@ -1047,35 +1063,20 @@ async function unicorn() {
|
|
|
1047
1063
|
|
|
1048
1064
|
// src/configs/vue.ts
|
|
1049
1065
|
async function vue(options = {}) {
|
|
1050
|
-
const {
|
|
1051
|
-
files = [GLOB_VUE],
|
|
1052
|
-
overrides = {},
|
|
1053
|
-
stylistic: stylistic2 = true
|
|
1054
|
-
} = options;
|
|
1055
|
-
const {
|
|
1056
|
-
indent = 2
|
|
1057
|
-
} = typeof stylistic2 === "boolean" ? {} : stylistic2;
|
|
1066
|
+
const { files = [GLOB_VUE], overrides = {} } = options;
|
|
1058
1067
|
const isVue3 = getVueVersion() === 3;
|
|
1059
|
-
const [
|
|
1060
|
-
pluginVue,
|
|
1061
|
-
parserVue
|
|
1062
|
-
] = await Promise.all([
|
|
1063
|
-
// @ts-expect-error missing types
|
|
1068
|
+
const [pluginVue, parserVue] = await Promise.all([
|
|
1064
1069
|
interopDefault(import("eslint-plugin-vue")),
|
|
1065
1070
|
interopDefault(import("vue-eslint-parser"))
|
|
1066
1071
|
]);
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
...pluginVue.configs.essential.rules,
|
|
1076
|
-
...pluginVue.configs["strongly-recommended"].rules,
|
|
1077
|
-
...pluginVue.configs.recommended.rules
|
|
1078
|
-
};
|
|
1072
|
+
const configKeys = isVue3 ? ["vue3-essential", "vue3-strongly-recommended", "vue3-recommended"] : ["essential", "strongly-recommended", "recommended"];
|
|
1073
|
+
const vueRules = configKeys.reduce((preRules, key) => {
|
|
1074
|
+
const config = pluginVue.configs[key];
|
|
1075
|
+
return {
|
|
1076
|
+
...preRules,
|
|
1077
|
+
...config.rules
|
|
1078
|
+
};
|
|
1079
|
+
}, {});
|
|
1079
1080
|
return [
|
|
1080
1081
|
{
|
|
1081
1082
|
name: "coderwyd:vue:setup",
|
|
@@ -1092,28 +1093,42 @@ async function vue(options = {}) {
|
|
|
1092
1093
|
jsx: true
|
|
1093
1094
|
},
|
|
1094
1095
|
extraFileExtensions: [".vue"],
|
|
1095
|
-
parser: options.typescript ? await interopDefault(
|
|
1096
|
+
parser: options.typescript ? await interopDefault(
|
|
1097
|
+
import("@typescript-eslint/parser")
|
|
1098
|
+
) : null,
|
|
1096
1099
|
sourceType: "module"
|
|
1097
1100
|
}
|
|
1098
1101
|
},
|
|
1099
1102
|
name: "coderwyd:vue:rules",
|
|
1100
1103
|
processor: pluginVue.processors[".vue"],
|
|
1101
1104
|
rules: {
|
|
1102
|
-
...
|
|
1105
|
+
...pluginVue.configs.base.rules,
|
|
1106
|
+
...vueRules,
|
|
1103
1107
|
"node/prefer-global/process": "off",
|
|
1104
|
-
"vue/block-order": [
|
|
1105
|
-
|
|
1106
|
-
|
|
1108
|
+
"vue/block-order": [
|
|
1109
|
+
"error",
|
|
1110
|
+
{
|
|
1111
|
+
order: ["script", "template", "style"]
|
|
1112
|
+
}
|
|
1113
|
+
],
|
|
1107
1114
|
"vue/component-name-in-template-casing": ["error", "PascalCase"],
|
|
1108
1115
|
"vue/component-options-name-casing": ["error", "PascalCase"],
|
|
1109
1116
|
"vue/custom-event-name-casing": ["error", "camelCase"],
|
|
1110
|
-
"vue/define-macros-order": [
|
|
1111
|
-
|
|
1112
|
-
|
|
1117
|
+
"vue/define-macros-order": [
|
|
1118
|
+
"error",
|
|
1119
|
+
{
|
|
1120
|
+
order: [
|
|
1121
|
+
"defineOptions",
|
|
1122
|
+
"defineProps",
|
|
1123
|
+
"defineEmits",
|
|
1124
|
+
"defineSlots"
|
|
1125
|
+
]
|
|
1126
|
+
}
|
|
1127
|
+
],
|
|
1113
1128
|
"vue/dot-location": ["error", "property"],
|
|
1114
1129
|
"vue/dot-notation": ["error", { allowKeywords: true }],
|
|
1115
1130
|
"vue/eqeqeq": ["error", "smart"],
|
|
1116
|
-
"vue/html-indent": ["error",
|
|
1131
|
+
"vue/html-indent": ["error", 2],
|
|
1117
1132
|
"vue/html-quotes": ["error", "double"],
|
|
1118
1133
|
"vue/max-attributes-per-line": "off",
|
|
1119
1134
|
"vue/multi-word-component-names": "off",
|
|
@@ -1149,91 +1164,7 @@ async function vue(options = {}) {
|
|
|
1149
1164
|
"vue/require-prop-types": "off",
|
|
1150
1165
|
"vue/space-infix-ops": "error",
|
|
1151
1166
|
"vue/space-unary-ops": ["error", { nonwords: false, words: true }],
|
|
1152
|
-
|
|
1153
|
-
"vue/array-bracket-spacing": ["error", "never"],
|
|
1154
|
-
"vue/arrow-spacing": ["error", { after: true, before: true }],
|
|
1155
|
-
"vue/block-spacing": ["error", "always"],
|
|
1156
|
-
"vue/block-tag-newline": ["error", {
|
|
1157
|
-
multiline: "always",
|
|
1158
|
-
singleline: "always"
|
|
1159
|
-
}],
|
|
1160
|
-
"vue/brace-style": ["error", "stroustrup", { allowSingleLine: true }],
|
|
1161
|
-
"vue/comma-dangle": ["error", "always-multiline"],
|
|
1162
|
-
"vue/comma-spacing": ["error", { after: true, before: false }],
|
|
1163
|
-
"vue/comma-style": ["error", "last"],
|
|
1164
|
-
"vue/html-comment-content-spacing": ["error", "always", {
|
|
1165
|
-
exceptions: ["-"]
|
|
1166
|
-
}],
|
|
1167
|
-
"vue/key-spacing": ["error", { afterColon: true, beforeColon: false }],
|
|
1168
|
-
"vue/keyword-spacing": ["error", { after: true, before: true }],
|
|
1169
|
-
"vue/object-curly-newline": "off",
|
|
1170
|
-
"vue/object-curly-spacing": ["error", "always"],
|
|
1171
|
-
"vue/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
|
|
1172
|
-
"vue/operator-linebreak": ["error", "before"],
|
|
1173
|
-
"vue/padding-line-between-blocks": ["error", "always"],
|
|
1174
|
-
"vue/quote-props": ["error", "consistent-as-needed"],
|
|
1175
|
-
"vue/space-in-parens": ["error", "never"],
|
|
1176
|
-
"vue/template-curly-spacing": "error"
|
|
1177
|
-
} : {},
|
|
1178
|
-
...overrides
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
];
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
// src/configs/yaml.ts
|
|
1185
|
-
async function yaml(options = {}) {
|
|
1186
|
-
const {
|
|
1187
|
-
files = [GLOB_YAML],
|
|
1188
|
-
overrides = {},
|
|
1189
|
-
stylistic: stylistic2 = true
|
|
1190
|
-
} = options;
|
|
1191
|
-
const {
|
|
1192
|
-
indent = 2,
|
|
1193
|
-
quotes = "single"
|
|
1194
|
-
} = typeof stylistic2 === "boolean" ? {} : stylistic2;
|
|
1195
|
-
const [
|
|
1196
|
-
pluginYaml,
|
|
1197
|
-
parserYaml
|
|
1198
|
-
] = await Promise.all([
|
|
1199
|
-
interopDefault(import("eslint-plugin-yml")),
|
|
1200
|
-
interopDefault(import("yaml-eslint-parser"))
|
|
1201
|
-
]);
|
|
1202
|
-
return [
|
|
1203
|
-
{
|
|
1204
|
-
name: "coderwyd:yaml:setup",
|
|
1205
|
-
plugins: {
|
|
1206
|
-
yaml: pluginYaml
|
|
1207
|
-
}
|
|
1208
|
-
},
|
|
1209
|
-
{
|
|
1210
|
-
files,
|
|
1211
|
-
languageOptions: {
|
|
1212
|
-
parser: parserYaml
|
|
1213
|
-
},
|
|
1214
|
-
name: "coderwyd:yaml:rules",
|
|
1215
|
-
rules: {
|
|
1216
|
-
"style/spaced-comment": "off",
|
|
1217
|
-
"yaml/block-mapping": "error",
|
|
1218
|
-
"yaml/block-sequence": "error",
|
|
1219
|
-
"yaml/no-empty-key": "error",
|
|
1220
|
-
"yaml/no-empty-sequence-entry": "error",
|
|
1221
|
-
"yaml/no-irregular-whitespace": "error",
|
|
1222
|
-
"yaml/plain-scalar": "error",
|
|
1223
|
-
"yaml/vue-custom-block/no-parsing-error": "error",
|
|
1224
|
-
...stylistic2 ? {
|
|
1225
|
-
"yaml/block-mapping-question-indicator-newline": "error",
|
|
1226
|
-
"yaml/block-sequence-hyphen-indicator-newline": "error",
|
|
1227
|
-
"yaml/flow-mapping-curly-newline": "error",
|
|
1228
|
-
"yaml/flow-mapping-curly-spacing": "error",
|
|
1229
|
-
"yaml/flow-sequence-bracket-newline": "error",
|
|
1230
|
-
"yaml/flow-sequence-bracket-spacing": "error",
|
|
1231
|
-
"yaml/indent": ["error", indent === "tab" ? 2 : indent],
|
|
1232
|
-
"yaml/key-spacing": "error",
|
|
1233
|
-
"yaml/no-tab-indent": "error",
|
|
1234
|
-
"yaml/quotes": ["error", { avoidEscape: false, prefer: quotes }],
|
|
1235
|
-
"yaml/spaced-comment": "error"
|
|
1236
|
-
} : {},
|
|
1167
|
+
"vue/valid-define-options": "warn",
|
|
1237
1168
|
...overrides
|
|
1238
1169
|
}
|
|
1239
1170
|
}
|
|
@@ -1242,15 +1173,8 @@ async function yaml(options = {}) {
|
|
|
1242
1173
|
|
|
1243
1174
|
// src/configs/test.ts
|
|
1244
1175
|
async function test(options = {}) {
|
|
1245
|
-
const {
|
|
1246
|
-
|
|
1247
|
-
isInEditor = false,
|
|
1248
|
-
overrides = {}
|
|
1249
|
-
} = options;
|
|
1250
|
-
const [
|
|
1251
|
-
pluginVitest,
|
|
1252
|
-
pluginNoOnlyTests
|
|
1253
|
-
] = await Promise.all([
|
|
1176
|
+
const { files = GLOB_TESTS, isInEditor = false, overrides = {} } = options;
|
|
1177
|
+
const [pluginVitest, pluginNoOnlyTests] = await Promise.all([
|
|
1254
1178
|
interopDefault(import("eslint-plugin-vitest")),
|
|
1255
1179
|
// @ts-expect-error missing types
|
|
1256
1180
|
interopDefault(import("eslint-plugin-no-only-tests"))
|
|
@@ -1274,8 +1198,12 @@ async function test(options = {}) {
|
|
|
1274
1198
|
name: "coderwyd:test:rules",
|
|
1275
1199
|
rules: {
|
|
1276
1200
|
"node/prefer-global/process": "off",
|
|
1277
|
-
"test/consistent-test-it": [
|
|
1201
|
+
"test/consistent-test-it": [
|
|
1202
|
+
"error",
|
|
1203
|
+
{ fn: "it", withinDescribe: "it" }
|
|
1204
|
+
],
|
|
1278
1205
|
"test/no-identical-title": "error",
|
|
1206
|
+
"test/no-import-node-test": "error",
|
|
1279
1207
|
"test/no-only-tests": isInEditor ? "off" : "error",
|
|
1280
1208
|
"test/prefer-hooks-in-order": "error",
|
|
1281
1209
|
"test/prefer-lowercase-title": "error",
|
|
@@ -1299,9 +1227,7 @@ async function perfectionist() {
|
|
|
1299
1227
|
|
|
1300
1228
|
// src/configs/react.ts
|
|
1301
1229
|
import { isPackageExists as isPackageExists2 } from "local-pkg";
|
|
1302
|
-
var ReactRefreshAllowConstantExportPackages = [
|
|
1303
|
-
"vite"
|
|
1304
|
-
];
|
|
1230
|
+
var ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
1305
1231
|
async function react(options = {}) {
|
|
1306
1232
|
const {
|
|
1307
1233
|
files = [GLOB_JSX, GLOB_TSX],
|
|
@@ -1313,15 +1239,13 @@ async function react(options = {}) {
|
|
|
1313
1239
|
"eslint-plugin-react-hooks",
|
|
1314
1240
|
"eslint-plugin-react-refresh"
|
|
1315
1241
|
]);
|
|
1316
|
-
const [
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1324
|
-
]);
|
|
1242
|
+
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
|
|
1243
|
+
[
|
|
1244
|
+
interopDefault(import("eslint-plugin-react")),
|
|
1245
|
+
interopDefault(import("eslint-plugin-react-hooks")),
|
|
1246
|
+
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1247
|
+
]
|
|
1248
|
+
);
|
|
1325
1249
|
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
|
|
1326
1250
|
(i) => isPackageExists2(i)
|
|
1327
1251
|
);
|
|
@@ -1329,9 +1253,14 @@ async function react(options = {}) {
|
|
|
1329
1253
|
{
|
|
1330
1254
|
name: "coderwyd:react:setup",
|
|
1331
1255
|
plugins: {
|
|
1332
|
-
|
|
1256
|
+
react: pluginReact,
|
|
1333
1257
|
"react-hooks": pluginReactHooks,
|
|
1334
1258
|
"react-refresh": pluginReactRefresh
|
|
1259
|
+
},
|
|
1260
|
+
settings: {
|
|
1261
|
+
react: {
|
|
1262
|
+
version: "detect"
|
|
1263
|
+
}
|
|
1335
1264
|
}
|
|
1336
1265
|
},
|
|
1337
1266
|
{
|
|
@@ -1389,16 +1318,9 @@ async function react(options = {}) {
|
|
|
1389
1318
|
|
|
1390
1319
|
// src/configs/unocss.ts
|
|
1391
1320
|
async function unocss(options = {}) {
|
|
1392
|
-
const {
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
} = options;
|
|
1396
|
-
await ensurePackages([
|
|
1397
|
-
"@unocss/eslint-plugin"
|
|
1398
|
-
]);
|
|
1399
|
-
const [
|
|
1400
|
-
pluginUnoCSS
|
|
1401
|
-
] = await Promise.all([
|
|
1321
|
+
const { attributify = true, strict = false } = options;
|
|
1322
|
+
await ensurePackages(["@unocss/eslint-plugin"]);
|
|
1323
|
+
const [pluginUnoCSS] = await Promise.all([
|
|
1402
1324
|
interopDefault(import("@unocss/eslint-plugin"))
|
|
1403
1325
|
]);
|
|
1404
1326
|
return [
|
|
@@ -1420,7 +1342,82 @@ async function unocss(options = {}) {
|
|
|
1420
1342
|
];
|
|
1421
1343
|
}
|
|
1422
1344
|
|
|
1423
|
-
// src/
|
|
1345
|
+
// src/configs/formatter.ts
|
|
1346
|
+
async function formatter(options = {}, prettierRules2 = {}) {
|
|
1347
|
+
await ensurePackages(["eslint-plugin-prettier"]);
|
|
1348
|
+
const {
|
|
1349
|
+
css = true,
|
|
1350
|
+
graphql,
|
|
1351
|
+
html = true,
|
|
1352
|
+
markdown,
|
|
1353
|
+
toml,
|
|
1354
|
+
yaml
|
|
1355
|
+
} = options || {};
|
|
1356
|
+
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
1357
|
+
function createPrettierFormatter(files, parser, plugins) {
|
|
1358
|
+
const rules = {
|
|
1359
|
+
...prettierRules2,
|
|
1360
|
+
parser
|
|
1361
|
+
};
|
|
1362
|
+
if (plugins == null ? void 0 : plugins.length) {
|
|
1363
|
+
rules.plugins = [...rules.plugins || [], ...plugins];
|
|
1364
|
+
}
|
|
1365
|
+
const config = {
|
|
1366
|
+
files,
|
|
1367
|
+
languageOptions: {
|
|
1368
|
+
parser: parserPlain
|
|
1369
|
+
},
|
|
1370
|
+
name: `coderwyd:formatter:${parser}`,
|
|
1371
|
+
plugins: {
|
|
1372
|
+
prettier: pluginPrettier
|
|
1373
|
+
},
|
|
1374
|
+
rules: {
|
|
1375
|
+
"prettier/prettier": ["warn", rules]
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
return config;
|
|
1379
|
+
}
|
|
1380
|
+
const configs = [
|
|
1381
|
+
{
|
|
1382
|
+
name: "coderwyd:formatter:setup",
|
|
1383
|
+
plugins: {
|
|
1384
|
+
prettier: pluginPrettier
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
];
|
|
1388
|
+
if (css) {
|
|
1389
|
+
const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], "css");
|
|
1390
|
+
const scssConfig = createPrettierFormatter([GLOB_SCSS], "scss");
|
|
1391
|
+
const lessConfig = createPrettierFormatter([GLOB_LESS], "less");
|
|
1392
|
+
configs.push(cssConfig, scssConfig, lessConfig);
|
|
1393
|
+
}
|
|
1394
|
+
if (html) {
|
|
1395
|
+
const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
|
|
1396
|
+
configs.push(htmlConfig);
|
|
1397
|
+
}
|
|
1398
|
+
if (markdown) {
|
|
1399
|
+
const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], "markdown");
|
|
1400
|
+
configs.push(markdownConfig);
|
|
1401
|
+
}
|
|
1402
|
+
if (graphql) {
|
|
1403
|
+
const graphqlConfig = createPrettierFormatter([GLOB_GRAPHQL], "graphql");
|
|
1404
|
+
configs.push(graphqlConfig);
|
|
1405
|
+
}
|
|
1406
|
+
if (yaml) {
|
|
1407
|
+
const yamlConfig = createPrettierFormatter([GLOB_YAML], "yaml");
|
|
1408
|
+
configs.push(yamlConfig);
|
|
1409
|
+
}
|
|
1410
|
+
if (toml) {
|
|
1411
|
+
await ensurePackages(["@toml-tools/parser", "prettier-plugin-toml"]);
|
|
1412
|
+
const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", [
|
|
1413
|
+
"prettier-plugin-toml"
|
|
1414
|
+
]);
|
|
1415
|
+
configs.push(tomlConfig);
|
|
1416
|
+
}
|
|
1417
|
+
return configs;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/index.ts
|
|
1424
1421
|
var flatConfigProps = [
|
|
1425
1422
|
"files",
|
|
1426
1423
|
"ignores",
|
|
@@ -1431,49 +1428,45 @@ var flatConfigProps = [
|
|
|
1431
1428
|
"rules",
|
|
1432
1429
|
"settings"
|
|
1433
1430
|
];
|
|
1434
|
-
var VuePackages = [
|
|
1435
|
-
|
|
1436
|
-
"nuxt",
|
|
1437
|
-
"vitepress",
|
|
1438
|
-
"@slidev/cli"
|
|
1439
|
-
];
|
|
1440
|
-
async function coderwyd(options = {}, ...userConfigs) {
|
|
1431
|
+
var VuePackages = ["vue", "nuxt", "vitepress", "@slidev/cli"];
|
|
1432
|
+
async function defineConfig(options = {}, ...userConfigs) {
|
|
1441
1433
|
const {
|
|
1442
1434
|
componentExts = [],
|
|
1443
1435
|
gitignore: enableGitignore = true,
|
|
1444
|
-
isInEditor = !!((process3.env.VSCODE_PID || process3.env.JETBRAINS_IDE) && !process3.env.CI),
|
|
1445
|
-
overrides = {},
|
|
1436
|
+
isInEditor = !!((process3.env.VSCODE_PID || process3.env.JETBRAINS_IDE || process3.env.VIM) && !process3.env.CI),
|
|
1446
1437
|
react: enableReact = false,
|
|
1447
1438
|
typescript: enableTypeScript = isPackageExists3("typescript"),
|
|
1448
1439
|
unocss: enableUnoCSS = false,
|
|
1440
|
+
usePrettierrc = true,
|
|
1449
1441
|
vue: enableVue = VuePackages.some((i) => isPackageExists3(i))
|
|
1450
1442
|
} = options;
|
|
1451
|
-
const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
1452
|
-
if (stylisticOptions && !("jsx" in stylisticOptions))
|
|
1453
|
-
stylisticOptions.jsx = options.jsx ?? true;
|
|
1454
1443
|
const configs = [];
|
|
1455
1444
|
if (enableGitignore) {
|
|
1456
1445
|
if (typeof enableGitignore !== "boolean") {
|
|
1457
|
-
configs.push(
|
|
1446
|
+
configs.push(
|
|
1447
|
+
interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
|
|
1448
|
+
r(enableGitignore)
|
|
1449
|
+
])
|
|
1450
|
+
);
|
|
1458
1451
|
} else {
|
|
1459
1452
|
if (fs.existsSync(".gitignore"))
|
|
1460
|
-
configs.push(
|
|
1453
|
+
configs.push(
|
|
1454
|
+
interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
|
|
1455
|
+
r()
|
|
1456
|
+
])
|
|
1457
|
+
);
|
|
1461
1458
|
}
|
|
1462
1459
|
}
|
|
1463
1460
|
configs.push(
|
|
1464
1461
|
ignores(),
|
|
1465
1462
|
javascript({
|
|
1466
1463
|
isInEditor,
|
|
1467
|
-
overrides:
|
|
1464
|
+
overrides: getOverrides(options, "javascript")
|
|
1468
1465
|
}),
|
|
1469
1466
|
comments(),
|
|
1470
1467
|
node(),
|
|
1471
|
-
jsdoc(
|
|
1472
|
-
|
|
1473
|
-
}),
|
|
1474
|
-
imports({
|
|
1475
|
-
stylistic: stylisticOptions
|
|
1476
|
-
}),
|
|
1468
|
+
jsdoc(),
|
|
1469
|
+
imports(),
|
|
1477
1470
|
unicorn(),
|
|
1478
1471
|
// Optional plugins (installed but not enabled by default)
|
|
1479
1472
|
perfectionist()
|
|
@@ -1481,60 +1474,70 @@ async function coderwyd(options = {}, ...userConfigs) {
|
|
|
1481
1474
|
if (enableVue)
|
|
1482
1475
|
componentExts.push("vue");
|
|
1483
1476
|
if (enableTypeScript) {
|
|
1484
|
-
configs.push(
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1477
|
+
configs.push(
|
|
1478
|
+
typescript({
|
|
1479
|
+
...resolveSubOptions(options, "typescript"),
|
|
1480
|
+
componentExts
|
|
1481
|
+
})
|
|
1482
|
+
);
|
|
1489
1483
|
}
|
|
1490
|
-
if (stylisticOptions)
|
|
1491
|
-
configs.push(stylistic(stylisticOptions));
|
|
1492
1484
|
if (options.test ?? true) {
|
|
1493
|
-
configs.push(
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1485
|
+
configs.push(
|
|
1486
|
+
test({
|
|
1487
|
+
isInEditor,
|
|
1488
|
+
overrides: getOverrides(options, "test")
|
|
1489
|
+
})
|
|
1490
|
+
);
|
|
1497
1491
|
}
|
|
1498
1492
|
if (enableVue) {
|
|
1499
|
-
configs.push(
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1493
|
+
configs.push(
|
|
1494
|
+
vue({
|
|
1495
|
+
...resolveSubOptions(options, "vue"),
|
|
1496
|
+
typescript: !!enableTypeScript
|
|
1497
|
+
})
|
|
1498
|
+
);
|
|
1504
1499
|
}
|
|
1505
1500
|
if (enableReact) {
|
|
1506
|
-
configs.push(
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1501
|
+
configs.push(
|
|
1502
|
+
react({
|
|
1503
|
+
overrides: getOverrides(options, "react"),
|
|
1504
|
+
typescript: !!enableTypeScript
|
|
1505
|
+
})
|
|
1506
|
+
);
|
|
1510
1507
|
}
|
|
1511
1508
|
if (enableUnoCSS) {
|
|
1512
|
-
configs.push(
|
|
1513
|
-
|
|
1514
|
-
|
|
1509
|
+
configs.push(
|
|
1510
|
+
unocss({
|
|
1511
|
+
...resolveSubOptions(options, "unocss"),
|
|
1512
|
+
overrides: getOverrides(options, "unocss")
|
|
1513
|
+
})
|
|
1514
|
+
);
|
|
1515
1515
|
}
|
|
1516
1516
|
if (options.jsonc ?? true) {
|
|
1517
1517
|
configs.push(
|
|
1518
1518
|
jsonc({
|
|
1519
|
-
overrides:
|
|
1520
|
-
stylistic: stylisticOptions
|
|
1519
|
+
overrides: getOverrides(options, "jsonc")
|
|
1521
1520
|
}),
|
|
1522
1521
|
sortPackageJson(),
|
|
1523
1522
|
sortTsconfig()
|
|
1524
1523
|
);
|
|
1525
1524
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1525
|
+
let prettierRules2 = {
|
|
1526
|
+
...DEFAULT_PRETTIER_RULES
|
|
1527
|
+
};
|
|
1528
|
+
if (options.prettierRules) {
|
|
1529
|
+
prettierRules2 = { ...prettierRules2, ...options.prettierRules };
|
|
1531
1530
|
}
|
|
1532
|
-
if (
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1531
|
+
if (usePrettierrc) {
|
|
1532
|
+
const prettierConfig = await loadPrettierConfig(
|
|
1533
|
+
options.cwd ?? process3.cwd()
|
|
1534
|
+
);
|
|
1535
|
+
Object.assign(prettierRules2, prettierConfig);
|
|
1537
1536
|
}
|
|
1537
|
+
configs.push(
|
|
1538
|
+
prettier(prettierRules2),
|
|
1539
|
+
formatter(options.formatter, prettierRules2)
|
|
1540
|
+
);
|
|
1538
1541
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
1539
1542
|
if (key in options)
|
|
1540
1543
|
acc[key] = options[key];
|
|
@@ -1542,62 +1545,9 @@ async function coderwyd(options = {}, ...userConfigs) {
|
|
|
1542
1545
|
}, {});
|
|
1543
1546
|
if (Object.keys(fusedConfig).length)
|
|
1544
1547
|
configs.push([fusedConfig]);
|
|
1545
|
-
const merged = combine(
|
|
1546
|
-
...configs,
|
|
1547
|
-
...userConfigs
|
|
1548
|
-
);
|
|
1548
|
+
const merged = combine(...configs, ...userConfigs);
|
|
1549
1549
|
return merged;
|
|
1550
1550
|
}
|
|
1551
|
-
|
|
1552
|
-
// src/index.ts
|
|
1553
|
-
var src_default = coderwyd;
|
|
1554
1551
|
export {
|
|
1555
|
-
|
|
1556
|
-
GLOB_CSS,
|
|
1557
|
-
GLOB_EXCLUDE,
|
|
1558
|
-
GLOB_HTML,
|
|
1559
|
-
GLOB_JS,
|
|
1560
|
-
GLOB_JSON,
|
|
1561
|
-
GLOB_JSON5,
|
|
1562
|
-
GLOB_JSONC,
|
|
1563
|
-
GLOB_JSX,
|
|
1564
|
-
GLOB_LESS,
|
|
1565
|
-
GLOB_MARKDOWN,
|
|
1566
|
-
GLOB_MARKDOWN_CODE,
|
|
1567
|
-
GLOB_SCSS,
|
|
1568
|
-
GLOB_SRC,
|
|
1569
|
-
GLOB_SRC_EXT,
|
|
1570
|
-
GLOB_STYLE,
|
|
1571
|
-
GLOB_TESTS,
|
|
1572
|
-
GLOB_TS,
|
|
1573
|
-
GLOB_TSX,
|
|
1574
|
-
GLOB_VUE,
|
|
1575
|
-
GLOB_YAML,
|
|
1576
|
-
coderwyd,
|
|
1577
|
-
combine,
|
|
1578
|
-
comments,
|
|
1579
|
-
src_default as default,
|
|
1580
|
-
ensurePackages,
|
|
1581
|
-
getVueVersion,
|
|
1582
|
-
ignores,
|
|
1583
|
-
imports,
|
|
1584
|
-
interopDefault,
|
|
1585
|
-
javascript,
|
|
1586
|
-
jsdoc,
|
|
1587
|
-
jsonc,
|
|
1588
|
-
markdown,
|
|
1589
|
-
node,
|
|
1590
|
-
perfectionist,
|
|
1591
|
-
react,
|
|
1592
|
-
renameRules,
|
|
1593
|
-
sortPackageJson,
|
|
1594
|
-
sortTsconfig,
|
|
1595
|
-
stylistic,
|
|
1596
|
-
test,
|
|
1597
|
-
toArray,
|
|
1598
|
-
typescript,
|
|
1599
|
-
unicorn,
|
|
1600
|
-
unocss,
|
|
1601
|
-
vue,
|
|
1602
|
-
yaml
|
|
1552
|
+
defineConfig
|
|
1603
1553
|
};
|