@cany748/eslint-config 3.0.2 → 3.0.4
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/dist/index.cjs +112 -81
- package/dist/index.d.cts +788 -437
- package/dist/index.d.ts +788 -437
- package/dist/index.js +107 -78
- package/package.json +34 -33
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
GLOB_ALL_SRC: () => GLOB_ALL_SRC,
|
|
34
34
|
GLOB_ASTRO: () => GLOB_ASTRO,
|
|
35
35
|
GLOB_ASTRO_TS: () => GLOB_ASTRO_TS,
|
|
@@ -61,12 +61,14 @@ __export(src_exports, {
|
|
|
61
61
|
GLOB_YAML: () => GLOB_YAML,
|
|
62
62
|
combine: () => combine,
|
|
63
63
|
comments: () => comments,
|
|
64
|
+
disables: () => disables,
|
|
64
65
|
factoryConfig: () => factoryConfig,
|
|
65
66
|
formatters: () => formatters,
|
|
66
67
|
ignores: () => ignores,
|
|
67
68
|
imports: () => imports,
|
|
68
69
|
interopDefault: () => interopDefault,
|
|
69
70
|
isInEditorEnv: () => isInEditorEnv,
|
|
71
|
+
isInGitHooksOrLintStaged: () => isInGitHooksOrLintStaged,
|
|
70
72
|
javascript: () => javascript,
|
|
71
73
|
jsonc: () => jsonc,
|
|
72
74
|
node: () => node,
|
|
@@ -81,7 +83,7 @@ __export(src_exports, {
|
|
|
81
83
|
unocss: () => unocss,
|
|
82
84
|
vue: () => vue
|
|
83
85
|
});
|
|
84
|
-
module.exports = __toCommonJS(
|
|
86
|
+
module.exports = __toCommonJS(index_exports);
|
|
85
87
|
|
|
86
88
|
// src/configs/comments.ts
|
|
87
89
|
var import_eslint_plugin_eslint_comments = __toESM(require("@eslint-community/eslint-plugin-eslint-comments"), 1);
|
|
@@ -100,10 +102,6 @@ function comments() {
|
|
|
100
102
|
];
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
// src/configs/formatters.ts
|
|
104
|
-
var import_eslint_plugin_prettier = __toESM(require("eslint-plugin-prettier"), 1);
|
|
105
|
-
var import_recommended = __toESM(require("eslint-plugin-prettier/recommended"), 1);
|
|
106
|
-
|
|
107
105
|
// src/globs.ts
|
|
108
106
|
var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
109
107
|
var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
|
|
@@ -189,6 +187,63 @@ var GLOB_EXCLUDE = [
|
|
|
189
187
|
"**/components.d.ts"
|
|
190
188
|
];
|
|
191
189
|
|
|
190
|
+
// src/configs/disables.ts
|
|
191
|
+
function disables() {
|
|
192
|
+
return [
|
|
193
|
+
{
|
|
194
|
+
files: [`**/scripts/${GLOB_SRC}`],
|
|
195
|
+
name: "disables/scripts",
|
|
196
|
+
rules: {
|
|
197
|
+
"no-console": "off",
|
|
198
|
+
"@typescript-eslint/explicit-function-return-type": "off"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
|
|
203
|
+
name: "disables/cli",
|
|
204
|
+
rules: {
|
|
205
|
+
"no-console": "off"
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
files: ["**/*.d.?([cm])ts"],
|
|
210
|
+
name: "disables/dts",
|
|
211
|
+
rules: {
|
|
212
|
+
"@eslint-community/eslint-comments/no-unlimited-disable": "off",
|
|
213
|
+
"import/no-duplicates": "off",
|
|
214
|
+
"no-restricted-syntax": "off",
|
|
215
|
+
"unused-imports/no-unused-vars": "off"
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
files: ["**/*.{test,spec}.([tj])s?(x)"],
|
|
220
|
+
name: "disables/test",
|
|
221
|
+
rules: {
|
|
222
|
+
"no-unused-expressions": "off"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
files: ["**/*.js", "**/*.cjs"],
|
|
227
|
+
name: "disables/cjs",
|
|
228
|
+
rules: {
|
|
229
|
+
"@typescript-eslint/no-require-imports": "off"
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
files: [`**/*.config.${GLOB_SRC_EXT}`, `**/*.config.*.${GLOB_SRC_EXT}`],
|
|
234
|
+
name: "disables/config-files",
|
|
235
|
+
rules: {
|
|
236
|
+
"no-console": "off",
|
|
237
|
+
"@typescript-eslint/explicit-function-return-type": "off"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/configs/formatters.ts
|
|
244
|
+
var import_eslint_plugin_prettier = __toESM(require("eslint-plugin-prettier"), 1);
|
|
245
|
+
var import_recommended = __toESM(require("eslint-plugin-prettier/recommended"), 1);
|
|
246
|
+
|
|
192
247
|
// src/utils.ts
|
|
193
248
|
var parserPlain = {
|
|
194
249
|
meta: {
|
|
@@ -221,8 +276,14 @@ async function interopDefault(m) {
|
|
|
221
276
|
const resolved = await m;
|
|
222
277
|
return resolved.default || resolved;
|
|
223
278
|
}
|
|
279
|
+
function isInGitHooksOrLintStaged() {
|
|
280
|
+
return !!// eslint-disable-next-line no-constant-binary-expression
|
|
281
|
+
(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
|
|
282
|
+
}
|
|
224
283
|
function isInEditorEnv() {
|
|
225
|
-
|
|
284
|
+
if (process.env.CI) return false;
|
|
285
|
+
if (isInGitHooksOrLintStaged()) return false;
|
|
286
|
+
return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
|
|
226
287
|
}
|
|
227
288
|
|
|
228
289
|
// src/configs/formatters.ts
|
|
@@ -318,10 +379,10 @@ function formatters(options = true) {
|
|
|
318
379
|
}
|
|
319
380
|
|
|
320
381
|
// src/configs/ignores.ts
|
|
321
|
-
function ignores() {
|
|
382
|
+
function ignores(userIgnores = []) {
|
|
322
383
|
return [
|
|
323
384
|
{
|
|
324
|
-
ignores: GLOB_EXCLUDE
|
|
385
|
+
ignores: [...GLOB_EXCLUDE, ...userIgnores]
|
|
325
386
|
}
|
|
326
387
|
];
|
|
327
388
|
}
|
|
@@ -418,7 +479,6 @@ function javascript(options = {}) {
|
|
|
418
479
|
"no-dupe-else-if": "error",
|
|
419
480
|
"no-dupe-keys": "error",
|
|
420
481
|
"no-duplicate-case": "error",
|
|
421
|
-
"no-duplicate-imports": "error",
|
|
422
482
|
"no-empty-character-class": "error",
|
|
423
483
|
"no-empty-pattern": "error",
|
|
424
484
|
"no-empty-static-block": "error",
|
|
@@ -526,13 +586,7 @@ function javascript(options = {}) {
|
|
|
526
586
|
allowUnboundThis: true
|
|
527
587
|
}
|
|
528
588
|
],
|
|
529
|
-
"prefer-const": [
|
|
530
|
-
"error",
|
|
531
|
-
{
|
|
532
|
-
destructuring: "all",
|
|
533
|
-
ignoreReadBeforeAssign: true
|
|
534
|
-
}
|
|
535
|
-
],
|
|
589
|
+
"prefer-const": isInEditor ? "warn" : ["error", { destructuring: "all", ignoreReadBeforeAssign: true }],
|
|
536
590
|
"prefer-exponentiation-operator": "error",
|
|
537
591
|
"prefer-promise-reject-errors": "error",
|
|
538
592
|
"prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
|
|
@@ -553,7 +607,7 @@ function javascript(options = {}) {
|
|
|
553
607
|
],
|
|
554
608
|
"symbol-description": "error",
|
|
555
609
|
"unicode-bom": ["error", "never"],
|
|
556
|
-
"unused-imports/no-unused-imports": isInEditor ? "
|
|
610
|
+
"unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
|
|
557
611
|
"unused-imports/no-unused-vars": [
|
|
558
612
|
"error",
|
|
559
613
|
{
|
|
@@ -570,20 +624,6 @@ function javascript(options = {}) {
|
|
|
570
624
|
yoda: ["error", "never"],
|
|
571
625
|
...overrides
|
|
572
626
|
}
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
|
|
576
|
-
name: "javascript/disables/cli",
|
|
577
|
-
rules: {
|
|
578
|
-
"no-console": "off"
|
|
579
|
-
}
|
|
580
|
-
},
|
|
581
|
-
{
|
|
582
|
-
files: ["**/*.{test,spec}.js?(x)"],
|
|
583
|
-
name: "javascript/disables/test",
|
|
584
|
-
rules: {
|
|
585
|
-
"no-unused-expressions": "off"
|
|
586
|
-
}
|
|
587
627
|
}
|
|
588
628
|
];
|
|
589
629
|
}
|
|
@@ -641,6 +681,23 @@ function node() {
|
|
|
641
681
|
];
|
|
642
682
|
}
|
|
643
683
|
|
|
684
|
+
// src/configs/regexp.ts
|
|
685
|
+
var import_eslint_plugin_regexp = require("eslint-plugin-regexp");
|
|
686
|
+
function regexp(options = {}) {
|
|
687
|
+
const config = import_eslint_plugin_regexp.configs["flat/recommended"];
|
|
688
|
+
return [
|
|
689
|
+
{
|
|
690
|
+
...config,
|
|
691
|
+
name: "regexp",
|
|
692
|
+
rules: {
|
|
693
|
+
...config.rules,
|
|
694
|
+
"regexp/no-obscure-range": "off",
|
|
695
|
+
...options.overrides
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
];
|
|
699
|
+
}
|
|
700
|
+
|
|
644
701
|
// src/configs/sort.ts
|
|
645
702
|
function sortPackageJson() {
|
|
646
703
|
return [
|
|
@@ -887,9 +944,11 @@ async function test(options = {}) {
|
|
|
887
944
|
"test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
|
|
888
945
|
"test/no-identical-title": "error",
|
|
889
946
|
"test/no-import-node-test": "error",
|
|
890
|
-
"test/no-only-tests": isInEditor ? "
|
|
947
|
+
"test/no-only-tests": isInEditor ? "warn" : "error",
|
|
891
948
|
"test/prefer-hooks-in-order": "error",
|
|
892
949
|
"test/prefer-lowercase-title": "error",
|
|
950
|
+
"no-unused-expressions": "off",
|
|
951
|
+
"n/prefer-global/process": "off",
|
|
893
952
|
"@typescript-eslint/explicit-function-return-type": "off",
|
|
894
953
|
...overrides
|
|
895
954
|
}
|
|
@@ -969,7 +1028,7 @@ async function typescript(options = {}) {
|
|
|
969
1028
|
"no-invalid-this": "off",
|
|
970
1029
|
"@typescript-eslint/no-invalid-this": "error",
|
|
971
1030
|
"no-redeclare": "off",
|
|
972
|
-
"@typescript-eslint/no-redeclare": "error",
|
|
1031
|
+
"@typescript-eslint/no-redeclare": ["error", { builtinGlobals: false }],
|
|
973
1032
|
"no-unused-expressions": "off",
|
|
974
1033
|
"@typescript-eslint/no-unused-expressions": ["error", { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true }],
|
|
975
1034
|
"no-use-before-define": "off",
|
|
@@ -1007,32 +1066,7 @@ async function typescript(options = {}) {
|
|
|
1007
1066
|
...overridesTypeAware
|
|
1008
1067
|
}
|
|
1009
1068
|
}
|
|
1010
|
-
] : []
|
|
1011
|
-
{
|
|
1012
|
-
files: ["**/*.d.?([cm])ts"],
|
|
1013
|
-
name: "typescript/disables/dts",
|
|
1014
|
-
rules: {
|
|
1015
|
-
"eslint-comments/no-unlimited-disable": "off",
|
|
1016
|
-
"import/no-duplicates": "off",
|
|
1017
|
-
"no-restricted-syntax": "off",
|
|
1018
|
-
"unused-imports/no-unused-vars": "off"
|
|
1019
|
-
}
|
|
1020
|
-
},
|
|
1021
|
-
{
|
|
1022
|
-
files: ["**/*.{test,spec}.ts?(x)"],
|
|
1023
|
-
name: "typescript/disables/test",
|
|
1024
|
-
rules: {
|
|
1025
|
-
"no-unused-expressions": "off"
|
|
1026
|
-
}
|
|
1027
|
-
},
|
|
1028
|
-
{
|
|
1029
|
-
files: ["**/*.js", "**/*.cjs"],
|
|
1030
|
-
name: "typescript/disables/cjs",
|
|
1031
|
-
rules: {
|
|
1032
|
-
"@typescript-eslint/no-require-imports": "off",
|
|
1033
|
-
"@typescript-eslint/no-var-requires": "off"
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1069
|
+
] : []
|
|
1036
1070
|
];
|
|
1037
1071
|
}
|
|
1038
1072
|
|
|
@@ -1049,9 +1083,11 @@ function unicorn() {
|
|
|
1049
1083
|
...import_eslint_plugin_unicorn.default.configs["flat/recommended"].rules,
|
|
1050
1084
|
"unicorn/consistent-function-scoping": "off",
|
|
1051
1085
|
"unicorn/filename-case": "off",
|
|
1086
|
+
"unicorn/import-style": "off",
|
|
1052
1087
|
"unicorn/no-array-callback-reference": "off",
|
|
1053
1088
|
"unicorn/no-null": "off",
|
|
1054
1089
|
"unicorn/prefer-string-replace-all": "off",
|
|
1090
|
+
"unicorn/prefer-structured-clone": "off",
|
|
1055
1091
|
"unicorn/prefer-top-level-await": "off",
|
|
1056
1092
|
"unicorn/prevent-abbreviations": "off"
|
|
1057
1093
|
}
|
|
@@ -1150,35 +1186,18 @@ async function vue(options = {}) {
|
|
|
1150
1186
|
"vue/prefer-template": "error",
|
|
1151
1187
|
"vue/padding-line-between-blocks": ["error", "always"],
|
|
1152
1188
|
"vue/component-tags-order": "off",
|
|
1189
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
1153
1190
|
...overrides
|
|
1154
1191
|
}
|
|
1155
1192
|
}
|
|
1156
1193
|
];
|
|
1157
1194
|
}
|
|
1158
1195
|
|
|
1159
|
-
// src/configs/regexp.ts
|
|
1160
|
-
var import_eslint_plugin_regexp = require("eslint-plugin-regexp");
|
|
1161
|
-
function regexp(options = {}) {
|
|
1162
|
-
const config = import_eslint_plugin_regexp.configs["flat/recommended"];
|
|
1163
|
-
return [
|
|
1164
|
-
{
|
|
1165
|
-
...config,
|
|
1166
|
-
name: "regexp",
|
|
1167
|
-
rules: {
|
|
1168
|
-
...config.rules,
|
|
1169
|
-
...options.overrides
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
];
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
1196
|
// src/factory.ts
|
|
1176
1197
|
var import_local_pkg = require("local-pkg");
|
|
1177
1198
|
var import_eslint_flat_config_utils = require("eslint-flat-config-utils");
|
|
1178
1199
|
var flatConfigProps = [
|
|
1179
1200
|
"name",
|
|
1180
|
-
"files",
|
|
1181
|
-
"ignores",
|
|
1182
1201
|
"languageOptions",
|
|
1183
1202
|
"linterOptions",
|
|
1184
1203
|
"processor",
|
|
@@ -1192,7 +1211,6 @@ var factoryConfig = function(options = {}, ...userConfigs) {
|
|
|
1192
1211
|
componentExts = [],
|
|
1193
1212
|
formatters: enableFormatters = true,
|
|
1194
1213
|
gitignore: enableGitignore = true,
|
|
1195
|
-
isInEditor = isInEditorEnv(),
|
|
1196
1214
|
jsonc: enableJSONC = true,
|
|
1197
1215
|
regexp: enableRegexp = true,
|
|
1198
1216
|
test: enableTest = true,
|
|
@@ -1200,6 +1218,11 @@ var factoryConfig = function(options = {}, ...userConfigs) {
|
|
|
1200
1218
|
unocss: enableUnoCSS = (0, import_local_pkg.isPackageExists)("unocss"),
|
|
1201
1219
|
vue: enableVue = VuePackages.some((i) => (0, import_local_pkg.isPackageExists)(i))
|
|
1202
1220
|
} = options;
|
|
1221
|
+
let isInEditor = options.isInEditor;
|
|
1222
|
+
if (isInEditor == null) {
|
|
1223
|
+
isInEditor = isInEditorEnv();
|
|
1224
|
+
if (isInEditor) console.log("[@cany748/eslint-config] Detected running in editor, some rules are disabled.");
|
|
1225
|
+
}
|
|
1203
1226
|
const configs2 = [];
|
|
1204
1227
|
if (enableGitignore) {
|
|
1205
1228
|
if (typeof enableGitignore === "boolean") {
|
|
@@ -1210,7 +1233,7 @@ var factoryConfig = function(options = {}, ...userConfigs) {
|
|
|
1210
1233
|
}
|
|
1211
1234
|
configs2.push(
|
|
1212
1235
|
comments(),
|
|
1213
|
-
ignores(),
|
|
1236
|
+
ignores(options.ignores),
|
|
1214
1237
|
imports(),
|
|
1215
1238
|
javascript({
|
|
1216
1239
|
isInEditor,
|
|
@@ -1259,6 +1282,12 @@ var factoryConfig = function(options = {}, ...userConfigs) {
|
|
|
1259
1282
|
if (enableFormatters) {
|
|
1260
1283
|
configs2.push(formatters(enableFormatters));
|
|
1261
1284
|
}
|
|
1285
|
+
configs2.push(disables());
|
|
1286
|
+
if ("files" in options) {
|
|
1287
|
+
throw new Error(
|
|
1288
|
+
'[@cany748/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.'
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1262
1291
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
1263
1292
|
if (key in options) acc[key] = options[key];
|
|
1264
1293
|
return acc;
|
|
@@ -1301,12 +1330,14 @@ var factoryConfig = function(options = {}, ...userConfigs) {
|
|
|
1301
1330
|
GLOB_YAML,
|
|
1302
1331
|
combine,
|
|
1303
1332
|
comments,
|
|
1333
|
+
disables,
|
|
1304
1334
|
factoryConfig,
|
|
1305
1335
|
formatters,
|
|
1306
1336
|
ignores,
|
|
1307
1337
|
imports,
|
|
1308
1338
|
interopDefault,
|
|
1309
1339
|
isInEditorEnv,
|
|
1340
|
+
isInGitHooksOrLintStaged,
|
|
1310
1341
|
javascript,
|
|
1311
1342
|
jsonc,
|
|
1312
1343
|
node,
|