@ivanmaxlogiudice/eslint-config 3.0.0-beta.5 → 3.0.0-beta.7

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
@@ -140,7 +140,14 @@ async function interopDefault(m) {
140
140
  return resolved.default || resolved;
141
141
  }
142
142
  function isInEditorEnv() {
143
- return !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM) && !process.env.CI);
143
+ if (process.env.CI)
144
+ return false;
145
+ if (isInGitHooksOrLintStaged())
146
+ return false;
147
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
148
+ }
149
+ function isInGitHooksOrLintStaged() {
150
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
144
151
  }
145
152
  async function spawnAsync(command, args, options) {
146
153
  return new Promise((resolve, reject) => {
@@ -466,7 +473,7 @@ function jsdoc() {
466
473
 
467
474
  // src/configs/jsonc.ts
468
475
  import plugin4 from "eslint-plugin-jsonc";
469
- import parser from "jsonc-eslint-parser";
476
+ import * as parser from "jsonc-eslint-parser";
470
477
  function jsonc(options = {}) {
471
478
  const {
472
479
  files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
@@ -537,12 +544,12 @@ async function markdown(options = {}) {
537
544
  overrides = {}
538
545
  } = options;
539
546
  await ensurePackages(["eslint-plugin-markdown"]);
540
- const plugin10 = await interopDefault(import("eslint-plugin-markdown"));
547
+ const plugin9 = await interopDefault(import("eslint-plugin-markdown"));
541
548
  return [
542
549
  {
543
550
  name: "ivanmaxlogiudice/markdown/setup",
544
551
  plugins: {
545
- markdown: plugin10
552
+ markdown: plugin9
546
553
  }
547
554
  },
548
555
  {
@@ -660,15 +667,15 @@ async function regexp(options = {}) {
660
667
  overrides = {}
661
668
  } = options;
662
669
  await ensurePackages(["eslint-plugin-regexp"]);
663
- const plugin10 = await interopDefault(import("eslint-plugin-regexp"));
670
+ const plugin9 = await interopDefault(import("eslint-plugin-regexp"));
664
671
  return [
665
672
  {
666
673
  name: "ivanmaxlogiudice/regexp/rules",
667
674
  plugins: {
668
- regexp: plugin10
675
+ regexp: plugin9
669
676
  },
670
677
  rules: {
671
- ...plugin10.configs["flat/recommended"].rules,
678
+ ...plugin9.configs["flat/recommended"].rules,
672
679
  ...overrides
673
680
  }
674
681
  }
@@ -963,41 +970,93 @@ async function test(options = {}) {
963
970
  }
964
971
 
965
972
  // src/configs/typescript.ts
966
- import plugin8 from "@typescript-eslint/eslint-plugin";
967
- import parser2 from "@typescript-eslint/parser";
968
- function typescript(options = {}) {
973
+ import process2 from "node:process";
974
+ async function typescript(options = {}) {
969
975
  const {
970
976
  componentExts = [],
971
977
  overrides = {},
978
+ overridesTypeAware = {},
979
+ parserOptions = {},
972
980
  type = "app"
973
981
  } = options;
974
982
  const files = options.files ?? [GLOB_TS, ...componentExts.map((ext) => `**/*.${ext}`)];
975
- return [
976
- {
977
- name: "ivanmaxlogiudice/typescript/setup",
978
- plugins: {
979
- ts: plugin8
980
- }
981
- },
982
- {
983
- name: "ivanmaxlogiudice/typescript/parser",
984
- files,
983
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS];
984
+ const ignoresTypeAware = options.ignoresTypeAware ?? [`${GLOB_MARKDOWN}/**`];
985
+ const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
986
+ const isTypeAware = !!tsconfigPath;
987
+ const typeAwareRules = {
988
+ "dot-notation": "off",
989
+ "no-implied-eval": "off",
990
+ "ts/await-thenable": "error",
991
+ "ts/dot-notation": ["error", { allowKeywords: true }],
992
+ "ts/no-floating-promises": "error",
993
+ "ts/no-for-in-array": "error",
994
+ "ts/no-implied-eval": "error",
995
+ "ts/no-misused-promises": "error",
996
+ "ts/no-unnecessary-type-assertion": "error",
997
+ "ts/no-unsafe-argument": "error",
998
+ "ts/no-unsafe-assignment": "error",
999
+ "ts/no-unsafe-call": "error",
1000
+ "ts/no-unsafe-member-access": "error",
1001
+ "ts/no-unsafe-return": "error",
1002
+ "ts/promise-function-async": "error",
1003
+ "ts/restrict-plus-operands": "error",
1004
+ "ts/restrict-template-expressions": "error",
1005
+ "ts/return-await": ["error", "in-try-catch"],
1006
+ "ts/strict-boolean-expressions": ["error", { allowNullableBoolean: true, allowNullableObject: true }],
1007
+ "ts/switch-exhaustiveness-check": "error",
1008
+ "ts/unbound-method": "error"
1009
+ };
1010
+ const [plugin9, parser2] = await Promise.all([
1011
+ interopDefault(import("@typescript-eslint/eslint-plugin")),
1012
+ interopDefault(import("@typescript-eslint/parser"))
1013
+ ]);
1014
+ function makeParser(typeAware, files2, ignores2) {
1015
+ return {
1016
+ files: files2,
1017
+ ...ignores2 ? { ignores: ignores2 } : {},
1018
+ name: `ivanmaxlogiudice/typescript/${typeAware ? "type-aware-parser" : "parser"}`,
985
1019
  languageOptions: {
986
1020
  parser: parser2,
987
1021
  parserOptions: {
988
1022
  extraFileExtensions: componentExts.map((ext) => `.${ext}`),
989
- sourceType: "module"
1023
+ sourceType: "module",
1024
+ ...typeAware ? {
1025
+ projectService: {
1026
+ allowDefaultProject: ["./*.js"],
1027
+ defaultProject: tsconfigPath
1028
+ },
1029
+ tsconfigRootDir: process2.cwd()
1030
+ } : {},
1031
+ ...parserOptions
990
1032
  }
991
1033
  }
1034
+ };
1035
+ }
1036
+ return [
1037
+ {
1038
+ // Install the plugins without globs, so they can be configured separately.
1039
+ name: "ivanmaxlogiudice/typescript/setup",
1040
+ plugins: {
1041
+ ts: plugin9
1042
+ }
992
1043
  },
1044
+ // assign type-aware parser for type-aware files and type-unaware parser for the rest
1045
+ ...isTypeAware ? [
1046
+ makeParser(false, files),
1047
+ makeParser(true, filesTypeAware, ignoresTypeAware)
1048
+ ] : [
1049
+ makeParser(false, files)
1050
+ ],
993
1051
  {
994
1052
  name: "ivanmaxlogiudice/typescript/rules",
995
1053
  files,
996
1054
  rules: {
997
1055
  // Disable eslint rules which are already handled by TypeScript.
998
- ...renameRules(plugin8.configs["eslint-recommended"].overrides[0].rules, "@typescript-eslint", "ts"),
999
- ...renameRules(plugin8.configs.strict.rules, "@typescript-eslint", "ts"),
1056
+ ...renameRules(plugin9.configs["eslint-recommended"].overrides[0].rules, "@typescript-eslint", "ts"),
1057
+ ...renameRules(plugin9.configs.strict.rules, "@typescript-eslint", "ts"),
1000
1058
  "no-dupe-class-members": "off",
1059
+ "no-loss-of-precision": "off",
1001
1060
  "no-redeclare": "off",
1002
1061
  "no-use-before-define": "off",
1003
1062
  "no-useless-constructor": "off",
@@ -1035,6 +1094,15 @@ function typescript(options = {}) {
1035
1094
  ...overrides
1036
1095
  }
1037
1096
  },
1097
+ ...isTypeAware ? [{
1098
+ name: "ivanmaxlogiudice/typescript/rules-type-aware",
1099
+ files: filesTypeAware,
1100
+ ignores: ignoresTypeAware,
1101
+ rules: {
1102
+ ...typeAwareRules,
1103
+ ...overridesTypeAware
1104
+ }
1105
+ }] : [],
1038
1106
  {
1039
1107
  name: "ivanmaxlogiudice/typescript/disables/dts",
1040
1108
  files: ["**/*.d.?([cm])ts"],
@@ -1056,20 +1124,21 @@ function typescript(options = {}) {
1056
1124
  name: "ivanmaxlogiudice/typescript/disables/cjs",
1057
1125
  files: ["**/*.js", "**/*.cjs"],
1058
1126
  rules: {
1059
- "ts/no-require-imports": "off"
1127
+ "ts/no-require-imports": "off",
1128
+ "ts/no-var-requires": "off"
1060
1129
  }
1061
1130
  }
1062
1131
  ];
1063
1132
  }
1064
1133
 
1065
1134
  // src/configs/unicorn.ts
1066
- import plugin9 from "eslint-plugin-unicorn";
1135
+ import plugin8 from "eslint-plugin-unicorn";
1067
1136
  function unicorn() {
1068
1137
  return [
1069
1138
  {
1070
1139
  name: "ivanmaxlogiudice/unicorn/rules",
1071
1140
  plugins: {
1072
- unicorn: plugin9
1141
+ unicorn: plugin8
1073
1142
  },
1074
1143
  rules: {
1075
1144
  // Pass error message when throwing errors
@@ -1111,14 +1180,14 @@ async function unocss(options = {}) {
1111
1180
  strict = false
1112
1181
  } = options;
1113
1182
  await ensurePackages(["@unocss/eslint-plugin"]);
1114
- const [plugin10] = await Promise.all([
1183
+ const [plugin9] = await Promise.all([
1115
1184
  interopDefault(import("@unocss/eslint-plugin"))
1116
1185
  ]);
1117
1186
  return [
1118
1187
  {
1119
1188
  name: "ivanmaxlogiudice/unocss/rules",
1120
1189
  plugins: {
1121
- unocss: plugin10
1190
+ unocss: plugin9
1122
1191
  },
1123
1192
  rules: {
1124
1193
  "unocss/order": "warn",
@@ -1137,7 +1206,7 @@ async function vue(options = {}) {
1137
1206
  overrides = {}
1138
1207
  } = options;
1139
1208
  await ensurePackages(["eslint-plugin-vue", "vue-eslint-parser"]);
1140
- const [plugin10, parser3] = await Promise.all([
1209
+ const [plugin9, parser2] = await Promise.all([
1141
1210
  // @ts-expect-error missing types
1142
1211
  interopDefault(import("eslint-plugin-vue")),
1143
1212
  interopDefault(import("vue-eslint-parser"))
@@ -1146,7 +1215,7 @@ async function vue(options = {}) {
1146
1215
  {
1147
1216
  name: "ivanmaxlogiudice/vue/setup",
1148
1217
  plugins: {
1149
- vue: plugin10
1218
+ vue: plugin9
1150
1219
  },
1151
1220
  // This allows Vue plugin to work with auto imports
1152
1221
  // https://github.com/vuejs/eslint-plugin-vue/pull/2422
@@ -1173,7 +1242,7 @@ async function vue(options = {}) {
1173
1242
  name: "ivanmaxlogiudice/vue/rules",
1174
1243
  files,
1175
1244
  languageOptions: {
1176
- parser: parser3,
1245
+ parser: parser2,
1177
1246
  parserOptions: {
1178
1247
  ecmaFeatures: {
1179
1248
  jsx: true
@@ -1183,15 +1252,15 @@ async function vue(options = {}) {
1183
1252
  sourceType: "module"
1184
1253
  }
1185
1254
  },
1186
- processor: plugin10.processors[".vue"],
1255
+ processor: plugin9.processors[".vue"],
1187
1256
  rules: {
1188
- ...plugin10.configs.base.rules,
1189
- ...plugin10.configs["vue3-essential"].rules,
1190
- ...plugin10.configs["vue3-strongly-recommended"].rules,
1191
- ...plugin10.configs["vue3-recommended"].rules,
1257
+ ...plugin9.configs.base.rules,
1258
+ ...plugin9.configs["vue3-essential"].rules,
1259
+ ...plugin9.configs["vue3-strongly-recommended"].rules,
1260
+ ...plugin9.configs["vue3-recommended"].rules,
1192
1261
  "node/prefer-global/process": "off",
1193
1262
  "vue/block-order": ["error", {
1194
- order: ["template", "script", "style"]
1263
+ order: ["script", "template", "style"]
1195
1264
  }],
1196
1265
  "vue/component-name-in-template-casing": ["error", "PascalCase"],
1197
1266
  "vue/component-options-name-casing": ["error", "PascalCase"],
@@ -1277,7 +1346,7 @@ async function yaml(options = {}) {
1277
1346
  overrides = {}
1278
1347
  } = options;
1279
1348
  await ensurePackages(["eslint-plugin-yml", "yaml-eslint-parser"]);
1280
- const [plugin10, parser3] = await Promise.all([
1349
+ const [plugin9, parser2] = await Promise.all([
1281
1350
  interopDefault(import("eslint-plugin-yml")),
1282
1351
  interopDefault(import("yaml-eslint-parser"))
1283
1352
  ]);
@@ -1285,14 +1354,14 @@ async function yaml(options = {}) {
1285
1354
  {
1286
1355
  name: "ivanmaxlogiudice/yaml/setup",
1287
1356
  plugins: {
1288
- yaml: plugin10
1357
+ yaml: plugin9
1289
1358
  }
1290
1359
  },
1291
1360
  {
1292
1361
  name: "ivanmaxlogiudice/yaml/rules",
1293
1362
  files,
1294
1363
  languageOptions: {
1295
- parser: parser3
1364
+ parser: parser2
1296
1365
  },
1297
1366
  rules: {
1298
1367
  // TODO: Check rules (https://github.com/ota-meshi/eslint-plugin-yml)
@@ -1326,12 +1395,18 @@ async function yaml(options = {}) {
1326
1395
  async function config2(options = {}, ...userConfigs) {
1327
1396
  const {
1328
1397
  componentExts = [],
1329
- isInEditor = isInEditorEnv(),
1330
1398
  regexp: enableRegexp = false,
1331
1399
  typescript: enableTypeScript = isPackageInScope("typescript"),
1332
1400
  unocss: enableUnoCSS = hasSomePackage(["unocss", "@unocss/nuxt"]),
1333
1401
  vue: enableVue = hasSomePackage(["vue", "nuxt", "vitepress", "@slidev/cli"])
1334
1402
  } = options;
1403
+ let isInEditor = options.isInEditor;
1404
+ if (isInEditor == null) {
1405
+ isInEditor = isInEditorEnv();
1406
+ if (isInEditor) {
1407
+ console.log("[@ivanmaxlogiudice/eslint-config] Detected running in editor, some rules are disabled.");
1408
+ }
1409
+ }
1335
1410
  const configs = [
1336
1411
  comments(),
1337
1412
  ignores(),
@@ -1359,6 +1434,7 @@ async function config2(options = {}, ...userConfigs) {
1359
1434
  }
1360
1435
  if (enableTypeScript) {
1361
1436
  configs.push(typescript({
1437
+ ...resolveSubOptions(options, "typescript"),
1362
1438
  componentExts,
1363
1439
  overrides: getOverrides(options, "typescript"),
1364
1440
  type: options.type
@@ -1412,7 +1488,6 @@ function resolveSubOptions(options, key) {
1412
1488
  function getOverrides(options, key) {
1413
1489
  const sub = resolveSubOptions(options, key);
1414
1490
  return {
1415
- ...options.overrides?.[key],
1416
1491
  ..."overrides" in sub ? sub.overrides : {}
1417
1492
  };
1418
1493
  }
@@ -1446,6 +1521,7 @@ export {
1446
1521
  imports,
1447
1522
  interopDefault,
1448
1523
  isInEditorEnv,
1524
+ isInGitHooksOrLintStaged,
1449
1525
  isPackageInScope,
1450
1526
  javascript,
1451
1527
  jsdoc,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ivanmaxlogiudice/eslint-config",
3
- "version": "3.0.0-beta.5",
4
- "packageManager": "bun@1.1.24",
3
+ "version": "3.0.0-beta.7",
4
+ "packageManager": "bun@1.1.26",
5
5
  "description": "Personal ESLint config",
6
6
  "type": "module",
7
7
  "keywords": ["eslint-config"],
@@ -32,7 +32,7 @@
32
32
  "dev": "config-inspector --config eslint.config.ts",
33
33
  "build": "bun run typegen && tsup --format esm --clean --dts",
34
34
  "test": "vitest",
35
- "lint": "eslint . --fix",
35
+ "lint": "eslint --flag unstable_ts_config --fix .",
36
36
  "typegen": "bun scripts/typegen.ts",
37
37
  "prepack": "bun run build",
38
38
  "release": "bumpp && npm publish",
@@ -73,19 +73,19 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@clack/prompts": "^0.7.0",
76
- "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
76
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
77
77
  "@ivanmaxlogiudice/gitignore": "^0.0.2",
78
- "@stylistic/eslint-plugin": "^2.6.2",
79
- "@typescript-eslint/eslint-plugin": "^8.1.0",
80
- "@typescript-eslint/parser": "^8.1.0",
81
- "@vitest/eslint-plugin": "^1.0.2",
82
- "eslint-plugin-antfu": "^2.3.5",
78
+ "@stylistic/eslint-plugin": "^2.6.4",
79
+ "@typescript-eslint/eslint-plugin": "^8.2.0",
80
+ "@typescript-eslint/parser": "^8.2.0",
81
+ "@vitest/eslint-plugin": "^1.0.3",
82
+ "eslint-plugin-antfu": "^2.3.6",
83
83
  "eslint-plugin-import-x": "^3.1.0",
84
84
  "eslint-plugin-jsdoc": "^50.2.2",
85
85
  "eslint-plugin-jsonc": "^2.16.0",
86
86
  "eslint-plugin-n": "^17.10.2",
87
- "eslint-plugin-no-only-tests": "^3.1.0",
88
- "eslint-plugin-perfectionist": "^3.1.3",
87
+ "eslint-plugin-no-only-tests": "^3.3.0",
88
+ "eslint-plugin-perfectionist": "^3.2.0",
89
89
  "eslint-plugin-unicorn": "^55.0.0",
90
90
  "eslint-plugin-unused-imports": "^4.1.3",
91
91
  "globals": "^15.9.0",
@@ -95,26 +95,33 @@
95
95
  "yargs": "^17.7.2"
96
96
  },
97
97
  "devDependencies": {
98
- "@eslint/config-inspector": "^0.5.2",
99
- "@stylistic/eslint-plugin-migrate": "^2.6.2",
98
+ "@eslint/config-inspector": "^0.5.4",
99
+ "@stylistic/eslint-plugin-migrate": "^2.6.4",
100
100
  "@types/eslint": "^9.6.0",
101
- "@types/node": "^22.3.0",
101
+ "@types/node": "^22.5.0",
102
102
  "@types/yargs": "^17.0.33",
103
- "@unocss/eslint-plugin": "^0.62.1",
104
- "bumpp": "^9.5.1",
105
- "bun-types": "^1.1.24",
106
- "bundle-require": "^5.0.0",
107
- "eslint": "^9.9.0",
103
+ "@unocss/eslint-plugin": "^0.62.3",
104
+ "bumpp": "^9.5.2",
105
+ "bun-types": "^1.1.26",
106
+ "eslint": "^9.9.1",
108
107
  "eslint-plugin-markdown": "^5.1.0",
109
108
  "eslint-plugin-regexp": "^2.6.0",
110
109
  "eslint-plugin-vue": "^9.27.0",
111
110
  "eslint-plugin-yml": "^1.14.0",
112
- "eslint-typegen": "^0.3.0",
111
+ "eslint-typegen": "^0.3.1",
112
+ "lint-staged": "^15.2.9",
113
+ "simple-git-hooks": "^2.11.1",
113
114
  "tsup": "^8.2.4",
114
115
  "typescript": "^5.5.4",
115
116
  "unbuild": "^2.0.0",
116
117
  "vitest": "^2.0.5",
117
118
  "vue-eslint-parser": "^9.4.3",
118
119
  "yaml-eslint-parser": "^1.2.3"
120
+ },
121
+ "simple-git-hooks": {
122
+ "pre-commit": "bunx lint-staged"
123
+ },
124
+ "lint-staged": {
125
+ "*": "eslint --flag unstable_ts_config --fix"
119
126
  }
120
127
  }