@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.js CHANGED
@@ -15,10 +15,6 @@ function comments() {
15
15
  ];
16
16
  }
17
17
 
18
- // src/configs/formatters.ts
19
- import pluginPrettier from "eslint-plugin-prettier";
20
- import configPrettier from "eslint-plugin-prettier/recommended";
21
-
22
18
  // src/globs.ts
23
19
  var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
24
20
  var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
@@ -104,6 +100,63 @@ var GLOB_EXCLUDE = [
104
100
  "**/components.d.ts"
105
101
  ];
106
102
 
103
+ // src/configs/disables.ts
104
+ function disables() {
105
+ return [
106
+ {
107
+ files: [`**/scripts/${GLOB_SRC}`],
108
+ name: "disables/scripts",
109
+ rules: {
110
+ "no-console": "off",
111
+ "@typescript-eslint/explicit-function-return-type": "off"
112
+ }
113
+ },
114
+ {
115
+ files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
116
+ name: "disables/cli",
117
+ rules: {
118
+ "no-console": "off"
119
+ }
120
+ },
121
+ {
122
+ files: ["**/*.d.?([cm])ts"],
123
+ name: "disables/dts",
124
+ rules: {
125
+ "@eslint-community/eslint-comments/no-unlimited-disable": "off",
126
+ "import/no-duplicates": "off",
127
+ "no-restricted-syntax": "off",
128
+ "unused-imports/no-unused-vars": "off"
129
+ }
130
+ },
131
+ {
132
+ files: ["**/*.{test,spec}.([tj])s?(x)"],
133
+ name: "disables/test",
134
+ rules: {
135
+ "no-unused-expressions": "off"
136
+ }
137
+ },
138
+ {
139
+ files: ["**/*.js", "**/*.cjs"],
140
+ name: "disables/cjs",
141
+ rules: {
142
+ "@typescript-eslint/no-require-imports": "off"
143
+ }
144
+ },
145
+ {
146
+ files: [`**/*.config.${GLOB_SRC_EXT}`, `**/*.config.*.${GLOB_SRC_EXT}`],
147
+ name: "disables/config-files",
148
+ rules: {
149
+ "no-console": "off",
150
+ "@typescript-eslint/explicit-function-return-type": "off"
151
+ }
152
+ }
153
+ ];
154
+ }
155
+
156
+ // src/configs/formatters.ts
157
+ import pluginPrettier from "eslint-plugin-prettier";
158
+ import configPrettier from "eslint-plugin-prettier/recommended";
159
+
107
160
  // src/utils.ts
108
161
  var parserPlain = {
109
162
  meta: {
@@ -136,8 +189,14 @@ async function interopDefault(m) {
136
189
  const resolved = await m;
137
190
  return resolved.default || resolved;
138
191
  }
192
+ function isInGitHooksOrLintStaged() {
193
+ return !!// eslint-disable-next-line no-constant-binary-expression
194
+ (process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
195
+ }
139
196
  function isInEditorEnv() {
140
- return !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM) && !process.env.CI);
197
+ if (process.env.CI) return false;
198
+ if (isInGitHooksOrLintStaged()) return false;
199
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
141
200
  }
142
201
 
143
202
  // src/configs/formatters.ts
@@ -233,10 +292,10 @@ function formatters(options = true) {
233
292
  }
234
293
 
235
294
  // src/configs/ignores.ts
236
- function ignores() {
295
+ function ignores(userIgnores = []) {
237
296
  return [
238
297
  {
239
- ignores: GLOB_EXCLUDE
298
+ ignores: [...GLOB_EXCLUDE, ...userIgnores]
240
299
  }
241
300
  ];
242
301
  }
@@ -333,7 +392,6 @@ function javascript(options = {}) {
333
392
  "no-dupe-else-if": "error",
334
393
  "no-dupe-keys": "error",
335
394
  "no-duplicate-case": "error",
336
- "no-duplicate-imports": "error",
337
395
  "no-empty-character-class": "error",
338
396
  "no-empty-pattern": "error",
339
397
  "no-empty-static-block": "error",
@@ -441,13 +499,7 @@ function javascript(options = {}) {
441
499
  allowUnboundThis: true
442
500
  }
443
501
  ],
444
- "prefer-const": [
445
- "error",
446
- {
447
- destructuring: "all",
448
- ignoreReadBeforeAssign: true
449
- }
450
- ],
502
+ "prefer-const": isInEditor ? "warn" : ["error", { destructuring: "all", ignoreReadBeforeAssign: true }],
451
503
  "prefer-exponentiation-operator": "error",
452
504
  "prefer-promise-reject-errors": "error",
453
505
  "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
@@ -468,7 +520,7 @@ function javascript(options = {}) {
468
520
  ],
469
521
  "symbol-description": "error",
470
522
  "unicode-bom": ["error", "never"],
471
- "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
523
+ "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
472
524
  "unused-imports/no-unused-vars": [
473
525
  "error",
474
526
  {
@@ -485,20 +537,6 @@ function javascript(options = {}) {
485
537
  yoda: ["error", "never"],
486
538
  ...overrides
487
539
  }
488
- },
489
- {
490
- files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
491
- name: "javascript/disables/cli",
492
- rules: {
493
- "no-console": "off"
494
- }
495
- },
496
- {
497
- files: ["**/*.{test,spec}.js?(x)"],
498
- name: "javascript/disables/test",
499
- rules: {
500
- "no-unused-expressions": "off"
501
- }
502
540
  }
503
541
  ];
504
542
  }
@@ -556,6 +594,23 @@ function node() {
556
594
  ];
557
595
  }
