@lincy/eslint-config 3.7.1 → 4.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 +65 -96
- package/dist/index.cjs +200 -119
- package/dist/index.d.cts +51 -55
- package/dist/index.d.ts +51 -55
- package/dist/index.js +206 -107
- package/package.json +14 -12
package/dist/index.js
CHANGED
|
@@ -2,32 +2,18 @@
|
|
|
2
2
|
import process2 from "process";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { isPackageExists } from "local-pkg";
|
|
5
|
-
import gitignore from "eslint-config-flat-gitignore";
|
|
6
5
|
|
|
7
6
|
// src/plugins.ts
|
|
8
7
|
import { default as default2 } from "eslint-plugin-antfu";
|
|
9
8
|
import { default as default3 } from "eslint-plugin-eslint-comments";
|
|
10
9
|
import * as pluginImport from "eslint-plugin-i";
|
|
11
|
-
import { default as default4 } from "eslint-plugin-
|
|
12
|
-
import
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as default7 } from "@stylistic/eslint-plugin";
|
|
16
|
-
import { default as default8 } from "@typescript-eslint/eslint-plugin";
|
|
17
|
-
import { default as default9 } from "eslint-plugin-unicorn";
|
|
18
|
-
import { default as default10 } from "eslint-plugin-unused-imports";
|
|
19
|
-
import { default as default11 } from "eslint-plugin-vue";
|
|
20
|
-
import * as pluginYaml from "eslint-plugin-yml";
|
|
21
|
-
import { default as default12 } from "eslint-plugin-no-only-tests";
|
|
22
|
-
import { default as default13 } from "eslint-plugin-vitest";
|
|
23
|
-
import { default as default14 } from "eslint-plugin-perfectionist";
|
|
24
|
-
import * as parserTs from "@typescript-eslint/parser";
|
|
25
|
-
import { default as default15 } from "vue-eslint-parser";
|
|
26
|
-
import { default as default16 } from "yaml-eslint-parser";
|
|
27
|
-
import { default as default17 } from "jsonc-eslint-parser";
|
|
10
|
+
import { default as default4 } from "eslint-plugin-n";
|
|
11
|
+
import { default as default5 } from "eslint-plugin-unicorn";
|
|
12
|
+
import { default as default6 } from "eslint-plugin-unused-imports";
|
|
13
|
+
import { default as default7 } from "eslint-plugin-perfectionist";
|
|
28
14
|
|
|
29
15
|
// src/configs/comments.ts
|
|
30
|
-
function comments() {
|
|
16
|
+
async function comments() {
|
|
31
17
|
return [
|
|
32
18
|
{
|
|
33
19
|
name: "eslint:comments",
|
|
@@ -108,7 +94,7 @@ var GLOB_EXCLUDE = [
|
|
|
108
94
|
];
|
|
109
95
|
|
|
110
96
|
// src/configs/ignores.ts
|
|
111
|
-
function ignores(options = {}) {
|
|
97
|
+
async function ignores(options = {}) {
|
|
112
98
|
const {
|
|
113
99
|
ignores: ignores2 = []
|
|
114
100
|
} = options;
|
|
@@ -123,7 +109,7 @@ function ignores(options = {}) {
|
|
|
123
109
|
}
|
|
124
110
|
|
|
125
111
|
// src/configs/imports.ts
|
|
126
|
-
function imports(options = {}) {
|
|
112
|
+
async function imports(options = {}) {
|
|
127
113
|
const {
|
|
128
114
|
stylistic: stylistic2 = true
|
|
129
115
|
} = options;
|
|
@@ -154,7 +140,7 @@ function imports(options = {}) {
|
|
|
154
140
|
|
|
155
141
|
// src/configs/javascript.ts
|
|
156
142
|
import globals from "globals";
|
|
157
|
-
function javascript(options = {}) {
|
|
143
|
+
async function javascript(options = {}) {
|
|
158
144
|
const {
|
|
159
145
|
isInEditor = false,
|
|
160
146
|
overrides = {}
|
|
@@ -186,7 +172,7 @@ function javascript(options = {}) {
|
|
|
186
172
|
name: "eslint:javascript",
|
|
187
173
|
plugins: {
|
|
188
174
|
"antfu": default2,
|
|
189
|
-
"unused-imports":
|
|
175
|
+
"unused-imports": default6
|
|
190
176
|
},
|
|
191
177
|
rules: {
|
|
192
178
|
"accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
|
|
@@ -375,8 +361,30 @@ function javascript(options = {}) {
|
|
|
375
361
|
];
|
|
376
362
|
}
|
|
377
363
|
|
|
364
|
+
// src/utils.ts
|
|
365
|
+
async function combine(...configs) {
|
|
366
|
+
const resolved = await Promise.all(configs);
|
|
367
|
+
return resolved.flat();
|
|
368
|
+
}
|
|
369
|
+
function renameRules(rules, from, to) {
|
|
370
|
+
return Object.fromEntries(
|
|
371
|
+
Object.entries(rules).map(([key, value]) => {
|
|
372
|
+
if (key.startsWith(from))
|
|
373
|
+
return [to + key.slice(from.length), value];
|
|
374
|
+
return [key, value];
|
|
375
|
+
})
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
function toArray(value) {
|
|
379
|
+
return Array.isArray(value) ? value : [value];
|
|
380
|
+
}
|
|
381
|
+
async function interopDefault(m) {
|
|
382
|
+
const resolved = await m;
|
|
383
|
+
return resolved.default || resolved;
|
|
384
|
+
}
|
|
385
|
+
|
|
378
386
|
// src/configs/jsdoc.ts
|
|
379
|
-
function jsdoc(options = {}) {
|
|
387
|
+
async function jsdoc(options = {}) {
|
|
380
388
|
const {
|
|
381
389
|
stylistic: stylistic2 = true
|
|
382
390
|
} = options;
|
|
@@ -384,7 +392,8 @@ function jsdoc(options = {}) {
|
|
|
384
392
|
{
|
|
385
393
|
name: "eslint:jsdoc",
|
|
386
394
|
plugins: {
|
|
387
|
-
|
|
395
|
+
// @ts-expect-error missing types
|
|
396
|
+
jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
|
|
388
397
|
},
|
|
389
398
|
rules: {
|
|
390
399
|
"jsdoc/check-access": "warn",
|
|
@@ -412,11 +421,18 @@ function jsdoc(options = {}) {
|
|
|
412
421
|
}
|
|
413
422
|
|
|
414
423
|
// src/configs/jsonc.ts
|
|
415
|
-
function jsonc(options = {}) {
|
|
424
|
+
async function jsonc(options = {}) {
|
|
416
425
|
const {
|
|
417
426
|
overrides = {},
|
|
418
427
|
stylistic: stylistic2 = true
|
|
419
428
|
} = options;
|
|
429
|
+
const [
|
|
430
|
+
pluginJsonc,
|
|
431
|
+
parserJsonc
|
|
432
|
+
] = await Promise.all([
|
|
433
|
+
interopDefault(import("eslint-plugin-jsonc")),
|
|
434
|
+
interopDefault(import("jsonc-eslint-parser"))
|
|
435
|
+
]);
|
|
420
436
|
return [
|
|
421
437
|
{
|
|
422
438
|
name: "eslint:jsonc:setup",
|
|
@@ -427,7 +443,7 @@ function jsonc(options = {}) {
|
|
|
427
443
|
{
|
|
428
444
|
files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
|
|
429
445
|
languageOptions: {
|
|
430
|
-
parser:
|
|
446
|
+
parser: parserJsonc
|
|
431
447
|
},
|
|
432
448
|
name: "eslint:jsonc:rules",
|
|
433
449
|
rules: {
|
|
@@ -476,7 +492,7 @@ function jsonc(options = {}) {
|
|
|
476
492
|
}
|
|
477
493
|
|
|
478
494
|
// src/configs/markdown.ts
|
|
479
|
-
function markdown(options = {}) {
|
|
495
|
+
async function markdown(options = {}) {
|
|
480
496
|
const {
|
|
481
497
|
componentExts = [],
|
|
482
498
|
overrides = {}
|
|
@@ -485,7 +501,8 @@ function markdown(options = {}) {
|
|
|
485
501
|
{
|
|
486
502
|
name: "eslint:markdown:setup",
|
|
487
503
|
plugins: {
|
|
488
|
-
|
|
504
|
+
// @ts-expect-error missing types
|
|
505
|
+
markdown: await interopDefault(import("eslint-plugin-markdown"))
|
|
489
506
|
}
|
|
490
507
|
},
|
|
491
508
|
{
|
|
@@ -557,12 +574,12 @@ function markdown(options = {}) {
|
|
|
557
574
|
}
|
|
558
575
|
|
|
559
576
|
// src/configs/node.ts
|
|
560
|
-
function node() {
|
|
577
|
+
async function node() {
|
|
561
578
|
return [
|
|
562
579
|
{
|
|
563
580
|
name: "eslint:node",
|
|
564
581
|
plugins: {
|
|
565
|
-
node:
|
|
582
|
+
node: default4
|
|
566
583
|
},
|
|
567
584
|
rules: {
|
|
568
585
|
"node/handle-callback-err": ["error", "^(err|error)$"],
|
|
@@ -579,7 +596,7 @@ function node() {
|
|
|
579
596
|
}
|
|
580
597
|
|
|
581
598
|
// src/configs/sort.ts
|
|
582
|
-
function sortPackageJson() {
|
|
599
|
+
async function sortPackageJson() {
|
|
583
600
|
return [
|
|
584
601
|
{
|
|
585
602
|
files: ["**/package.json"],
|
|
@@ -795,7 +812,7 @@ function sortTsconfig() {
|
|
|
795
812
|
}
|
|
796
813
|
|
|
797
814
|
// src/configs/stylistic.ts
|
|
798
|
-
function stylistic(options = {}) {
|
|
815
|
+
async function stylistic(options = {}) {
|
|
799
816
|
const {
|
|
800
817
|
overrides = {},
|
|
801
818
|
stylistic: stylistic2 = {}
|
|
@@ -805,12 +822,13 @@ function stylistic(options = {}) {
|
|
|
805
822
|
jsx = true,
|
|
806
823
|
quotes = "single"
|
|
807
824
|
} = typeof stylistic2 === "boolean" ? {} : stylistic2;
|
|
825
|
+
const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
|
|
808
826
|
return [
|
|
809
827
|
{
|
|
810
828
|
name: "eslint:stylistic",
|
|
811
829
|
plugins: {
|
|
812
830
|
antfu: default2,
|
|
813
|
-
style:
|
|
831
|
+
style: pluginStylistic
|
|
814
832
|
},
|
|
815
833
|
rules: {
|
|
816
834
|
"antfu/consistent-list-newline": "off",
|
|
@@ -853,6 +871,8 @@ function stylistic(options = {}) {
|
|
|
853
871
|
"JSXText",
|
|
854
872
|
"JSXEmptyExpression",
|
|
855
873
|
"JSXSpreadChild",
|
|
874
|
+
"TSUnionType",
|
|
875
|
+
"TSIntersectionType",
|
|
856
876
|
"TSTypeParameterInstantiation",
|
|
857
877
|
"FunctionExpression > .params[decorators.length > 0]",
|
|
858
878
|
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
|
|
@@ -930,9 +950,13 @@ function stylistic(options = {}) {
|
|
|
930
950
|
"style/jsx-first-prop-new-line": "error",
|
|
931
951
|
"style/jsx-indent": ["error", indent, { checkAttributes: true, indentLogicalExpressions: true }],
|
|
932
952
|
"style/jsx-indent-props": ["error", indent],
|
|
933
|
-
"style/jsx-max-props-per-line": ["error", { maximum: 1
|
|
953
|
+
"style/jsx-max-props-per-line": ["error", { maximum: 1 }],
|
|
954
|
+
// 在 JSX 中的单行上强制执行最多 props 数量
|
|
955
|
+
"style/jsx-newline": "off",
|
|
956
|
+
// 在 jsx 元素和表达式之后换行
|
|
934
957
|
"style/jsx-one-expression-per-line": ["error", { allow: "single-child" }],
|
|
935
|
-
"style/jsx-quotes": "error",
|
|
958
|
+
"style/jsx-quotes": ["error", "prefer-double"],
|
|
959
|
+
// 强制在 JSX 属性中一致使用双引号或单引号
|
|
936
960
|
"style/jsx-tag-spacing": ["error", {
|
|
937
961
|
afterOpening: "never",
|
|
938
962
|
beforeClosing: "never",
|
|
@@ -957,26 +981,7 @@ function stylistic(options = {}) {
|
|
|
957
981
|
|
|
958
982
|
// src/configs/typescript.ts
|
|
959
983
|
import process from "process";
|
|
960
|
-
|
|
961
|
-
// src/utils.ts
|
|
962
|
-
function combine(...configs) {
|
|
963
|
-
return configs.flat();
|
|
964
|
-
}
|
|
965
|
-
function renameRules(rules, from, to) {
|
|
966
|
-
return Object.fromEntries(
|
|
967
|
-
Object.entries(rules).map(([key, value]) => {
|
|
968
|
-
if (key.startsWith(from))
|
|
969
|
-
return [to + key.slice(from.length), value];
|
|
970
|
-
return [key, value];
|
|
971
|
-
})
|
|
972
|
-
);
|
|
973
|
-
}
|
|
974
|
-
function toArray(value) {
|
|
975
|
-
return Array.isArray(value) ? value : [value];
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// src/configs/typescript.ts
|
|
979
|
-
function typescript(options) {
|
|
984
|
+
async function typescript(options) {
|
|
980
985
|
const {
|
|
981
986
|
componentExts = [],
|
|
982
987
|
overrides = {},
|
|
@@ -1004,14 +1009,20 @@ function typescript(options) {
|
|
|
1004
1009
|
"ts/unbound-method": "error"
|
|
1005
1010
|
};
|
|
1006
1011
|
const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
|
|
1012
|
+
const [
|
|
1013
|
+
pluginTs,
|
|
1014
|
+
parserTs
|
|
1015
|
+
] = await Promise.all([
|
|
1016
|
+
interopDefault(import("@typescript-eslint/eslint-plugin")),
|
|
1017
|
+
interopDefault(import("@typescript-eslint/parser"))
|
|
1018
|
+
]);
|
|
1007
1019
|
return [
|
|
1008
1020
|
{
|
|
1009
1021
|
// Install the plugins without globs, so they can be configured separately.
|
|
1010
1022
|
name: "eslint:typescript:setup",
|
|
1011
1023
|
plugins: {
|
|
1012
1024
|
antfu: default2,
|
|
1013
|
-
|
|
1014
|
-
ts: default8
|
|
1025
|
+
ts: pluginTs
|
|
1015
1026
|
}
|
|
1016
1027
|
},
|
|
1017
1028
|
{
|
|
@@ -1034,12 +1045,12 @@ function typescript(options) {
|
|
|
1034
1045
|
name: "eslint:typescript:rules",
|
|
1035
1046
|
rules: {
|
|
1036
1047
|
...renameRules(
|
|
1037
|
-
|
|
1048
|
+
pluginTs.configs["eslint-recommended"].overrides[0].rules,
|
|
1038
1049
|
"@typescript-eslint/",
|
|
1039
1050
|
"ts/"
|
|
1040
1051
|
),
|
|
1041
1052
|
...renameRules(
|
|
1042
|
-
|
|
1053
|
+
pluginTs.configs.strict.rules,
|
|
1043
1054
|
"@typescript-eslint/",
|
|
1044
1055
|
"ts/"
|
|
1045
1056
|
),
|
|
@@ -1105,12 +1116,12 @@ function typescript(options) {
|
|
|
1105
1116
|
}
|
|
1106
1117
|
|
|
1107
1118
|
// src/configs/unicorn.ts
|
|
1108
|
-
function unicorn() {
|
|
1119
|
+
async function unicorn() {
|
|
1109
1120
|
return [
|
|
1110
1121
|
{
|
|
1111
1122
|
name: "eslint:unicorn",
|
|
1112
1123
|
plugins: {
|
|
1113
|
-
unicorn:
|
|
1124
|
+
unicorn: default5
|
|
1114
1125
|
},
|
|
1115
1126
|
rules: {
|
|
1116
1127
|
// Pass error message when throwing errors
|
|
@@ -1152,7 +1163,7 @@ var pkg = getPackageInfoSync("vue");
|
|
|
1152
1163
|
var vueVersion = pkg && pkg.version;
|
|
1153
1164
|
vueVersion = vueVersion && vueVersion[0];
|
|
1154
1165
|
vueVersion = Number.isNaN(vueVersion) ? "3" : vueVersion;
|
|
1155
|
-
function vue(options = {}) {
|
|
1166
|
+
async function vue(options = {}) {
|
|
1156
1167
|
const {
|
|
1157
1168
|
overrides = {},
|
|
1158
1169
|
stylistic: stylistic2 = true
|
|
@@ -1160,38 +1171,46 @@ function vue(options = {}) {
|
|
|
1160
1171
|
const {
|
|
1161
1172
|
indent = 4
|
|
1162
1173
|
} = typeof stylistic2 === "boolean" ? {} : stylistic2;
|
|
1174
|
+
const [
|
|
1175
|
+
pluginVue,
|
|
1176
|
+
parserVue
|
|
1177
|
+
] = await Promise.all([
|
|
1178
|
+
// @ts-expect-error missing types
|
|
1179
|
+
interopDefault(import("eslint-plugin-vue")),
|
|
1180
|
+
interopDefault(import("vue-eslint-parser"))
|
|
1181
|
+
]);
|
|
1163
1182
|
return [
|
|
1164
1183
|
{
|
|
1165
1184
|
name: "eslint:vue:setup",
|
|
1166
1185
|
plugins: {
|
|
1167
|
-
vue:
|
|
1186
|
+
vue: pluginVue
|
|
1168
1187
|
}
|
|
1169
1188
|
},
|
|
1170
1189
|
{
|
|
1171
1190
|
files: [GLOB_VUE],
|
|
1172
1191
|
languageOptions: {
|
|
1173
|
-
parser:
|
|
1192
|
+
parser: parserVue,
|
|
1174
1193
|
parserOptions: {
|
|
1175
1194
|
ecmaFeatures: {
|
|
1176
1195
|
jsx: true
|
|
1177
1196
|
},
|
|
1178
1197
|
extraFileExtensions: [".vue"],
|
|
1179
|
-
parser: options.typescript ?
|
|
1198
|
+
parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
|
|
1180
1199
|
sourceType: "module"
|
|
1181
1200
|
}
|
|
1182
1201
|
},
|
|
1183
1202
|
name: "eslint:vue:rules",
|
|
1184
|
-
processor:
|
|
1203
|
+
processor: pluginVue.processors[".vue"],
|
|
1185
1204
|
rules: {
|
|
1186
|
-
...
|
|
1205
|
+
...pluginVue.configs.base.rules,
|
|
1187
1206
|
...vueVersion === "3" ? {
|
|
1188
|
-
...
|
|
1189
|
-
...
|
|
1190
|
-
...
|
|
1207
|
+
...pluginVue.configs["vue3-essential"].rules,
|
|
1208
|
+
...pluginVue.configs["vue3-strongly-recommended"].rules,
|
|
1209
|
+
...pluginVue.configs["vue3-recommended"].rules
|
|
1191
1210
|
} : {
|
|
1192
|
-
...
|
|
1193
|
-
...
|
|
1194
|
-
...
|
|
1211
|
+
...pluginVue.configs.essential.rules,
|
|
1212
|
+
...pluginVue.configs["strongly-recommended"].rules,
|
|
1213
|
+
...pluginVue.configs.recommended.rules
|
|
1195
1214
|
},
|
|
1196
1215
|
"node/prefer-global/process": "off",
|
|
1197
1216
|
"vue/block-order": ["error", {
|
|
@@ -1285,11 +1304,18 @@ function vue(options = {}) {
|
|
|
1285
1304
|
}
|
|
1286
1305
|
|
|
1287
1306
|
// src/configs/yaml.ts
|
|
1288
|
-
function yaml(options = {}) {
|
|
1307
|
+
async function yaml(options = {}) {
|
|
1289
1308
|
const {
|
|
1290
1309
|
overrides = {},
|
|
1291
1310
|
stylistic: stylistic2 = true
|
|
1292
1311
|
} = options;
|
|
1312
|
+
const [
|
|
1313
|
+
pluginYaml,
|
|
1314
|
+
parserYaml
|
|
1315
|
+
] = await Promise.all([
|
|
1316
|
+
interopDefault(import("eslint-plugin-yml")),
|
|
1317
|
+
interopDefault(import("yaml-eslint-parser"))
|
|
1318
|
+
]);
|
|
1293
1319
|
return [
|
|
1294
1320
|
{
|
|
1295
1321
|
name: "eslint:yaml:setup",
|
|
@@ -1300,7 +1326,7 @@ function yaml(options = {}) {
|
|
|
1300
1326
|
{
|
|
1301
1327
|
files: [GLOB_YAML],
|
|
1302
1328
|
languageOptions: {
|
|
1303
|
-
parser:
|
|
1329
|
+
parser: parserYaml
|
|
1304
1330
|
},
|
|
1305
1331
|
name: "eslint:yaml:rules",
|
|
1306
1332
|
rules: {
|
|
@@ -1332,21 +1358,29 @@ function yaml(options = {}) {
|
|
|
1332
1358
|
}
|
|
1333
1359
|
|
|
1334
1360
|
// src/configs/test.ts
|
|
1335
|
-
function test(options = {}) {
|
|
1361
|
+
async function test(options = {}) {
|
|
1336
1362
|
const {
|
|
1337
1363
|
isInEditor = false,
|
|
1338
1364
|
overrides = {}
|
|
1339
1365
|
} = options;
|
|
1366
|
+
const [
|
|
1367
|
+
pluginVitest,
|
|
1368
|
+
pluginNoOnlyTests
|
|
1369
|
+
] = await Promise.all([
|
|
1370
|
+
interopDefault(import("eslint-plugin-vitest")),
|
|
1371
|
+
// @ts-expect-error missing types
|
|
1372
|
+
interopDefault(import("eslint-plugin-no-only-tests"))
|
|
1373
|
+
]);
|
|
1340
1374
|
return [
|
|
1341
1375
|
{
|
|
1342
1376
|
name: "eslint:test:setup",
|
|
1343
1377
|
plugins: {
|
|
1344
1378
|
test: {
|
|
1345
|
-
...
|
|
1379
|
+
...pluginVitest,
|
|
1346
1380
|
rules: {
|
|
1347
|
-
...
|
|
1381
|
+
...pluginVitest.rules,
|
|
1348
1382
|
// extend `test/no-only-tests` rule
|
|
1349
|
-
...
|
|
1383
|
+
...pluginNoOnlyTests.rules
|
|
1350
1384
|
}
|
|
1351
1385
|
}
|
|
1352
1386
|
}
|
|
@@ -1368,12 +1402,82 @@ function test(options = {}) {
|
|
|
1368
1402
|
}
|
|
1369
1403
|
|
|
1370
1404
|
// src/configs/perfectionist.ts
|
|
1371
|
-
function perfectionist() {
|
|
1405
|
+
async function perfectionist() {
|
|
1372
1406
|
return [
|
|
1373
1407
|
{
|
|
1374
1408
|
name: "eslint:perfectionist",
|
|
1375
1409
|
plugins: {
|
|
1376
|
-
perfectionist:
|
|
1410
|
+
perfectionist: default7
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
];
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// src/configs/react.ts
|
|
1417
|
+
async function react(options = {}) {
|
|
1418
|
+
const {
|
|
1419
|
+
jsx = true,
|
|
1420
|
+
overrides = {},
|
|
1421
|
+
version = "17.0"
|
|
1422
|
+
} = options;
|
|
1423
|
+
const [
|
|
1424
|
+
pluginReact,
|
|
1425
|
+
pluginReactHooks
|
|
1426
|
+
] = await Promise.all([
|
|
1427
|
+
// @ts-expect-error missing types
|
|
1428
|
+
interopDefault(import("eslint-plugin-react")),
|
|
1429
|
+
// @ts-expect-error missing types
|
|
1430
|
+
interopDefault(import("eslint-plugin-react-hooks"))
|
|
1431
|
+
]);
|
|
1432
|
+
return [
|
|
1433
|
+
{
|
|
1434
|
+
name: "eslint:react:setup",
|
|
1435
|
+
plugins: {
|
|
1436
|
+
"react": pluginReact,
|
|
1437
|
+
"react-hooks": pluginReactHooks
|
|
1438
|
+
}
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
files: [GLOB_JSX, GLOB_TSX],
|
|
1442
|
+
languageOptions: {
|
|
1443
|
+
parserOptions: {
|
|
1444
|
+
ecmaFeatures: {
|
|
1445
|
+
jsx
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
name: "eslint:react:rules",
|
|
1450
|
+
rules: {
|
|
1451
|
+
...pluginReact.configs.all.rules,
|
|
1452
|
+
...pluginReactHooks.configs.recommended.rules,
|
|
1453
|
+
"react/forbid-component-props": "off",
|
|
1454
|
+
// 禁止组件上使用某些 props
|
|
1455
|
+
"react/hook-use-state": "off",
|
|
1456
|
+
// useState 钩子值和 setter 变量的解构和对称命名
|
|
1457
|
+
"react/jsx-filename-extension": "off",
|
|
1458
|
+
// 禁止可能包含 JSX 文件扩展名
|
|
1459
|
+
"react/jsx-max-depth": "off",
|
|
1460
|
+
// 强制 JSX 最大深度
|
|
1461
|
+
"react/jsx-no-bind": "off",
|
|
1462
|
+
// .bind()JSX 属性中禁止使用箭头函数
|
|
1463
|
+
"react/jsx-no-literals": "off",
|
|
1464
|
+
// 禁止在 JSX 中使用字符串文字
|
|
1465
|
+
"react/jsx-props-no-spreading": "off",
|
|
1466
|
+
// 强制任何 JSX 属性都不会传播
|
|
1467
|
+
"react/no-danger": "off",
|
|
1468
|
+
// 禁止使用 dangerouslySetInnerHTML
|
|
1469
|
+
"react/no-unsafe": "off",
|
|
1470
|
+
// 禁止使用不安全的生命周期方法
|
|
1471
|
+
"react/react-in-jsx-scope": "off",
|
|
1472
|
+
// 使用 JSX 时需要引入 React
|
|
1473
|
+
"react/require-default-props": "off",
|
|
1474
|
+
// 为每个非必需 prop 强制执行 defaultProps 定义
|
|
1475
|
+
...overrides
|
|
1476
|
+
},
|
|
1477
|
+
settings: {
|
|
1478
|
+
react: {
|
|
1479
|
+
version
|
|
1480
|
+
}
|
|
1377
1481
|
}
|
|
1378
1482
|
}
|
|
1379
1483
|
];
|
|
@@ -1396,25 +1500,32 @@ var VuePackages = [
|
|
|
1396
1500
|
"vitepress",
|
|
1397
1501
|
"@slidev/cli"
|
|
1398
1502
|
];
|
|
1399
|
-
|
|
1503
|
+
var ReactPackages = [
|
|
1504
|
+
"react",
|
|
1505
|
+
"next"
|
|
1506
|
+
];
|
|
1507
|
+
async function lincy(options = {}, ...userConfigs) {
|
|
1400
1508
|
const {
|
|
1401
1509
|
componentExts = [],
|
|
1402
1510
|
gitignore: enableGitignore = true,
|
|
1403
1511
|
isInEditor = !!((process2.env.VSCODE_PID || process2.env.JETBRAINS_IDE) && !process2.env.CI),
|
|
1404
1512
|
overrides = {},
|
|
1513
|
+
react: enableReact = ReactPackages.some((i) => isPackageExists(i)),
|
|
1405
1514
|
typescript: enableTypeScript = isPackageExists("typescript"),
|
|
1406
1515
|
vue: enableVue = VuePackages.some((i) => isPackageExists(i))
|
|
1407
1516
|
} = options;
|
|
1408
1517
|
const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
1409
|
-
if (stylisticOptions
|
|
1410
|
-
|
|
1518
|
+
if (stylisticOptions) {
|
|
1519
|
+
if (!("jsx" in stylisticOptions))
|
|
1520
|
+
stylisticOptions.jsx = options.jsx ?? true;
|
|
1521
|
+
}
|
|
1411
1522
|
const configs = [];
|
|
1412
1523
|
if (enableGitignore) {
|
|
1413
1524
|
if (typeof enableGitignore !== "boolean") {
|
|
1414
|
-
configs.push(
|
|
1525
|
+
configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
|
|
1415
1526
|
} else {
|
|
1416
1527
|
if (fs.existsSync(".gitignore"))
|
|
1417
|
-
configs.push(
|
|
1528
|
+
configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
|
|
1418
1529
|
}
|
|
1419
1530
|
}
|
|
1420
1531
|
configs.push(
|
|
@@ -1465,6 +1576,12 @@ function lincy(options = {}, ...userConfigs) {
|
|
|
1465
1576
|
typescript: !!enableTypeScript
|
|
1466
1577
|
}));
|
|
1467
1578
|
}
|
|
1579
|
+
if (enableReact) {
|
|
1580
|
+
configs.push(react({
|
|
1581
|
+
overrides: overrides.react,
|
|
1582
|
+
...typeof enableReact !== "boolean" ? enableReact : {}
|
|
1583
|
+
}));
|
|
1584
|
+
}
|
|
1468
1585
|
if (options.jsonc ?? true) {
|
|
1469
1586
|
configs.push(
|
|
1470
1587
|
jsonc({
|
|
@@ -1530,33 +1647,15 @@ export {
|
|
|
1530
1647
|
src_default as default,
|
|
1531
1648
|
ignores,
|
|
1532
1649
|
imports,
|
|
1650
|
+
interopDefault,
|
|
1533
1651
|
javascript,
|
|
1534
1652
|
jsdoc,
|
|
1535
1653
|
jsonc,
|
|
1536
1654
|
lincy,
|
|
1537
1655
|
markdown,
|
|
1538
1656
|
node,
|
|
1539
|
-
default17 as parserJsonc,
|
|
1540
|
-
parserTs,
|
|
1541
|
-
default15 as parserVue,
|
|
1542
|
-
default16 as parserYaml,
|
|
1543
1657
|
perfectionist,
|
|
1544
|
-
|
|
1545
|
-
default3 as pluginComments,
|
|
1546
|
-
pluginImport,
|
|
1547
|
-
default4 as pluginJsdoc,
|
|
1548
|
-
pluginJsonc,
|
|
1549
|
-
default5 as pluginMarkdown,
|
|
1550
|
-
default12 as pluginNoOnlyTests,
|
|
1551
|
-
default6 as pluginNode,
|
|
1552
|
-
default14 as pluginPerfectionist,
|
|
1553
|
-
default7 as pluginStylistic,
|
|
1554
|
-
default8 as pluginTs,
|
|
1555
|
-
default9 as pluginUnicorn,
|
|
1556
|
-
default10 as pluginUnusedImports,
|
|
1557
|
-
default13 as pluginVitest,
|
|
1558
|
-
default11 as pluginVue,
|
|
1559
|
-
pluginYaml,
|
|
1658
|
+
react,
|
|
1560
1659
|
renameRules,
|
|
1561
1660
|
sortPackageJson,
|
|
1562
1661
|
sortTsconfig,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincy/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.1",
|
|
5
5
|
"packageManager": "pnpm@8.7.6",
|
|
6
6
|
"description": "LinCenYing's ESLint config",
|
|
7
7
|
"author": "LinCenYing <lincenying@gmail.com> (https://github.com/lincenying/)",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@antfu/eslint-define-config": "1.23.0-2",
|
|
43
|
-
"@stylistic/eslint-plugin": "1.
|
|
43
|
+
"@stylistic/eslint-plugin": "1.4.0",
|
|
44
44
|
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
45
45
|
"@typescript-eslint/parser": "^6.11.0",
|
|
46
46
|
"eslint-config-flat-gitignore": "^0.1.1",
|
|
47
|
-
"eslint-plugin-antfu": "^1.0.
|
|
47
|
+
"eslint-plugin-antfu": "^1.0.10",
|
|
48
48
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
49
49
|
"eslint-plugin-i": "^2.29.0",
|
|
50
50
|
"eslint-plugin-jsdoc": "^46.9.0",
|
|
@@ -52,10 +52,12 @@
|
|
|
52
52
|
"eslint-plugin-markdown": "^3.0.1",
|
|
53
53
|
"eslint-plugin-n": "^16.3.1",
|
|
54
54
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
55
|
-
"eslint-plugin-perfectionist": "^2.
|
|
55
|
+
"eslint-plugin-perfectionist": "^2.4.0",
|
|
56
|
+
"eslint-plugin-react": "^7.33.2",
|
|
57
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
56
58
|
"eslint-plugin-unicorn": "^49.0.0",
|
|
57
59
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
58
|
-
"eslint-plugin-vitest": "^0.3.
|
|
60
|
+
"eslint-plugin-vitest": "^0.3.10",
|
|
59
61
|
"eslint-plugin-vue": "^9.18.1",
|
|
60
62
|
"eslint-plugin-yml": "^1.10.0",
|
|
61
63
|
"globals": "^13.23.0",
|
|
@@ -66,23 +68,23 @@
|
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|
|
68
70
|
"@antfu/ni": "^0.21.9",
|
|
69
|
-
"@eslint-types/jsdoc": "46.
|
|
70
|
-
"@eslint-types/typescript-eslint": "^6.
|
|
71
|
+
"@eslint-types/jsdoc": "46.9.0",
|
|
72
|
+
"@eslint-types/typescript-eslint": "^6.11.0",
|
|
71
73
|
"@eslint-types/unicorn": "^49.0.0",
|
|
72
74
|
"@lincy/eslint-config": "workspace:*",
|
|
73
|
-
"@stylistic/eslint-plugin-migrate": "^1.
|
|
75
|
+
"@stylistic/eslint-plugin-migrate": "^1.4.0",
|
|
74
76
|
"@types/eslint": "^8.44.7",
|
|
75
|
-
"@types/node": "^20.9.
|
|
77
|
+
"@types/node": "^20.9.2",
|
|
76
78
|
"bumpp": "^9.2.0",
|
|
77
|
-
"eslint": "^8.
|
|
78
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
79
|
+
"eslint": "^8.54.0",
|
|
80
|
+
"eslint-flat-config-viewer": "^0.1.3",
|
|
79
81
|
"esno": "^4.0.0",
|
|
80
82
|
"lint-staged": "^15.1.0",
|
|
81
83
|
"rimraf": "^5.0.5",
|
|
82
84
|
"simple-git-hooks": "^2.9.0",
|
|
83
85
|
"simple-open-url": "^3.0.1",
|
|
84
86
|
"sucrase": "^3.34.0",
|
|
85
|
-
"tsup": "^
|
|
87
|
+
"tsup": "^8.0.0",
|
|
86
88
|
"typescript": "^5.2.2",
|
|
87
89
|
"unbuild": "^2.0.0",
|
|
88
90
|
"vitest": "^0.34.6"
|