@cany748/eslint-config 3.0.3 → 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 +111 -80
- package/dist/index.d.cts +630 -439
- package/dist/index.d.ts +630 -439
- package/dist/index.js +106 -77
- 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
|
}
|
|
@@ -525,13 +586,7 @@ function javascript(options = {}) {
|
|
|
525
586
|
allowUnboundThis: true
|
|
526
587
|
}
|
|
527
588
|
],
|
|
528
|
-
"prefer-const": [
|
|
529
|
-
"error",
|
|
530
|
-
{
|
|
531
|
-
destructuring: "all",
|
|
532
|
-
ignoreReadBeforeAssign: true
|
|
533
|
-
}
|
|
534
|
-
],
|
|
589
|
+
"prefer-const": isInEditor ? "warn" : ["error", { destructuring: "all", ignoreReadBeforeAssign: true }],
|
|
535
590
|
"prefer-exponentiation-operator": "error",
|
|
536
591
|
"prefer-promise-reject-errors": "error",
|
|
537
592
|
"prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
|
|
@@ -552,7 +607,7 @@ function javascript(options = {}) {
|
|
|
552
607
|
],
|
|
553
608
|
"symbol-description": "error",
|
|
554
609
|
"unicode-bom": ["error", "never"],
|
|
555
|
-
"unused-imports/no-unused-imports": isInEditor ? "
|
|
610
|
+
"unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
|
|
556
611
|
"unused-imports/no-unused-vars": [
|
|
557
612
|
"error",
|
|
558
613
|
{
|
|
@@ -569,20 +624,6 @@ function javascript(options = {}) {
|
|
|
569
624
|
yoda: ["error", "never"],
|
|
570
625
|
...overrides
|
|
571
626
|
}
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
|
|
575
|
-
name: "javascript/disables/cli",
|
|
576
|
-
rules: {
|
|
577
|
-
"no-console": "off"
|
|
578
|
-
}
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
files: ["**/*.{test,spec}.js?(x)"],
|
|
582
|
-
name: "javascript/disables/test",
|
|
583
|
-
rules: {
|
|
584
|
-
"no-unused-expressions": "off"
|
|
585
|
-
}
|
|
586
627
|
}
|
|
587
628
|
];
|
|
588
629
|
}
|
|
@@ -640,6 +681,23 @@ function node() {
|
|
|
640
681
|
];
|
|
641
682
|
}
|
|
642
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
|
+
|
|
643
701
|
// src/configs/sort.ts
|
|
644
702
|
function sortPackageJson() {
|
|
645
703
|
return [
|
|
@@ -886,9 +944,11 @@ async function test(options = {}) {
|
|
|
886
944
|
"test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
|
|
887
945
|
"test/no-identical-title": "error",
|
|
888
946
|
"test/no-import-node-test": "error",
|
|
889
|
-
"test/no-only-tests": isInEditor ? "
|
|
947
|
+
"test/no-only-tests": isInEditor ? "warn" : "error",
|
|
890
948
|
"test/prefer-hooks-in-order": "error",
|
|
891
949
|
"test/prefer-lowercase-title": "error",
|
|
950
|
+
"no-unused-expressions": "off",
|
|
951
|
+
"n/prefer-global/process": "off",
|
|
892
952
|
"@typescript-eslint/explicit-function-return-type": "off",
|
|
893
953
|
...overrides
|
|
894
954
|
}
|
|
@@ -968,7 +1028,7 @@ async function typescript(options = {}) {
|
|
|
968
1028
|
"no-invalid-this": "off",
|
|
969
1029
|
"@typescript-eslint/no-invalid-this": "error",
|
|
970
1030
|
"no-redeclare": "off",
|
|
971
|
-
"@typescript-eslint/no-redeclare": "error",
|
|
1031
|
+
"@typescript-eslint/no-redeclare": ["error", { builtinGlobals: false }],
|
|
972
1032
|
"no-unused-expressions": "off",
|
|
973
1033
|
"@typescript-eslint/no-unused-expressions": ["error", { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true }],
|
|
974
1034
|
"no-use-before-define": "off",
|
|
@@ -1006,32 +1066,7 @@ async function typescript(options = {}) {
|
|
|
1006
1066
|
...overridesTypeAware
|
|
1007
1067
|
}
|
|
1008
1068
|
}
|
|
1009
|
-
] : []
|
|
1010
|
-
{
|
|
1011
|
-
files: ["**/*.d.?([cm])ts"],
|
|
1012
|
-
name: "typescript/disables/dts",
|
|
1013
|
-
rules: {
|
|
1014
|
-
"eslint-comments/no-unlimited-disable": "off",
|
|
1015
|
-
"import/no-duplicates": "off",
|
|
1016
|
-
"no-restricted-syntax": "off",
|
|
1017
|
-
"unused-imports/no-unused-vars": "off"
|
|
1018
|
-
}
|
|
1019
|
-
},
|
|
1020
|
-
{
|
|
1021
|
-
files: ["**/*.{test,spec}.ts?(x)"],
|
|
1022
|
-
name: "typescript/disables/test",
|
|
1023
|
-
rules: {
|
|
1024
|
-
"no-unused-expressions": "off"
|
|
1025
|
-
}
|
|
1026
|
-
},
|
|
1027
|
-
{
|
|
1028
|
-
files: ["**/*.js", "**/*.cjs"],
|
|
1029
|
-
name: "typescript/disables/cjs",
|
|
1030
|
-
rules: {
|
|
1031
|
-
"@typescript-eslint/no-require-imports": "off",
|
|
1032
|
-
"@typescript-eslint/no-var-requires": "off"
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1069
|
+
] : []
|
|
1035
1070
|
];
|
|
1036
1071
|
}
|
|
1037
1072
|
|
|
@@ -1052,6 +1087,7 @@ function unicorn() {
|
|
|
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,
|