558
596
 
597
+ // src/configs/regexp.ts
598
+ import { configs } from "eslint-plugin-regexp";
599
+ function regexp(options = {}) {
600
+ const config = configs["flat/recommended"];
601
+ return [
602
+ {
603
+ ...config,
604
+ name: "regexp",
605
+ rules: {
606
+ ...config.rules,
607
+ "regexp/no-obscure-range": "off",
608
+ ...options.overrides
609
+ }
610
+ }
611
+ ];
612
+ }
613
+
559
614
  // src/configs/sort.ts
560
615
  function sortPackageJson() {
561
616
  return [
@@ -802,9 +857,11 @@ async function test(options = {}) {
802
857
  "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
803
858
  "test/no-identical-title": "error",
804
859
  "test/no-import-node-test": "error",
805
- "test/no-only-tests": isInEditor ? "off" : "error",
860
+ "test/no-only-tests": isInEditor ? "warn" : "error",
806
861
  "test/prefer-hooks-in-order": "error",
807
862
  "test/prefer-lowercase-title": "error",
863
+ "no-unused-expressions": "off",
864
+ "n/prefer-global/process": "off",
808
865
  "@typescript-eslint/explicit-function-return-type": "off",
809
866
  ...overrides
810
867
  }
@@ -884,7 +941,7 @@ async function typescript(options = {}) {
884
941
  "no-invalid-this": "off",
885
942
  "@typescript-eslint/no-invalid-this": "error",
886
943
  "no-redeclare": "off",
887
- "@typescript-eslint/no-redeclare": "error",
944
+ "@typescript-eslint/no-redeclare": ["error", { builtinGlobals: false }],
888
945
  "no-unused-expressions": "off",
889
946
  "@typescript-eslint/no-unused-expressions": ["error", { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true }],
890
947
  "no-use-before-define": "off",
@@ -922,32 +979,7 @@ async function typescript(options = {}) {
922
979
  ...overridesTypeAware
923
980
  }
924
981
  }
925
- ] : [],
926
- {
927
- files: ["**/*.d.?([cm])ts"],
928
- name: "typescript/disables/dts",
929
- rules: {
930
- "eslint-comments/no-unlimited-disable": "off",
931
- "import/no-duplicates": "off",
932
- "no-restricted-syntax": "off",
933
- "unused-imports/no-unused-vars": "off"
934
- }
935
- },
936
- {
937
- files: ["**/*.{test,spec}.ts?(x)"],
938
- name: "typescript/disables/test",
939
- rules: {
940
- "no-unused-expressions": "off"
941
- }
942
- },
943
- {
944
- files: ["**/*.js", "**/*.cjs"],
945
- name: "typescript/disables/cjs",
946
- rules: {
947
- "@typescript-eslint/no-require-imports": "off",
948
- "@typescript-eslint/no-var-requires": "off"
949
- }
950
- }
982
+ ] : []
951
983
  ];
952
984
  }
953
985
 
@@ -964,9 +996,11 @@ function unicorn() {
964
996
  ...pluginUnicorn.configs["flat/recommended"].rules,
965
997
  "unicorn/consistent-function-scoping": "off",
966
998
  "unicorn/filename-case": "off",
999
+ "unicorn/import-style": "off",
967
1000
  "unicorn/no-array-callback-reference": "off",
968
1001
  "unicorn/no-null": "off",
969
1002
  "unicorn/prefer-string-replace-all": "off",
1003
+ "unicorn/prefer-structured-clone": "off",
970
1004
  "unicorn/prefer-top-level-await": "off",
971
1005
  "unicorn/prevent-abbreviations": "off"
972
1006
  }
