@luxass/eslint-config 4.8.3 → 4.10.0

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 CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  GLOB_ASTRO: () => GLOB_ASTRO,
34
+ GLOB_ASTRO_TS: () => GLOB_ASTRO_TS,
34
35
  GLOB_CSS: () => GLOB_CSS,
35
36
  GLOB_EXCLUDE: () => GLOB_EXCLUDE,
36
37
  GLOB_GRAPHQL: () => GLOB_GRAPHQL,
@@ -78,6 +79,7 @@ __export(src_exports, {
78
79
  parserPlain: () => parserPlain,
79
80
  react: () => react,
80
81
  regexp: () => regexp,
82
+ renamePluginInConfigs: () => renamePluginInConfigs,
81
83
  renameRules: () => renameRules,
82
84
  resolveSubOptions: () => resolveSubOptions,
83
85
  sortPackageJson: () => sortPackageJson,
@@ -202,6 +204,7 @@ var GLOB_YAML = "**/*.y?(a)ml";
202
204
  var GLOB_TOML = "**/*.toml";
203
205
  var GLOB_HTML = "**/*.htm?(l)";
204
206
  var GLOB_ASTRO = "**/*.astro";
207
+ var GLOB_ASTRO_TS = "**/*.astro/*.ts";
205
208
  var GLOB_GRAPHQL = "**/*.{g,graph}ql";
206
209
  var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
207
210
  var GLOB_TESTS = [
@@ -319,6 +322,7 @@ function sortPackageJson() {
319
322
  "type",
320
323
  "private",
321
324
  "author",
325
+ "contributors",
322
326
  "publisher",
323
327
  "packageManager",
324
328
  "license",
@@ -506,6 +510,7 @@ function sortTsconfig() {
506
510
  "allowSyntheticDefaultImports",
507
511
  "esModuleInterop",
508
512
  "forceConsistentCasingInFileNames",
513
+ "isolatedDeclarations",
509
514
  "isolatedModules",
510
515
  "preserveSymlinks",
511
516
  "verbatimModuleSyntax",
@@ -567,10 +572,13 @@ var import_globals = __toESM(require("globals"), 1);
567
572
  var import_eslint_plugin_unused_imports = __toESM(require("eslint-plugin-unused-imports"), 1);
568
573
  var import_eslint_plugin_antfu2 = __toESM(require("eslint-plugin-antfu"), 1);
569
574
  async function javascript(options = {}) {
570
- const { editor = false, overrides = {} } = options;
575
+ const {
576
+ editor = false,
577
+ overrides = {}
578
+ } = options;
571
579
  return [
572
580
  {
573
- name: "luxass/javascript",
581
+ name: "luxass/javascript/setup",
574
582
  languageOptions: {
575
583
  ecmaVersion: 2022,
576
584
  globals: {
@@ -592,7 +600,10 @@ async function javascript(options = {}) {
592
600
  },
593
601
  linterOptions: {
594
602
  reportUnusedDisableDirectives: true
595
- },
603
+ }
604
+ },
605
+ {
606
+ name: "luxass/javascript/rules",
596
607
  plugins: {
597
608
  "antfu": import_eslint_plugin_antfu2.default,
598
609
  "unused-imports": import_eslint_plugin_unused_imports.default
@@ -847,16 +858,37 @@ async function combine(...configs2) {
847
858
  const resolved = await Promise.all(configs2);
848
859
  return resolved.flat();
849
860
  }
850
- function renameRules(rules, from, to) {
861
+ function renameRules(rules, map) {
851
862
  return Object.fromEntries(
852
863
  Object.entries(rules).map(([key, value]) => {
853
- if (key.startsWith(from)) {
854
- return [to + key.slice(from.length), value];
864
+ for (const [from, to] of Object.entries(map)) {
865
+ if (key.startsWith(`${from}/`)) {
866
+ return [to + key.slice(from.length), value];
867
+ }
855
868
  }
856
869
  return [key, value];
857
870
  })
858
871
  );
859
872
  }
873
+ function renamePluginInConfigs(configs2, map) {
874
+ return configs2.map((i) => {
875
+ const clone = { ...i };
876
+ if (clone.rules) {
877
+ clone.rules = renameRules(clone.rules, map);
878
+ }
879
+ if (clone.plugins) {
880
+ clone.plugins = Object.fromEntries(
881
+ Object.entries(clone.plugins).map(([key, value]) => {
882
+ if (key in map) {
883
+ return [map[key], value];
884
+ }
885
+ return [key, value];
886
+ })
887
+ );
888
+ }
889
+ return clone;
890
+ });
891
+ }
860
892
  function toArray(value) {
861
893
  return Array.isArray(value) ? value : [value];
862
894
  }
@@ -899,7 +931,7 @@ async function jsdoc(options = {}) {
899
931
  } = options;
900
932
  return [
901
933
  {
902
- name: "luxass/jsdoc",
934
+ name: "luxass/jsdoc/rules",
903
935
  plugins: {
904
936
  jsdoc: await interop(import("eslint-plugin-jsdoc"))
905
937
  },
@@ -1065,36 +1097,24 @@ async function markdown(options = {}) {
1065
1097
  "import/newline-after-import": "off",
1066
1098
  "no-alert": "off",
1067
1099
  "no-console": "off",
1100
+ "no-labels": "off",
1101
+ "no-lone-blocks": "off",
1102
+ "no-restricted-syntax": "off",
1068
1103
  "no-undef": "off",
1069
1104
  "no-unused-expressions": "off",
1105
+ "no-unused-labels": "off",
1070
1106
  "no-unused-vars": "off",
1071
1107
  "node/prefer-global/process": "off",
1072
1108
  "style/comma-dangle": "off",
1073
1109
  "style/eol-last": "off",
1074
- // Type aware rules
1075
- "ts/await-thenable": "off",
1076
1110
  "ts/consistent-type-imports": "off",
1077
- "ts/dot-notation": "off",
1078
- "ts/no-floating-promises": "off",
1079
- "ts/no-for-in-array": "off",
1080
- "ts/no-implied-eval": "off",
1081
- "ts/no-misused-promises": "off",
1082
1111
  "ts/no-namespace": "off",
1083
1112
  "ts/no-redeclare": "off",
1084
1113
  "ts/no-require-imports": "off",
1085
- "ts/no-throw-literal": "off",
1086
- "ts/no-unnecessary-type-assertion": "off",
1087
- "ts/no-unsafe-argument": "off",
1088
- "ts/no-unsafe-assignment": "off",
1089
- "ts/no-unsafe-call": "off",
1090
- "ts/no-unsafe-member-access": "off",
1091
- "ts/no-unsafe-return": "off",
1114
+ "ts/no-unused-expressions": "off",
1092
1115
  "ts/no-unused-vars": "off",
1093
1116
  "ts/no-use-before-define": "off",
1094
1117
  "ts/no-var-requires": "off",
1095
- "ts/restrict-plus-operands": "off",
1096
- "ts/restrict-template-expressions": "off",
1097
- "ts/unbound-method": "off",
1098
1118
  "unicode-bom": "off",
1099
1119
  "unused-imports/no-unused-imports": "off",
1100
1120
  "unused-imports/no-unused-vars": "off",
@@ -1160,34 +1180,42 @@ async function typescript(options = {}) {
1160
1180
  const {
1161
1181
  exts = [],
1162
1182
  overrides = {},
1163
- parserOptions = {}
1183
+ parserOptions = {},
1184
+ type = "app"
1164
1185
  } = options ?? {};
1165
1186
  const files = options.files ?? [
1166
- GLOB_SRC,
1187
+ GLOB_TS,
1188
+ GLOB_TSX,
1167
1189
  ...exts.map((ext) => `**/*.${ext}`)
1168
1190
  ];
1169
- const filesTypeAware = options.typeAwareFileS ?? [GLOB_TS, GLOB_TSX];
1170
- const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
1191
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1192
+ const ignoresTypeAware = options.ignoresTypeAware ?? [
1193
+ `${GLOB_MARKDOWN}/**`,
1194
+ GLOB_ASTRO_TS
1195
+ ];
1196
+ const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
1171
1197
  const isTypeAware = !!tsconfigPath;
1172
1198
  const typeAwareRules = {
1173
1199
  "dot-notation": "off",
1174
1200
  "no-implied-eval": "off",
1175
- "no-throw-literal": "off",
1176
1201
  "ts/await-thenable": "error",
1177
1202
  "ts/dot-notation": ["error", { allowKeywords: true }],
1178
1203
  "ts/no-floating-promises": "error",
1179
1204
  "ts/no-for-in-array": "error",
1180
1205
  "ts/no-implied-eval": "error",
1181
1206
  "ts/no-misused-promises": "error",
1182
- "ts/no-throw-literal": "error",
1183
1207
  "ts/no-unnecessary-type-assertion": "error",
1184
1208
  "ts/no-unsafe-argument": "error",
1185
1209
  "ts/no-unsafe-assignment": "error",
1186
1210
  "ts/no-unsafe-call": "error",
1187
1211
  "ts/no-unsafe-member-access": "error",
1188
1212
  "ts/no-unsafe-return": "error",
1213
+ "ts/promise-function-async": "error",
1189
1214
  "ts/restrict-plus-operands": "error",
1190
1215
  "ts/restrict-template-expressions": "error",
1216
+ "ts/return-await": ["error", "in-try-catch"],
1217
+ "ts/strict-boolean-expressions": ["error", { allowNullableBoolean: true, allowNullableObject: true }],
1218
+ "ts/switch-exhaustiveness-check": "error",
1191
1219
  "ts/unbound-method": "error"
1192
1220
  };
1193
1221
  const [
@@ -1208,7 +1236,10 @@ async function typescript(options = {}) {
1208
1236
  extraFileExtensions: exts.map((ext) => `.${ext}`),
1209
1237
  sourceType: "module",
1210
1238
  ...typeAware ? {
1211
- project: tsconfigPath,
1239
+ projectService: {
1240
+ allowDefaultProject: ["./*.js"],
1241
+ defaultProject: tsconfigPath
1242
+ },
1212
1243
  tsconfigRootDir: import_node_process2.default.cwd()
1213
1244
  } : {},
1214
1245
  ...parserOptions
@@ -1226,7 +1257,7 @@ async function typescript(options = {}) {
1226
1257
  }
1227
1258
  },
1228
1259
  ...isTypeAware ? [
1229
- makeParser(true, filesTypeAware),
1260
+ makeParser(true, filesTypeAware, ignoresTypeAware),
1230
1261
  makeParser(false, files, filesTypeAware)
1231
1262
  ] : [makeParser(false, files)],
1232
1263
  {
@@ -1235,58 +1266,29 @@ async function typescript(options = {}) {
1235
1266
  rules: {
1236
1267
  ...renameRules(
1237
1268
  pluginTs.configs["eslint-recommended"].overrides[0].rules,
1238
- "@typescript-eslint/",
1239
- "ts/"
1269
+ {
1270
+ "@typescript-eslint": "ts"
1271
+ }
1240
1272
  ),
1241
1273
  ...renameRules(
1242
1274
  pluginTs.configs.strict.rules,
1243
- "@typescript-eslint/",
1244
- "ts/"
1275
+ {
1276
+ "@typescript-eslint": "ts"
1277
+ }
1245
1278
  ),
1246
1279
  "no-dupe-class-members": "off",
1247
1280
  "no-invalid-this": "off",
1248
- "no-loss-of-precision": "off",
1281
+ "no-loss-of-precision": "error",
1249
1282
  "no-redeclare": "off",
1250
1283
  "no-use-before-define": "off",
1251
1284
  "no-useless-constructor": "off",
1252
1285
  "ts/ban-ts-comment": [
1253
1286
  "error",
1254
- { "ts-ignore": "allow-with-description" }
1255
- ],
1256
- "ts/ban-types": ["error", {
1257
- extendDefaults: false,
1258
- types: {
1259
- BigInt: {
1260
- fixWith: "bigint",
1261
- message: "Use `bigint` instead."
1262
- },
1263
- Boolean: {
1264
- fixWith: "boolean",
1265
- message: "Use `boolean` instead."
1266
- },
1267
- Function: "Use a specific function type instead, like `() => void`.",
1268
- Number: {
1269
- fixWith: "number",
1270
- message: "Use `number` instead."
1271
- },
1272
- Object: {
1273
- fixWith: "Record<string, unknown>",
1274
- message: "The `Object` type is mostly the same as `unknown`. You probably want `Record<string, unknown>` instead. See https://github.com/typescript-eslint/typescript-eslint/pull/848"
1275
- },
1276
- String: {
1277
- fixWith: "string",
1278
- message: "Use `string` instead."
1279
- },
1280
- Symbol: {
1281
- fixWith: "symbol",
1282
- message: "Use `symbol` instead."
1283
- },
1284
- object: {
1285
- fixWith: "Record<string, unknown>",
1286
- message: "The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848"
1287
- }
1287
+ {
1288
+ "ts-ignore": "allow-with-description",
1289
+ "ts-expect-error": "allow-with-description"
1288
1290
  }
1289
- }],
1291
+ ],
1290
1292
  "ts/consistent-type-definitions": ["error", "interface"],
1291
1293
  "ts/consistent-type-imports": [
1292
1294
  "error",
@@ -1296,12 +1298,12 @@ async function typescript(options = {}) {
1296
1298
  // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
1297
1299
  "ts/no-dupe-class-members": "error",
1298
1300
  "ts/no-dynamic-delete": "off",
1301
+ "ts/no-empty-object-type": "error",
1299
1302
  "ts/no-explicit-any": "off",
1300
1303
  "ts/no-extraneous-class": "off",
1301
1304
  "ts/no-import-type-side-effects": "error",
1302
1305
  "ts/no-invalid-this": "error",
1303
1306
  "ts/no-invalid-void-type": "off",
1304
- "ts/no-loss-of-precision": "error",
1305
1307
  "ts/no-non-null-assertion": "off",
1306
1308
  "ts/no-redeclare": "error",
1307
1309
  "ts/no-require-imports": "error",
@@ -1311,23 +1313,28 @@ async function typescript(options = {}) {
1311
1313
  { classes: false, functions: false, variables: true }
1312
1314
  ],
1313
1315
  "ts/no-useless-constructor": "off",
1314
- "ts/prefer-ts-expect-error": "error",
1316
+ "ts/no-wrapper-object-types": "error",
1315
1317
  "ts/triple-slash-reference": "off",
1316
1318
  "ts/unified-signatures": "off",
1319
+ ...type === "lib" ? {
1320
+ "ts/explicit-function-return-type": ["error", {
1321
+ allowExpressions: true,
1322
+ allowHigherOrderFunctions: true,
1323
+ allowIIFEs: true
1324
+ }]
1325
+ } : {},
1317
1326
  ...overrides
1318
1327
  }
1319
1328
  },
1320
- {
1321
- name: "luxass/typescript/rules-type-aware",
1329
+ ...isTypeAware ? [{
1322
1330
  files: filesTypeAware,
1323
- rules: {
1324
- ...tsconfigPath ? typeAwareRules : {},
1325
- ...overrides
1326
- }
1327
- },
1331
+ ignores: ignoresTypeAware,
1332
+ name: "luxass/typescript/rules-type-aware",
1333
+ rules: typeAwareRules
1334
+ }] : [],
1328
1335
  {
1329
1336
  name: "luxass/typescript/disables/dts",
1330
- files: ["**/*.d.ts"],
1337
+ files: ["**/*.d.?([cm])ts"],
1331
1338
  rules: {
1332
1339
  "eslint-comments/no-unlimited-disable": "off",
1333
1340
  "import/no-duplicates": "off",
@@ -1336,21 +1343,14 @@ async function typescript(options = {}) {
1336
1343
  }
1337
1344
  },
1338
1345
  {
1339
- name: "luxass/typescript/disables/tests",
1340
1346
  files: ["**/*.{test,spec}.ts?(x)"],
1347
+ name: "luxass/typescript/disables/test",
1341
1348
  rules: {
1342
1349
  "no-unused-expressions": "off"
1343
1350
  }
1344
1351
  },
1345
1352
  {
1346
- name: "luxass/typescript/disables/playground",
1347
- files: [`**/playground.${GLOB_SRC_EXT}`],
1348
- rules: {
1349
- "no-console": "off"
1350
- }
1351
- },
1352
- {
1353
- name: "luxass/typescript/disables/javascript",
1353
+ name: "luxass/typescript/disables/cjs",
1354
1354
  files: ["**/*.js", "**/*.cjs"],
1355
1355
  rules: {
1356
1356
  "ts/no-require-imports": "off",
@@ -1653,6 +1653,7 @@ async function test(options = {}) {
1653
1653
  "test/no-focused-tests": editor ? "off" : "error",
1654
1654
  "test/prefer-hooks-in-order": "error",
1655
1655
  "test/prefer-lowercase-title": "error",
1656
+ "ts/explicit-function-return-type": "off",
1656
1657
  ...overrides
1657
1658
  }
1658
1659
  }
@@ -2307,7 +2308,8 @@ function luxass(options = {}, ...userConfigs) {
2307
2308
  typescript: enableTypeScript = (0, import_local_pkg4.isPackageExists)("typescript"),
2308
2309
  unocss: enableUnoCSS = false,
2309
2310
  tailwindcss: enableTailwindCSS = false,
2310
- vue: enableVue = VuePackages.some((i) => (0, import_local_pkg4.isPackageExists)(i))
2311
+ vue: enableVue = VuePackages.some((i) => (0, import_local_pkg4.isPackageExists)(i)),
2312
+ type: projectType = "app"
2311
2313
  } = options;
2312
2314
  const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
2313
2315
  if (stylisticOptions && !("jsx" in stylisticOptions)) {
@@ -2351,7 +2353,8 @@ function luxass(options = {}, ...userConfigs) {
2351
2353
  configs2.push(typescript({
2352
2354
  ...typescriptOptions,
2353
2355
  exts,
2354
- overrides: getOverrides(options, "typescript")
2356
+ overrides: getOverrides(options, "typescript"),
2357
+ type: projectType
2355
2358
  }));
2356
2359
  }
2357
2360
  if (stylisticOptions) {
@@ -2470,6 +2473,7 @@ var src_default = luxass;
2470
2473
  // Annotate the CommonJS export names for ESM import in node:
2471
2474
  0 && (module.exports = {
2472
2475
  GLOB_ASTRO,
2476
+ GLOB_ASTRO_TS,
2473
2477
  GLOB_CSS,
2474
2478
  GLOB_EXCLUDE,
2475
2479
  GLOB_GRAPHQL,
@@ -2516,6 +2520,7 @@ var src_default = luxass;
2516
2520
  parserPlain,
2517
2521
  react,
2518
2522
  regexp,
2523
+ renamePluginInConfigs,
2519
2524
  renameRules,
2520
2525
  resolveSubOptions,
2521
2526
  sortPackageJson,