@coderwyd/eslint-config 1.1.1 → 2.0.1
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 +424 -539
- package/dist/index.d.cts +127 -147
- package/dist/index.d.ts +127 -147
- package/dist/index.js +424 -491
- 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,43 @@ 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
|
-
"import/no-named-default": "error",
|
|
128
131
|
"import/no-self-import": "error",
|
|
129
132
|
"import/no-webpack-loader-syntax": "error",
|
|
130
|
-
"import/order":
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
"import/order": [
|
|
134
|
+
"error",
|
|
135
|
+
{
|
|
136
|
+
groups: [
|
|
137
|
+
"builtin",
|
|
138
|
+
"external",
|
|
139
|
+
"internal",
|
|
140
|
+
"parent",
|
|
141
|
+
"sibling",
|
|
142
|
+
"index",
|
|
143
|
+
"object",
|
|
144
|
+
"type"
|
|
145
|
+
],
|
|
146
|
+
pathGroups: [{ group: "internal", pattern: "{{@,~}/,#}**" }],
|
|
147
|
+
pathGroupsExcludedImportTypes: ["type"]
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
|
|
154
|
+
name: "coderwyd:imports:bin",
|
|
155
|
+
rules: {
|
|
156
|
+
"antfu/no-import-dist": "off",
|
|
157
|
+
"antfu/no-import-node-modules-by-path": "off"
|
|
134
158
|
}
|
|
135
159
|
}
|
|
136
160
|
];
|
|
@@ -139,10 +163,7 @@ async function imports(options = {}) {
|
|
|
139
163
|
// src/configs/javascript.ts
|
|
140
164
|
import globals from "globals";
|
|
141
165
|
async function javascript(options = {}) {
|
|
142
|
-
const {
|
|
143
|
-
isInEditor = false,
|
|
144
|
-
overrides = {}
|
|
145
|
-
} = options;
|
|
166
|
+
const { isInEditor = false, overrides = {} } = options;
|
|
146
167
|
return [
|
|
147
168
|
{
|
|
148
169
|
languageOptions: {
|
|
@@ -169,18 +190,23 @@ async function javascript(options = {}) {
|
|
|
169
190
|
},
|
|
170
191
|
name: "coderwyd:javascript",
|
|
171
192
|
plugins: {
|
|
172
|
-
"antfu": default2,
|
|
173
193
|
"unused-imports": default6
|
|
174
194
|
},
|
|
175
195
|
rules: {
|
|
176
|
-
"accessor-pairs": [
|
|
196
|
+
"accessor-pairs": [
|
|
197
|
+
"error",
|
|
198
|
+
{ enforceForClassMembers: true, setWithoutGet: true }
|
|
199
|
+
],
|
|
177
200
|
"array-callback-return": "error",
|
|
178
201
|
"block-scoped-var": "error",
|
|
179
202
|
"constructor-super": "error",
|
|
180
203
|
"default-case-last": "error",
|
|
181
204
|
"dot-notation": ["error", { allowKeywords: true }],
|
|
182
|
-
|
|
183
|
-
"new-cap": [
|
|
205
|
+
eqeqeq: ["error", "smart"],
|
|
206
|
+
"new-cap": [
|
|
207
|
+
"error",
|
|
208
|
+
{ capIsNew: false, newIsCap: true, properties: true }
|
|
209
|
+
],
|
|
184
210
|
"no-alert": "error",
|
|
185
211
|
"no-array-constructor": "error",
|
|
186
212
|
"no-async-promise-executor": "error",
|
|
@@ -238,11 +264,26 @@ async function javascript(options = {}) {
|
|
|
238
264
|
],
|
|
239
265
|
"no-restricted-properties": [
|
|
240
266
|
"error",
|
|
241
|
-
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{
|
|
267
|
+
{
|
|
268
|
+
message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
|
|
269
|
+
property: "__proto__"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
message: "Use `Object.defineProperty` instead.",
|
|
273
|
+
property: "__defineGetter__"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
message: "Use `Object.defineProperty` instead.",
|
|
277
|
+
property: "__defineSetter__"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
message: "Use `Object.getOwnPropertyDescriptor` instead.",
|
|
281
|
+
property: "__lookupGetter__"
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
message: "Use `Object.getOwnPropertyDescriptor` instead.",
|
|
285
|
+
property: "__lookupSetter__"
|
|
286
|
+
}
|
|
246
287
|
],
|
|
247
288
|
"no-restricted-syntax": [
|
|
248
289
|
"error",
|
|
@@ -269,18 +310,27 @@ async function javascript(options = {}) {
|
|
|
269
310
|
"no-unreachable-loop": "error",
|
|
270
311
|
"no-unsafe-finally": "error",
|
|
271
312
|
"no-unsafe-negation": "error",
|
|
272
|
-
"no-unused-expressions": [
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
313
|
+
"no-unused-expressions": [
|
|
314
|
+
"error",
|
|
315
|
+
{
|
|
316
|
+
allowShortCircuit: true,
|
|
317
|
+
allowTaggedTemplates: true,
|
|
318
|
+
allowTernary: true
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
"no-unused-vars": [
|
|
322
|
+
"error",
|
|
323
|
+
{
|
|
324
|
+
args: "none",
|
|
325
|
+
caughtErrors: "none",
|
|
326
|
+
ignoreRestSiblings: true,
|
|
327
|
+
vars: "all"
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
"no-use-before-define": [
|
|
331
|
+
"error",
|
|
332
|
+
{ classes: false, functions: false, variables: true }
|
|
333
|
+
],
|
|
284
334
|
"no-useless-backreference": "error",
|
|
285
335
|
"no-useless-call": "error",
|
|
286
336
|
"no-useless-catch": "error",
|
|
@@ -334,12 +384,20 @@ async function javascript(options = {}) {
|
|
|
334
384
|
"unused-imports/no-unused-imports": isInEditor ? "off" : "error",
|
|
335
385
|
"unused-imports/no-unused-vars": [
|
|
336
386
|
"error",
|
|
337
|
-
{
|
|
387
|
+
{
|
|
388
|
+
args: "after-used",
|
|
389
|
+
argsIgnorePattern: "^_",
|
|
390
|
+
vars: "all",
|
|
391
|
+
varsIgnorePattern: "^_"
|
|
392
|
+
}
|
|
393
|
+
],
|
|
394
|
+
"use-isnan": [
|
|
395
|
+
"error",
|
|
396
|
+
{ enforceForIndexOf: true, enforceForSwitchCase: true }
|
|
338
397
|
],
|
|
339
|
-
"use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
|
|
340
398
|
"valid-typeof": ["error", { requireStringLiterals: true }],
|
|
341
399
|
"vars-on-top": "error",
|
|
342
|
-
|
|
400
|
+
yoda: ["error", "never"],
|
|
343
401
|
...overrides
|
|
344
402
|
}
|
|
345
403
|
},
|
|
@@ -353,9 +411,31 @@ async function javascript(options = {}) {
|
|
|
353
411
|
];
|
|
354
412
|
}
|
|
355
413
|
|
|
356
|
-
// src/
|
|
414
|
+
// src/shared/index.ts
|
|
357
415
|
import process from "process";
|
|
416
|
+
import { readFile } from "fs/promises";
|
|
417
|
+
import path from "path";
|
|
358
418
|
import { getPackageInfoSync, isPackageExists } from "local-pkg";
|
|
419
|
+
var parserPlain = {
|
|
420
|
+
meta: {
|
|
421
|
+
name: "parser-plain"
|
|
422
|
+
},
|
|
423
|
+
parseForESLint: (code) => ({
|
|
424
|
+
ast: {
|
|
425
|
+
body: [],
|
|
426
|
+
comments: [],
|
|
427
|
+
loc: { end: code.length, start: 0 },
|
|
428
|
+
range: [0, code.length],
|
|
429
|
+
tokens: [],
|
|
430
|
+
type: "Program"
|
|
431
|
+
},
|
|
432
|
+
scopeManager: null,
|
|
433
|
+
services: { isPlain: true },
|
|
434
|
+
visitorKeys: {
|
|
435
|
+
Program: []
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
};
|
|
359
439
|
async function combine(...configs) {
|
|
360
440
|
const resolved = await Promise.all(configs);
|
|
361
441
|
return resolved.flat();
|
|
@@ -391,20 +471,41 @@ async function ensurePackages(packages) {
|
|
|
391
471
|
const { default: prompts } = await import("prompts");
|
|
392
472
|
const { result } = await prompts([
|
|
393
473
|
{
|
|
394
|
-
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
|
|
474
|
+
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
|
|
475
|
+
", "
|
|
476
|
+
)}. Do you want to install them?`,
|
|
395
477
|
name: "result",
|
|
396
478
|
type: "confirm"
|
|
397
479
|
}
|
|
398
480
|
]);
|
|
399
481
|
if (result)
|
|
400
|
-
await import("@antfu/install-pkg").then(
|
|
482
|
+
await import("@antfu/install-pkg").then(
|
|
483
|
+
(i) => i.installPackage(nonExistingPackages, { dev: true })
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
async function loadPrettierConfig(cwd) {
|
|
487
|
+
let prettierConfig = {};
|
|
488
|
+
try {
|
|
489
|
+
const prettierrc = await readFile(path.join(cwd, ".prettierrc"), "utf-8");
|
|
490
|
+
prettierConfig = JSON.parse(prettierrc);
|
|
491
|
+
} catch {
|
|
492
|
+
}
|
|
493
|
+
return prettierConfig;
|
|
494
|
+
}
|
|
495
|
+
function resolveSubOptions(options, key) {
|
|
496
|
+
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
497
|
+
}
|
|
498
|
+
function getOverrides(options, key) {
|
|
499
|
+
var _a;
|
|
500
|
+
const sub = resolveSubOptions(options, key);
|
|
501
|
+
return {
|
|
502
|
+
...(_a = options.overrides) == null ? void 0 : _a[key],
|
|
503
|
+
..."overrides" in sub ? sub.overrides : {}
|
|
504
|
+
};
|
|
401
505
|
}
|
|
402
506
|
|
|
403
507
|
// src/configs/jsdoc.ts
|
|
404
|
-
async function jsdoc(
|
|
405
|
-
const {
|
|
406
|
-
stylistic: stylistic2 = true
|
|
407
|
-
} = options;
|
|
508
|
+
async function jsdoc() {
|
|
408
509
|
return [
|
|
409
510
|
{
|
|
410
511
|
name: "coderwyd:jsdoc",
|
|
@@ -427,11 +528,12 @@ async function jsdoc(options = {}) {
|
|
|
427
528
|
"jsdoc/require-property-name": "warn",
|
|
428
529
|
"jsdoc/require-returns-check": "warn",
|
|
429
530
|
"jsdoc/require-returns-description": "warn",
|
|
430
|
-
"jsdoc/require-yields-check": "warn"
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
531
|
+
"jsdoc/require-yields-check": "warn"
|
|
532
|
+
// style
|
|
533
|
+
// ...{
|
|
534
|
+
// 'jsdoc/check-alignment': 'warn',
|
|
535
|
+
// 'jsdoc/multiline-blocks': 'warn',
|
|
536
|
+
// }
|
|
435
537
|
}
|
|
436
538
|
}
|
|
437
539
|
];
|
|
@@ -439,18 +541,8 @@ async function jsdoc(options = {}) {
|
|
|
439
541
|
|
|
440
542
|
// src/configs/jsonc.ts
|
|
441
543
|
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([
|
|
544
|
+
const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = options || {};
|
|
545
|
+
const [pluginJsonc, parserJsonc] = await Promise.all([
|
|
454
546
|
interopDefault(import("eslint-plugin-jsonc")),
|
|
455
547
|
interopDefault(import("jsonc-eslint-parser"))
|
|
456
548
|
]);
|
|
@@ -494,101 +586,19 @@ async function jsonc(options = {}) {
|
|
|
494
586
|
"jsonc/space-unary-ops": "error",
|
|
495
587
|
"jsonc/valid-json-number": "error",
|
|
496
588
|
"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
|
-
},
|
|
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
|
+
// },
|
|
592
602
|
...overrides
|
|
593
603
|
}
|
|
594
604
|
}
|
|
@@ -683,23 +693,14 @@ async function sortPackageJson() {
|
|
|
683
693
|
},
|
|
684
694
|
{
|
|
685
695
|
order: { type: "asc" },
|
|
686
|
-
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
order: { type: "asc" },
|
|
690
|
-
pathPattern: "^resolutions$"
|
|
696
|
+
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
|
|
691
697
|
},
|
|
692
698
|
{
|
|
693
699
|
order: { type: "asc" },
|
|
694
|
-
pathPattern: "^pnpm.overrides$"
|
|
700
|
+
pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
|
|
695
701
|
},
|
|
696
702
|
{
|
|
697
|
-
order: [
|
|
698
|
-
"types",
|
|
699
|
-
"import",
|
|
700
|
-
"require",
|
|
701
|
-
"default"
|
|
702
|
-
],
|
|
703
|
+
order: ["types", "import", "require", "default"],
|
|
703
704
|
pathPattern: "^exports.*$"
|
|
704
705
|
}
|
|
705
706
|
]
|
|
@@ -833,54 +834,41 @@ function sortTsconfig() {
|
|
|
833
834
|
];
|
|
834
835
|
}
|
|
835
836
|
|
|
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 [
|
|
837
|
+
// src/configs/prettier.ts
|
|
838
|
+
import prettierRules from "eslint-config-prettier";
|
|
839
|
+
var { rules: eslintRules } = prettierRules;
|
|
840
|
+
async function prettier(rules) {
|
|
841
|
+
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
842
|
+
const pRules = {
|
|
843
|
+
...rules
|
|
844
|
+
};
|
|
845
|
+
const configs = [
|
|
854
846
|
{
|
|
855
|
-
|
|
847
|
+
files: GLOB_PRETTIER_LINT,
|
|
856
848
|
plugins: {
|
|
857
|
-
|
|
858
|
-
style: pluginStylistic
|
|
849
|
+
prettier: pluginPrettier
|
|
859
850
|
},
|
|
860
851
|
rules: {
|
|
861
|
-
...
|
|
862
|
-
"
|
|
863
|
-
|
|
864
|
-
"
|
|
865
|
-
"
|
|
866
|
-
"curly": ["error", "multi-or-nest", "consistent"]
|
|
852
|
+
...eslintRules,
|
|
853
|
+
"prettier/prettier": ["warn", pRules],
|
|
854
|
+
// eslint-disable-next-line perfectionist/sort-objects
|
|
855
|
+
"arrow-body-style": "off",
|
|
856
|
+
"prefer-arrow-callback": "off"
|
|
867
857
|
}
|
|
868
858
|
}
|
|
869
859
|
];
|
|
860
|
+
return configs;
|
|
870
861
|
}
|
|
871
862
|
|
|
872
863
|
// src/configs/typescript.ts
|
|
873
864
|
import process2 from "process";
|
|
874
865
|
async function typescript(options = {}) {
|
|
875
|
-
const {
|
|
876
|
-
componentExts = [],
|
|
877
|
-
overrides = {},
|
|
878
|
-
parserOptions = {}
|
|
879
|
-
} = options;
|
|
866
|
+
const { componentExts = [], overrides = {}, parserOptions = {} } = options;
|
|
880
867
|
const files = options.files ?? [
|
|
881
868
|
GLOB_SRC,
|
|
882
869
|
...componentExts.map((ext) => `**/*.${ext}`)
|
|
883
870
|
];
|
|
871
|
+
const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
|
|
884
872
|
const typeAwareRules = {
|
|
885
873
|
"dot-notation": "off",
|
|
886
874
|
"no-implied-eval": "off",
|
|
@@ -902,11 +890,8 @@ async function typescript(options = {}) {
|
|
|
902
890
|
"ts/restrict-template-expressions": "error",
|
|
903
891
|
"ts/unbound-method": "error"
|
|
904
892
|
};
|
|
905
|
-
const tsconfigPath = options
|
|
906
|
-
const [
|
|
907
|
-
pluginTs,
|
|
908
|
-
parserTs
|
|
909
|
-
] = await Promise.all([
|
|
893
|
+
const tsconfigPath = (options == null ? void 0 : options.tsconfigPath) ? toArray(options.tsconfigPath) : void 0;
|
|
894
|
+
const [pluginTs, parserTs] = await Promise.all([
|
|
910
895
|
interopDefault(import("@typescript-eslint/eslint-plugin")),
|
|
911
896
|
interopDefault(import("@typescript-eslint/parser"))
|
|
912
897
|
]);
|
|
@@ -945,17 +930,21 @@ async function typescript(options = {}) {
|
|
|
945
930
|
"@typescript-eslint/",
|
|
946
931
|
"ts/"
|
|
947
932
|
),
|
|
948
|
-
"antfu/generic-spacing": "error",
|
|
949
|
-
"antfu/named-tuple-spacing": "error",
|
|
950
933
|
"no-dupe-class-members": "off",
|
|
951
934
|
"no-loss-of-precision": "off",
|
|
952
935
|
"no-redeclare": "off",
|
|
953
936
|
"no-use-before-define": "off",
|
|
954
937
|
"no-useless-constructor": "off",
|
|
955
|
-
"ts/ban-ts-comment": [
|
|
938
|
+
"ts/ban-ts-comment": [
|
|
939
|
+
"error",
|
|
940
|
+
{ "ts-ignore": "allow-with-description" }
|
|
941
|
+
],
|
|
956
942
|
"ts/ban-types": ["error", { types: { Function: false } }],
|
|
957
943
|
"ts/consistent-type-definitions": ["error", "interface"],
|
|
958
|
-
"ts/consistent-type-imports": [
|
|
944
|
+
"ts/consistent-type-imports": [
|
|
945
|
+
"error",
|
|
946
|
+
{ disallowTypeAnnotations: false, prefer: "type-imports" }
|
|
947
|
+
],
|
|
959
948
|
"ts/no-dupe-class-members": "error",
|
|
960
949
|
"ts/no-dynamic-delete": "off",
|
|
961
950
|
"ts/no-explicit-any": "off",
|
|
@@ -967,11 +956,21 @@ async function typescript(options = {}) {
|
|
|
967
956
|
"ts/no-redeclare": "error",
|
|
968
957
|
"ts/no-require-imports": "error",
|
|
969
958
|
"ts/no-unused-vars": "off",
|
|
970
|
-
"ts/no-use-before-define": [
|
|
959
|
+
"ts/no-use-before-define": [
|
|
960
|
+
"error",
|
|
961
|
+
{ classes: false, functions: false, variables: true }
|
|
962
|
+
],
|
|
971
963
|
"ts/no-useless-constructor": "off",
|
|
972
964
|
"ts/prefer-ts-expect-error": "error",
|
|
973
965
|
"ts/triple-slash-reference": "off",
|
|
974
966
|
"ts/unified-signatures": "off",
|
|
967
|
+
...overrides
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
{
|
|
971
|
+
files: filesTypeAware,
|
|
972
|
+
name: "coderwyd:typescript:rules-type-aware",
|
|
973
|
+
rules: {
|
|
975
974
|
...tsconfigPath ? typeAwareRules : {},
|
|
976
975
|
...overrides
|
|
977
976
|
}
|
|
@@ -1047,35 +1046,20 @@ async function unicorn() {
|
|
|
1047
1046
|
|
|
1048
1047
|
// src/configs/vue.ts
|
|
1049
1048
|
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;
|
|
1049
|
+
const { files = [GLOB_VUE], overrides = {} } = options;
|
|
1058
1050
|
const isVue3 = getVueVersion() === 3;
|
|
1059
|
-
const [
|
|
1060
|
-
pluginVue,
|
|
1061
|
-
parserVue
|
|
1062
|
-
] = await Promise.all([
|
|
1063
|
-
// @ts-expect-error missing types
|
|
1051
|
+
const [pluginVue, parserVue] = await Promise.all([
|
|
1064
1052
|
interopDefault(import("eslint-plugin-vue")),
|
|
1065
1053
|
interopDefault(import("vue-eslint-parser"))
|
|
1066
1054
|
]);
|
|
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
|
-
};
|
|
1055
|
+
const configKeys = isVue3 ? ["vue3-essential", "vue3-strongly-recommended", "vue3-recommended"] : ["essential", "strongly-recommended", "recommended"];
|
|
1056
|
+
const vueRules = configKeys.reduce((preRules, key) => {
|
|
1057
|
+
const config = pluginVue.configs[key];
|
|
1058
|
+
return {
|
|
1059
|
+
...preRules,
|
|
1060
|
+
...config.rules
|
|
1061
|
+
};
|
|
1062
|
+
}, {});
|
|
1079
1063
|
return [
|
|
1080
1064
|
{
|
|
1081
1065
|
name: "coderwyd:vue:setup",
|
|
@@ -1092,28 +1076,42 @@ async function vue(options = {}) {
|
|
|
1092
1076
|
jsx: true
|
|
1093
1077
|
},
|
|
1094
1078
|
extraFileExtensions: [".vue"],
|
|
1095
|
-
parser: options.typescript ? await interopDefault(
|
|
1079
|
+
parser: options.typescript ? await interopDefault(
|
|
1080
|
+
import("@typescript-eslint/parser")
|
|
1081
|
+
) : null,
|
|
1096
1082
|
sourceType: "module"
|
|
1097
1083
|
}
|
|
1098
1084
|
},
|
|
1099
1085
|
name: "coderwyd:vue:rules",
|
|
1100
1086
|
processor: pluginVue.processors[".vue"],
|
|
1101
1087
|
rules: {
|
|
1102
|
-
...
|
|
1088
|
+
...pluginVue.configs.base.rules,
|
|
1089
|
+
...vueRules,
|
|
1103
1090
|
"node/prefer-global/process": "off",
|
|
1104
|
-
"vue/block-order": [
|
|
1105
|
-
|
|
1106
|
-
|
|
1091
|
+
"vue/block-order": [
|
|
1092
|
+
"error",
|
|
1093
|
+
{
|
|
1094
|
+
order: ["script", "template", "style"]
|
|
1095
|
+
}
|
|
1096
|
+
],
|
|
1107
1097
|
"vue/component-name-in-template-casing": ["error", "PascalCase"],
|
|
1108
1098
|
"vue/component-options-name-casing": ["error", "PascalCase"],
|
|
1109
1099
|
"vue/custom-event-name-casing": ["error", "camelCase"],
|
|
1110
|
-
"vue/define-macros-order": [
|
|
1111
|
-
|
|
1112
|
-
|
|
1100
|
+
"vue/define-macros-order": [
|
|
1101
|
+
"error",
|
|
1102
|
+
{
|
|
1103
|
+
order: [
|
|
1104
|
+
"defineOptions",
|
|
1105
|
+
"defineProps",
|
|
1106
|
+
"defineEmits",
|
|
1107
|
+
"defineSlots"
|
|
1108
|
+
]
|
|
1109
|
+
}
|
|
1110
|
+
],
|
|
1113
1111
|
"vue/dot-location": ["error", "property"],
|
|
1114
1112
|
"vue/dot-notation": ["error", { allowKeywords: true }],
|
|
1115
1113
|
"vue/eqeqeq": ["error", "smart"],
|
|
1116
|
-
"vue/html-indent": ["error",
|
|
1114
|
+
"vue/html-indent": ["error", 2],
|
|
1117
1115
|
"vue/html-quotes": ["error", "double"],
|
|
1118
1116
|
"vue/max-attributes-per-line": "off",
|
|
1119
1117
|
"vue/multi-word-component-names": "off",
|
|
@@ -1149,91 +1147,7 @@ async function vue(options = {}) {
|
|
|
1149
1147
|
"vue/require-prop-types": "off",
|
|
1150
1148
|
"vue/space-infix-ops": "error",
|
|
1151
1149
|
"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
|
-
} : {},
|
|
1150
|
+
"vue/valid-define-options": "warn",
|
|
1237
1151
|
...overrides
|
|
1238
1152
|
}
|
|
1239
1153
|
}
|
|
@@ -1242,15 +1156,8 @@ async function yaml(options = {}) {
|
|
|
1242
1156
|
|
|
1243
1157
|
// src/configs/test.ts
|
|
1244
1158
|
async function test(options = {}) {
|
|
1245
|
-
const {
|
|
1246
|
-
|
|
1247
|
-
isInEditor = false,
|
|
1248
|
-
overrides = {}
|
|
1249
|
-
} = options;
|
|
1250
|
-
const [
|
|
1251
|
-
pluginVitest,
|
|
1252
|
-
pluginNoOnlyTests
|
|
1253
|
-
] = await Promise.all([
|
|
1159
|
+
const { files = GLOB_TESTS, isInEditor = false, overrides = {} } = options;
|
|
1160
|
+
const [pluginVitest, pluginNoOnlyTests] = await Promise.all([
|
|
1254
1161
|
interopDefault(import("eslint-plugin-vitest")),
|
|
1255
1162
|
// @ts-expect-error missing types
|
|
1256
1163
|
interopDefault(import("eslint-plugin-no-only-tests"))
|
|
@@ -1274,8 +1181,12 @@ async function test(options = {}) {
|
|
|
1274
1181
|
name: "coderwyd:test:rules",
|
|
1275
1182
|
rules: {
|
|
1276
1183
|
"node/prefer-global/process": "off",
|
|
1277
|
-
"test/consistent-test-it": [
|
|
1184
|
+
"test/consistent-test-it": [
|
|
1185
|
+
"error",
|
|
1186
|
+
{ fn: "it", withinDescribe: "it" }
|
|
1187
|
+
],
|
|
1278
1188
|
"test/no-identical-title": "error",
|
|
1189
|
+
"test/no-import-node-test": "error",
|
|
1279
1190
|
"test/no-only-tests": isInEditor ? "off" : "error",
|
|
1280
1191
|
"test/prefer-hooks-in-order": "error",
|
|
1281
1192
|
"test/prefer-lowercase-title": "error",
|
|
@@ -1299,9 +1210,7 @@ async function perfectionist() {
|
|
|
1299
1210
|
|
|
1300
1211
|
// src/configs/react.ts
|
|
1301
1212
|
import { isPackageExists as isPackageExists2 } from "local-pkg";
|
|
1302
|
-
var ReactRefreshAllowConstantExportPackages = [
|
|
1303
|
-
"vite"
|
|
1304
|
-
];
|
|
1213
|
+
var ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
1305
1214
|
async function react(options = {}) {
|
|
1306
1215
|
const {
|
|
1307
1216
|
files = [GLOB_JSX, GLOB_TSX],
|
|
@@ -1313,15 +1222,13 @@ async function react(options = {}) {
|
|
|
1313
1222
|
"eslint-plugin-react-hooks",
|
|
1314
1223
|
"eslint-plugin-react-refresh"
|
|
1315
1224
|
]);
|
|
1316
|
-
const [
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1324
|
-
]);
|
|
1225
|
+
const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
|
|
1226
|
+
[
|
|
1227
|
+
interopDefault(import("eslint-plugin-react")),
|
|
1228
|
+
interopDefault(import("eslint-plugin-react-hooks")),
|
|
1229
|
+
interopDefault(import("eslint-plugin-react-refresh"))
|
|
1230
|
+
]
|
|
1231
|
+
);
|
|
1325
1232
|
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
|
|
1326
1233
|
(i) => isPackageExists2(i)
|
|
1327
1234
|
);
|
|
@@ -1329,9 +1236,14 @@ async function react(options = {}) {
|
|
|
1329
1236
|
{
|
|
1330
1237
|
name: "coderwyd:react:setup",
|
|
1331
1238
|
plugins: {
|
|
1332
|
-
|
|
1239
|
+
react: pluginReact,
|
|
1333
1240
|
"react-hooks": pluginReactHooks,
|
|
1334
1241
|
"react-refresh": pluginReactRefresh
|
|
1242
|
+
},
|
|
1243
|
+
settings: {
|
|
1244
|
+
react: {
|
|
1245
|
+
version: "detect"
|
|
1246
|
+
}
|
|
1335
1247
|
}
|
|
1336
1248
|
},
|
|
1337
1249
|
{
|
|
@@ -1389,16 +1301,9 @@ async function react(options = {}) {
|
|
|
1389
1301
|
|
|
1390
1302
|
// src/configs/unocss.ts
|
|
1391
1303
|
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([
|
|
1304
|
+
const { attributify = true, strict = false } = options;
|
|
1305
|
+
await ensurePackages(["@unocss/eslint-plugin"]);
|
|
1306
|
+
const [pluginUnoCSS] = await Promise.all([
|
|
1402
1307
|
interopDefault(import("@unocss/eslint-plugin"))
|
|
1403
1308
|
]);
|
|
1404
1309
|
return [
|
|
@@ -1420,7 +1325,82 @@ async function unocss(options = {}) {
|
|
|
1420
1325
|
];
|
|
1421
1326
|
}
|
|
1422
1327
|
|
|
1423
|
-
// src/
|
|
1328
|
+
// src/configs/formatter.ts
|
|
1329
|
+
async function formatter(options = {}, prettierRules2 = {}) {
|
|
1330
|
+
await ensurePackages(["eslint-plugin-prettier"]);
|
|
1331
|
+
const {
|
|
1332
|
+
css = true,
|
|
1333
|
+
graphql,
|
|
1334
|
+
html = true,
|
|
1335
|
+
markdown,
|
|
1336
|
+
toml,
|
|
1337
|
+
yaml
|
|
1338
|
+
} = options || {};
|
|
1339
|
+
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
1340
|
+
function createPrettierFormatter(files, parser, plugins) {
|
|
1341
|
+
const rules = {
|
|
1342
|
+
...prettierRules2,
|
|
1343
|
+
parser
|
|
1344
|
+
};
|
|
1345
|
+
if (plugins == null ? void 0 : plugins.length) {
|
|
1346
|
+
rules.plugins = [...rules.plugins || [], ...plugins];
|
|
1347
|
+
}
|
|
1348
|
+
const config = {
|
|
1349
|
+
files,
|
|
1350
|
+
languageOptions: {
|
|
1351
|
+
parser: parserPlain
|
|
1352
|
+
},
|
|
1353
|
+
name: `coderwyd:formatter:${parser}`,
|
|
1354
|
+
plugins: {
|
|
1355
|
+
prettier: pluginPrettier
|
|
1356
|
+
},
|
|
1357
|
+
rules: {
|
|
1358
|
+
"prettier/prettier": ["warn", rules]
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
return config;
|
|
1362
|
+
}
|
|
1363
|
+
const configs = [
|
|
1364
|
+
{
|
|
1365
|
+
name: "coderwyd:formatter:setup",
|
|
1366
|
+
plugins: {
|
|
1367
|
+
prettier: pluginPrettier
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
];
|
|
1371
|
+
if (css) {
|
|
1372
|
+
const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], "css");
|
|
1373
|
+
const scssConfig = createPrettierFormatter([GLOB_SCSS], "scss");
|
|
1374
|
+
const lessConfig = createPrettierFormatter([GLOB_LESS], "less");
|
|
1375
|
+
configs.push(cssConfig, scssConfig, lessConfig);
|
|
1376
|
+
}
|
|
1377
|
+
if (html) {
|
|
1378
|
+
const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
|
|
1379
|
+
configs.push(htmlConfig);
|
|
1380
|
+
}
|
|
1381
|
+
if (markdown) {
|
|
1382
|
+
const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], "markdown");
|
|
1383
|
+
configs.push(markdownConfig);
|
|
1384
|
+
}
|
|
1385
|
+
if (graphql) {
|
|
1386
|
+
const graphqlConfig = createPrettierFormatter([GLOB_GRAPHQL], "graphql");
|
|
1387
|
+
configs.push(graphqlConfig);
|
|
1388
|
+
}
|
|
1389
|
+
if (yaml) {
|
|
1390
|
+
const yamlConfig = createPrettierFormatter([GLOB_YAML], "yaml");
|
|
1391
|
+
configs.push(yamlConfig);
|
|
1392
|
+
}
|
|
1393
|
+
if (toml) {
|
|
1394
|
+
await ensurePackages(["@toml-tools/parser", "prettier-plugin-toml"]);
|
|
1395
|
+
const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", [
|
|
1396
|
+
"prettier-plugin-toml"
|
|
1397
|
+
]);
|
|
1398
|
+
configs.push(tomlConfig);
|
|
1399
|
+
}
|
|
1400
|
+
return configs;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// src/index.ts
|
|
1424
1404
|
var flatConfigProps = [
|
|
1425
1405
|
"files",
|
|
1426
1406
|
"ignores",
|
|
@@ -1431,49 +1411,45 @@ var flatConfigProps = [
|
|
|
1431
1411
|
"rules",
|
|
1432
1412
|
"settings"
|
|
1433
1413
|
];
|
|
1434
|
-
var VuePackages = [
|
|
1435
|
-
|
|
1436
|
-
"nuxt",
|
|
1437
|
-
"vitepress",
|
|
1438
|
-
"@slidev/cli"
|
|
1439
|
-
];
|
|
1440
|
-
async function coderwyd(options = {}, ...userConfigs) {
|
|
1414
|
+
var VuePackages = ["vue", "nuxt", "vitepress", "@slidev/cli"];
|
|
1415
|
+
async function defineConfig(options = {}, ...userConfigs) {
|
|
1441
1416
|
const {
|
|
1442
1417
|
componentExts = [],
|
|
1443
1418
|
gitignore: enableGitignore = true,
|
|
1444
|
-
isInEditor = !!((process3.env.VSCODE_PID || process3.env.JETBRAINS_IDE) && !process3.env.CI),
|
|
1445
|
-
overrides = {},
|
|
1419
|
+
isInEditor = !!((process3.env.VSCODE_PID || process3.env.JETBRAINS_IDE || process3.env.VIM) && !process3.env.CI),
|
|
1446
1420
|
react: enableReact = false,
|
|
1447
1421
|
typescript: enableTypeScript = isPackageExists3("typescript"),
|
|
1448
1422
|
unocss: enableUnoCSS = false,
|
|
1423
|
+
usePrettierrc = true,
|
|
1449
1424
|
vue: enableVue = VuePackages.some((i) => isPackageExists3(i))
|
|
1450
1425
|
} = 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
1426
|
const configs = [];
|
|
1455
1427
|
if (enableGitignore) {
|
|
1456
1428
|
if (typeof enableGitignore !== "boolean") {
|
|
1457
|
-
configs.push(
|
|
1429
|
+
configs.push(
|
|
1430
|
+
interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
|
|
1431
|
+
r(enableGitignore)
|
|
1432
|
+
])
|
|
1433
|
+
);
|
|
1458
1434
|
} else {
|
|
1459
1435
|
if (fs.existsSync(".gitignore"))
|
|
1460
|
-
configs.push(
|
|
1436
|
+
configs.push(
|
|
1437
|
+
interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
|
|
1438
|
+
r()
|
|
1439
|
+
])
|
|
1440
|
+
);
|
|
1461
1441
|
}
|
|
1462
1442
|
}
|
|
1463
1443
|
configs.push(
|
|
1464
1444
|
ignores(),
|
|
1465
1445
|
javascript({
|
|
1466
1446
|
isInEditor,
|
|
1467
|
-
overrides:
|
|
1447
|
+
overrides: getOverrides(options, "javascript")
|
|
1468
1448
|
}),
|
|
1469
1449
|
comments(),
|
|
1470
1450
|
node(),
|
|
1471
|
-
jsdoc(
|
|
1472
|
-
|
|
1473
|
-
}),
|
|
1474
|
-
imports({
|
|
1475
|
-
stylistic: stylisticOptions
|
|
1476
|
-
}),
|
|
1451
|
+
jsdoc(),
|
|
1452
|
+
imports(),
|
|
1477
1453
|
unicorn(),
|
|
1478
1454
|
// Optional plugins (installed but not enabled by default)
|
|
1479
1455
|
perfectionist()
|
|
@@ -1481,60 +1457,70 @@ async function coderwyd(options = {}, ...userConfigs) {
|
|
|
1481
1457
|
if (enableVue)
|
|
1482
1458
|
componentExts.push("vue");
|
|
1483
1459
|
if (enableTypeScript) {
|
|
1484
|
-
configs.push(
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1460
|
+
configs.push(
|
|
1461
|
+
typescript({
|
|
1462
|
+
...resolveSubOptions(options, "typescript"),
|
|
1463
|
+
componentExts
|
|
1464
|
+
})
|
|
1465
|
+
);
|
|
1489
1466
|
}
|
|
1490
|
-
if (stylisticOptions)
|
|
1491
|
-
configs.push(stylistic(stylisticOptions));
|
|
1492
1467
|
if (options.test ?? true) {
|
|
1493
|
-
configs.push(
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1468
|
+
configs.push(
|
|
1469
|
+
test({
|
|
1470
|
+
isInEditor,
|
|
1471
|
+
overrides: getOverrides(options, "test")
|
|
1472
|
+
})
|
|
1473
|
+
);
|
|
1497
1474
|
}
|
|
1498
1475
|
if (enableVue) {
|
|
1499
|
-
configs.push(
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1476
|
+
configs.push(
|
|
1477
|
+
vue({
|
|
1478
|
+
...resolveSubOptions(options, "vue"),
|
|
1479
|
+
typescript: !!enableTypeScript
|
|
1480
|
+
})
|
|
1481
|
+
);
|
|
1504
1482
|
}
|
|
1505
1483
|
if (enableReact) {
|
|
1506
|
-
configs.push(
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1484
|
+
configs.push(
|
|
1485
|
+
react({
|
|
1486
|
+
overrides: getOverrides(options, "react"),
|
|
1487
|
+
typescript: !!enableTypeScript
|
|
1488
|
+
})
|
|
1489
|
+
);
|
|
1510
1490
|
}
|
|
1511
1491
|
if (enableUnoCSS) {
|
|
1512
|
-
configs.push(
|
|
1513
|
-
|
|
1514
|
-
|
|
1492
|
+
configs.push(
|
|
1493
|
+
unocss({
|
|
1494
|
+
...resolveSubOptions(options, "unocss"),
|
|
1495
|
+
overrides: getOverrides(options, "unocss")
|
|
1496
|
+
})
|
|
1497
|
+
);
|
|
1515
1498
|
}
|
|
1516
1499
|
if (options.jsonc ?? true) {
|
|
1517
1500
|
configs.push(
|
|
1518
1501
|
jsonc({
|
|
1519
|
-
overrides:
|
|
1520
|
-
stylistic: stylisticOptions
|
|
1502
|
+
overrides: getOverrides(options, "jsonc")
|
|
1521
1503
|
}),
|
|
1522
1504
|
sortPackageJson(),
|
|
1523
1505
|
sortTsconfig()
|
|
1524
1506
|
);
|
|
1525
1507
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1508
|
+
let prettierRules2 = {
|
|
1509
|
+
...DEFAULT_PRETTIER_RULES
|
|
1510
|
+
};
|
|
1511
|
+
if (options.prettierRules) {
|
|
1512
|
+
prettierRules2 = { ...prettierRules2, ...options.prettierRules };
|
|
1531
1513
|
}
|
|
1532
|
-
if (
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1514
|
+
if (usePrettierrc) {
|
|
1515
|
+
const prettierConfig = await loadPrettierConfig(
|
|
1516
|
+
options.cwd ?? process3.cwd()
|
|
1517
|
+
);
|
|
1518
|
+
Object.assign(prettierRules2, prettierConfig);
|
|
1537
1519
|
}
|
|
1520
|
+
configs.push(
|
|
1521
|
+
prettier(prettierRules2),
|
|
1522
|
+
formatter(options.formatter, prettierRules2)
|
|
1523
|
+
);
|
|
1538
1524
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
1539
1525
|
if (key in options)
|
|
1540
1526
|
acc[key] = options[key];
|
|
@@ -1542,62 +1528,9 @@ async function coderwyd(options = {}, ...userConfigs) {
|
|
|
1542
1528
|
}, {});
|
|
1543
1529
|
if (Object.keys(fusedConfig).length)
|
|
1544
1530
|
configs.push([fusedConfig]);
|
|
1545
|
-
const merged = combine(
|
|
1546
|
-
...configs,
|
|
1547
|
-
...userConfigs
|
|
1548
|
-
);
|
|
1531
|
+
const merged = combine(...configs, ...userConfigs);
|
|
1549
1532
|
return merged;
|
|
1550
1533
|
}
|
|
1551
|
-
|
|
1552
|
-
// src/index.ts
|
|
1553
|
-
var src_default = coderwyd;
|
|
1554
1534
|
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
|
|
1535
|
+
defineConfig
|
|
1603
1536
|
};
|