@@ -1065,35 +1099,18 @@ async function vue(options = {}) {
1065
1099
  "vue/prefer-template": "error",
1066
1100
  "vue/padding-line-between-blocks": ["error", "always"],
1067
1101
  "vue/component-tags-order": "off",
1102
+ "@typescript-eslint/explicit-function-return-type": "off",
1068
1103
  ...overrides
1069
1104
  }
1070
1105
  }
1071
1106
  ];
1072
1107
  }
1073
1108
 
1074
- // src/configs/regexp.ts
1075
- import { configs } from "eslint-plugin-regexp";
1076
- function regexp(options = {}) {
1077
- const config = configs["flat/recommended"];
1078
- return [
1079
- {
1080
- ...config,
1081
- name: "regexp",
1082
- rules: {
1083
- ...config.rules,
1084
- ...options.overrides
1085
- }
1086
- }
1087
- ];
1088
- }
1089
-
1090
1109
  // src/factory.ts
1091
1110
  import { isPackageExists } from "local-pkg";
1092
1111
  import { FlatConfigComposer } from "eslint-flat-config-utils";
1093
1112
  var flatConfigProps = [
1094
1113
  "name",
1095
- "files",
1096
- "ignores",
1097
1114
  "languageOptions",
1098
1115
  "linterOptions",
1099
1116
  "processor",
@@ -1107,7 +1124,6 @@ var factoryConfig = function(options = {}, ...userConfigs) {
1107
1124
  componentExts = [],
1108
1125
  formatters: enableFormatters = true,
1109
1126
  gitignore: enableGitignore = true,
1110
- isInEditor = isInEditorEnv(),
1111
1127
  jsonc: enableJSONC = true,
1112
1128
  regexp: enableRegexp = true,
1113
1129
  test: enableTest = true,
@@ -1115,6 +1131,11 @@ var factoryConfig = function(options = {}, ...userConfigs) {
1115
1131
  unocss: enableUnoCSS = isPackageExists("unocss"),
1116
1132
  vue: enableVue = VuePackages.some((i) => isPackageExists(i))
1117
1133
  } = options;
1134
+ let isInEditor = options.isInEditor;
1135
+ if (isInEditor == null) {
1136
+ isInEditor = isInEditorEnv();
1137
+ if (isInEditor) console.log("[@cany748/eslint-config] Detected running in editor, some rules are disabled.");
1138
+ }
1118
1139
  const configs2 = [];
1119
1140
  if (enableGitignore) {
1120
1141
  if (typeof enableGitignore === "boolean") {
@@ -1125,7 +1146,7 @@ var factoryConfig = function(options = {}, ...userConfigs) {
1125
1146
  }
1126
1147
  configs2.push(
1127
1148
  comments(),
1128
- ignores(),
1149
+ ignores(options.ignores),
1129
1150
  imports(),
1130
1151
  javascript({
1131
1152
  isInEditor,
@@ -1174,6 +1195,12 @@ var factoryConfig = function(options = {}, ...userConfigs) {
1174
1195
  if (enableFormatters) {
1175
1196
  configs2.push(formatters(enableFormatters));
1176
1197
  }
1198
+ configs2.push(disables());
1199
+ if ("files" in options) {
1200
+ throw new Error(
1201
+ '[@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.'
1202
+ );
1203
+ }
1177
1204
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
1178
1205
  if (key in options) acc[key] = options[key];
1179
1206
  return acc;
@@ -1215,12 +1242,14 @@ export {
1215
1242
  GLOB_YAML,
1216
1243
  combine,
1217
1244
  comments,
1245
+ disables,
1218
1246
  factoryConfig,
1219
1247
  formatters,
1220
1248
  ignores,
1221
1249
  imports,
1222
1250
  interopDefault,
1223
1251
  isInEditorEnv,
1252
+ isInGitHooksOrLintStaged,
1224
1253
  javascript,
1225
1254
  jsonc,
1226
1255
  node,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cany748/eslint-config",
3
3
  "type": "module",
4
- "version": "3.0.2",
4
+ "version": "3.0.4",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./dist/index.js",
@@ -14,9 +14,9 @@
14
14
  "dist"
15
15
  ],
16
16
  "peerDependencies": {
17
- "@unocss/eslint-plugin": "^0.62.1",
18
- "eslint-plugin-vue": "^9.27.0",
19
- "typescript-eslint": "^8.1.0"
17
+ "@unocss/eslint-plugin": "^65.4.3",
18
+ "eslint-plugin-vue": "^9.32.0",
19
+ "typescript-eslint": "^8.21.0"
20
20
  },
21
21
  "peerDependenciesMeta": {
22
22
  "@unocss/eslint-plugin": {
@@ -30,50 +30,51 @@
30
30
  }
31
31
  },
32
32
  "dependencies": {
33
- "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
34
- "@vitest/eslint-plugin": "^1.1.0",
35
- "eslint": "^9.9.1",
36
- "eslint-config-flat-gitignore": "^0.3.0",
37
- "eslint-config-prettier": "^9.1.0",
38
- "eslint-flat-config-utils": "^0.3.1",
39
- "eslint-plugin-import-x": "^4.1.0",
40
- "eslint-plugin-jsonc": "^2.16.0",
41
- "eslint-plugin-n": "^17.10.2",
33
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
34
+ "@vitest/eslint-plugin": "^1.1.25",
35
+ "eslint": "^9.18.0",
36
+ "eslint-config-flat-gitignore": "^1.0.0",
37
+ "eslint-config-prettier": "^10.0.1",
38
+ "eslint-flat-config-utils": "^1.1.0",
39
+ "eslint-plugin-import-x": "^4.6.1",
40
+ "eslint-plugin-jsonc": "^2.19.0",
41
+ "eslint-plugin-n": "^17.15.1",
42
42
  "eslint-plugin-no-only-tests": "^3.3.0",
43
- "eslint-plugin-prettier": "^5.2.1",
44
- "eslint-plugin-regexp": "^2.6.0",
45
- "eslint-plugin-unicorn": "^55.0.0",
46
- "eslint-plugin-unused-imports": "^4.1.3",
47
- "globals": "^15.9.0",
43
+ "eslint-plugin-prettier": "^5.2.3",
44
+ "eslint-plugin-regexp": "^2.7.0",
45
+ "eslint-plugin-unicorn": "^56.0.1",
46
+ "eslint-plugin-unused-imports": "^4.1.4",
47
+ "globals": "^15.14.0",
48
+ "jiti": "^2.4.2",
48
49
  "jsonc-eslint-parser": "^2.4.0",
49
- "local-pkg": "^0.5.0",
50
- "prettier": "^3.3.3"
50
+ "local-pkg": "^1.0.0",
51
+ "prettier": "^3.4.2"
51
52
  },
52
53
  "devDependencies": {
53
- "@types/node": "^22.5.1",
54
- "@unocss/eslint-plugin": "^0.62.3",
55
- "bumpp": "^9.5.2",
56
- "eslint-plugin-vue": "^9.27.0",
57
- "eslint-typegen": "^0.3.1",
58
- "esno": "^4.7.0",
59
- "lint-staged": "^15.2.9",
54
+ "@types/node": "^22.10.10",
55
+ "@unocss/eslint-plugin": "^65.4.3",
56
+ "bumpp": "^9.10.2",
57
+ "eslint-plugin-vue": "^9.32.0",
58
+ "eslint-typegen": "^1.0.0",
59
+ "esno": "^4.8.0",
60
+ "lint-staged": "^15.4.2",
60
61
  "simple-git-hooks": "^2.11.1",
61
- "tsup": "^8.2.4",
62
- "typescript": "^5.5.4",
63
- "typescript-eslint": "^8.3.0"
62
+ "tsup": "^8.3.5",
63
+ "typescript": "^5.7.3",
64
+ "typescript-eslint": "^8.21.0"
64
65
  },
65
66
  "simple-git-hooks": {
66
67
  "pre-commit": "pnpm lint-staged"
67
68
  },
68
69
  "lint-staged": {
69
- "*": "eslint --fix --flag unstable_ts_config"
70
+ "*": "eslint --fix"
70
71
  },
71
72
  "scripts": {
72
73
  "build": "pnpm typegen && tsup --format esm,cjs --clean --dts",
73
74
  "typegen": "esno scripts/typegen.ts",
74
75
  "dev": "npx @eslint/config-inspector --config eslint.config.ts",
75
- "lint": "eslint . --flag unstable_ts_config",
76
- "lint:fix": "eslint . --fix --flag unstable_ts_config",
76
+ "lint": "eslint .",
77
+ "lint:fix": "eslint . --fix",
77
78
  "release": "bumpp && pnpm publish",
78
79
  "typecheck": "tsc --noEmit"
79
80
  }