@antfu/eslint-config 1.2.0 → 2.0.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.js CHANGED
@@ -2,32 +2,18 @@
2
2
  import process2 from "process";
3
3
  import fs from "fs";
4
4
  import { isPackageExists } from "local-pkg";
5
- import gitignore from "eslint-config-flat-gitignore";
6
5
 
7
6
  // src/plugins.ts
8
7
  import { default as default2 } from "eslint-plugin-antfu";
9
8
  import { default as default3 } from "eslint-plugin-eslint-comments";
10
9
  import * as pluginImport from "eslint-plugin-i";
11
- import { default as default4 } from "eslint-plugin-jsdoc";
12
- import * as pluginJsonc from "eslint-plugin-jsonc";
13
- import { default as default5 } from "eslint-plugin-markdown";
14
- import { default as default6 } from "eslint-plugin-n";
15
- import { default as default7 } from "@stylistic/eslint-plugin";
16
- import { default as default8 } from "@typescript-eslint/eslint-plugin";
17
- import { default as default9 } from "eslint-plugin-unicorn";
18
- import { default as default10 } from "eslint-plugin-unused-imports";
19
- import { default as default11 } from "eslint-plugin-vue";
20
- import * as pluginYaml from "eslint-plugin-yml";
21
- import { default as default12 } from "eslint-plugin-no-only-tests";
22
- import { default as default13 } from "eslint-plugin-vitest";
23
- import { default as default14 } from "eslint-plugin-perfectionist";
24
- import * as parserTs from "@typescript-eslint/parser";
25
- import { default as default15 } from "vue-eslint-parser";
26
- import { default as default16 } from "yaml-eslint-parser";
27
- import { default as default17 } from "jsonc-eslint-parser";
10
+ import { default as default4 } from "eslint-plugin-n";
11
+ import { default as default5 } from "eslint-plugin-unicorn";
12
+ import { default as default6 } from "eslint-plugin-unused-imports";
13
+ import { default as default7 } from "eslint-plugin-perfectionist";
28
14
 
29
15
  // src/configs/comments.ts
30
- function comments() {
16
+ async function comments() {
31
17
  return [
32
18
  {
33
19
  name: "antfu:eslint-comments",
@@ -112,7 +98,7 @@ var GLOB_EXCLUDE = [
112
98
  ];
113
99
 
114
100
  // src/configs/ignores.ts
115
- function ignores() {
101
+ async function ignores() {
116
102
  return [
117
103
  {
118
104
  ignores: GLOB_EXCLUDE
@@ -121,7 +107,7 @@ function ignores() {
121
107
  }
122
108
 
123
109
  // src/configs/imports.ts
124
- function imports(options = {}) {
110
+ async function imports(options = {}) {
125
111
  const {
126
112
  stylistic: stylistic2 = true
127
113
  } = options;
@@ -152,7 +138,7 @@ function imports(options = {}) {
152
138
 
153
139
  // src/configs/javascript.ts
154
140
  import globals from "globals";
155
- function javascript(options = {}) {
141
+ async function javascript(options = {}) {
156
142
  const {
157
143
  isInEditor = false,
158
144
  overrides = {}
@@ -184,7 +170,7 @@ function javascript(options = {}) {
184
170
  name: "antfu:javascript",
185
171
  plugins: {
186
172
  "antfu": default2,
187
- "unused-imports": default10
173
+ "unused-imports": default6
188
174
  },
189
175
  rules: {
190
176
  "accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
@@ -369,7 +355,7 @@ function javascript(options = {}) {
369
355
  }
370
356
 
371
357
  // src/configs/jsdoc.ts
372
- function jsdoc(options = {}) {
358
+ async function jsdoc(options = {}) {
373
359
  const {
374
360
  stylistic: stylistic2 = true
375
361
  } = options;
@@ -377,7 +363,8 @@ function jsdoc(options = {}) {
377
363
  {
378
364
  name: "antfu:jsdoc",
379
365
  plugins: {
380
- jsdoc: default4
366
+ // @ts-expect-error missing types
367
+ jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
381
368
  },
382
369
  rules: {
383
370
  "jsdoc/check-access": "warn",
@@ -404,8 +391,30 @@ function jsdoc(options = {}) {
404
391
  ];
405
392
  }
406
393
 
394
+ // src/utils.ts
395
+ async function combine(...configs) {
396
+ const resolved = await Promise.all(configs);
397
+ return resolved.flat();
398
+ }
399
+ function renameRules(rules, from, to) {
400
+ return Object.fromEntries(
401
+ Object.entries(rules).map(([key, value]) => {
402
+ if (key.startsWith(from))
403
+ return [to + key.slice(from.length), value];
404
+ return [key, value];
405
+ })
406
+ );
407
+ }
408
+ function toArray(value) {
409
+ return Array.isArray(value) ? value : [value];
410
+ }
411
+ async function interopDefault(m) {
412
+ const resolved = await m;
413
+ return resolved.default || resolved;
414
+ }
415
+
407
416
  // src/configs/jsonc.ts
408
- function jsonc(options = {}) {
417
+ async function jsonc(options = {}) {
409
418
  const {
410
419
  overrides = {},
411
420
  stylistic: stylistic2 = true
@@ -413,6 +422,13 @@ function jsonc(options = {}) {
413
422
  const {
414
423
  indent = 2
415
424
  } = typeof stylistic2 === "boolean" ? {} : stylistic2;
425
+ const [
426
+ pluginJsonc,
427
+ parserJsonc
428
+ ] = await Promise.all([
429
+ interopDefault(import("eslint-plugin-jsonc")),
430
+ interopDefault(import("jsonc-eslint-parser"))
431
+ ]);
416
432
  return [
417
433
  {
418
434
  name: "antfu:jsonc:setup",
@@ -423,7 +439,7 @@ function jsonc(options = {}) {
423
439
  {
424
440
  files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
425
441
  languageOptions: {
426
- parser: default17
442
+ parser: parserJsonc
427
443
  },
428
444
  name: "antfu:jsonc:rules",
429
445
  rules: {
@@ -472,7 +488,7 @@ function jsonc(options = {}) {
472
488
  }
473
489
 
474
490
  // src/configs/markdown.ts
475
- function markdown(options = {}) {
491
+ async function markdown(options = {}) {
476
492
  const {
477
493
  componentExts = [],
478
494
  overrides = {}
@@ -481,7 +497,8 @@ function markdown(options = {}) {
481
497
  {
482
498
  name: "antfu:markdown:setup",
483
499
  plugins: {
484
- markdown: default5
500
+ // @ts-expect-error missing types
501
+ markdown: await interopDefault(import("eslint-plugin-markdown"))
485
502
  }
486
503
  },
487
504
  {
@@ -553,12 +570,12 @@ function markdown(options = {}) {
553
570
  }
554
571
 
555
572
  // src/configs/node.ts
556
- function node() {
573
+ async function node() {
557
574
  return [
558
575
  {
559
576
  name: "antfu:node",
560
577
  plugins: {
561
- node: default6
578
+ node: default4
562
579
  },
563
580
  rules: {
564
581
  "node/handle-callback-err": ["error", "^(err|error)$"],
@@ -575,7 +592,7 @@ function node() {
575
592
  }
576
593
 
577
594
  // src/configs/sort.ts
578
- function sortPackageJson() {
595
+ async function sortPackageJson() {
579
596
  return [
580
597
  {
581
598
  files: ["**/package.json"],
@@ -791,14 +808,15 @@ function sortTsconfig() {
791
808
  }
792
809
 
793
810
  // src/configs/stylistic.ts
794
- function stylistic(options = {}) {
811
+ async function stylistic(options = {}) {
795
812
  const {
796
813
  indent = 2,
797
814
  jsx = true,
798
815
  quotes = "single",
799
816
  semi = false
800
817
  } = options;
801
- const config = default7.configs.customize({
818
+ const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
819
+ const config = pluginStylistic.configs.customize({
802
820
  flat: true,
803
821
  indent,
804
822
  jsx,
@@ -811,7 +829,7 @@ function stylistic(options = {}) {
811
829
  name: "antfu:stylistic",
812
830
  plugins: {
813
831
  antfu: default2,
814
- style: default7
832
+ style: pluginStylistic
815
833
  },
816
834
  rules: {
817
835
  ...config.rules,
@@ -827,26 +845,7 @@ function stylistic(options = {}) {
827
845
 
828
846
  // src/configs/typescript.ts
829
847
  import process from "process";
830
-
831
- // src/utils.ts
832
- function combine(...configs) {
833
- return configs.flat();
834
- }
835
- function renameRules(rules, from, to) {
836
- return Object.fromEntries(
837
- Object.entries(rules).map(([key, value]) => {
838
- if (key.startsWith(from))
839
- return [to + key.slice(from.length), value];
840
- return [key, value];
841
- })
842
- );
843
- }
844
- function toArray(value) {
845
- return Array.isArray(value) ? value : [value];
846
- }
847
-
848
- // src/configs/typescript.ts
849
- function typescript(options) {
848
+ async function typescript(options) {
850
849
  const {
851
850
  componentExts = [],
852
851
  overrides = {},
@@ -874,14 +873,20 @@ function typescript(options) {
874
873
  "ts/unbound-method": "error"
875
874
  };
876
875
  const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
876
+ const [
877
+ pluginTs,
878
+ parserTs
879
+ ] = await Promise.all([
880
+ interopDefault(import("@typescript-eslint/eslint-plugin")),
881
+ interopDefault(import("@typescript-eslint/parser"))
882
+ ]);
877
883
  return [
878
884
  {
879
885
  // Install the plugins without globs, so they can be configured separately.
880
886
  name: "antfu:typescript:setup",
881
887
  plugins: {
882
888
  antfu: default2,
883
- import: pluginImport,
884
- ts: default8
889
+ ts: pluginTs
885
890
  }
886
891
  },
887
892
  {
@@ -904,12 +909,12 @@ function typescript(options) {
904
909
  name: "antfu:typescript:rules",
905
910
  rules: {
906
911
  ...renameRules(
907
- default8.configs["eslint-recommended"].overrides[0].rules,
912
+ pluginTs.configs["eslint-recommended"].overrides[0].rules,
908
913
  "@typescript-eslint/",
909
914
  "ts/"
910
915
  ),
911
916
  ...renameRules(
912
- default8.configs.strict.rules,
917
+ pluginTs.configs.strict.rules,
913
918
  "@typescript-eslint/",
914
919
  "ts/"
915
920
  ),
@@ -975,12 +980,12 @@ function typescript(options) {
975
980
  }
976
981
 
977
982
  // src/configs/unicorn.ts
978
- function unicorn() {
983
+ async function unicorn() {
979
984
  return [
980
985
  {
981
986
  name: "antfu:unicorn",
982
987
  plugins: {
983
- unicorn: default9
988
+ unicorn: default5
984
989
  },
985
990
  rules: {
986
991
  // Pass error message when throwing errors
@@ -1015,7 +1020,7 @@ function unicorn() {
1015
1020
  }
1016
1021
 
1017
1022
  // src/configs/vue.ts
1018
- function vue(options = {}) {
1023
+ async function vue(options = {}) {
1019
1024
  const {
1020
1025
  overrides = {},
1021
1026
  stylistic: stylistic2 = true
@@ -1023,33 +1028,41 @@ function vue(options = {}) {
1023
1028
  const {
1024
1029
  indent = 2
1025
1030
  } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1031
+ const [
1032
+ pluginVue,
1033
+ parserVue
1034
+ ] = await Promise.all([
1035
+ // @ts-expect-error missing types
1036
+ interopDefault(import("eslint-plugin-vue")),
1037
+ interopDefault(import("vue-eslint-parser"))
1038
+ ]);
1026
1039
  return [
1027
1040
  {
1028
1041
  name: "antfu:vue:setup",
1029
1042
  plugins: {
1030
- vue: default11
1043
+ vue: pluginVue
1031
1044
  }
1032
1045
  },
1033
1046
  {
1034
1047
  files: [GLOB_VUE],
1035
1048
  languageOptions: {
1036
- parser: default15,
1049
+ parser: parserVue,
1037
1050
  parserOptions: {
1038
1051
  ecmaFeatures: {
1039
1052
  jsx: true
1040
1053
  },
1041
1054
  extraFileExtensions: [".vue"],
1042
- parser: options.typescript ? parserTs : null,
1055
+ parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1043
1056
  sourceType: "module"
1044
1057
  }
1045
1058
  },
1046
1059
  name: "antfu:vue:rules",
1047
- processor: default11.processors[".vue"],
1060
+ processor: pluginVue.processors[".vue"],
1048
1061
  rules: {
1049
- ...default11.configs.base.rules,
1050
- ...default11.configs["vue3-essential"].rules,
1051
- ...default11.configs["vue3-strongly-recommended"].rules,
1052
- ...default11.configs["vue3-recommended"].rules,
1062
+ ...pluginVue.configs.base.rules,
1063
+ ...pluginVue.configs["vue3-essential"].rules,
1064
+ ...pluginVue.configs["vue3-strongly-recommended"].rules,
1065
+ ...pluginVue.configs["vue3-recommended"].rules,
1053
1066
  "node/prefer-global/process": "off",
1054
1067
  "vue/block-order": ["error", {
1055
1068
  order: ["script", "template", "style"]
@@ -1132,7 +1145,7 @@ function vue(options = {}) {
1132
1145
  }
1133
1146
 
1134
1147
  // src/configs/yaml.ts
1135
- function yaml(options = {}) {
1148
+ async function yaml(options = {}) {
1136
1149
  const {
1137
1150
  overrides = {},
1138
1151
  stylistic: stylistic2 = true
@@ -1141,6 +1154,13 @@ function yaml(options = {}) {
1141
1154
  indent = 2,
1142
1155
  quotes = "single"
1143
1156
  } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1157
+ const [
1158
+ pluginYaml,
1159
+ parserYaml
1160
+ ] = await Promise.all([
1161
+ interopDefault(import("eslint-plugin-yml")),
1162
+ interopDefault(import("yaml-eslint-parser"))
1163
+ ]);
1144
1164
  return [
1145
1165
  {
1146
1166
  name: "antfu:yaml:setup",
@@ -1151,7 +1171,7 @@ function yaml(options = {}) {
1151
1171
  {
1152
1172
  files: [GLOB_YAML],
1153
1173
  languageOptions: {
1154
- parser: default16
1174
+ parser: parserYaml
1155
1175
  },
1156
1176
  name: "antfu:yaml:rules",
1157
1177
  rules: {
@@ -1183,21 +1203,29 @@ function yaml(options = {}) {
1183
1203
  }
1184
1204
 
1185
1205
  // src/configs/test.ts
1186
- function test(options = {}) {
1206
+ async function test(options = {}) {
1187
1207
  const {
1188
1208
  isInEditor = false,
1189
1209
  overrides = {}
1190
1210
  } = options;
1211
+ const [
1212
+ pluginVitest,
1213
+ pluginNoOnlyTests
1214
+ ] = await Promise.all([
1215
+ interopDefault(import("eslint-plugin-vitest")),
1216
+ // @ts-expect-error missing types
1217
+ interopDefault(import("eslint-plugin-no-only-tests"))
1218
+ ]);
1191
1219
  return [
1192
1220
  {
1193
1221
  name: "antfu:test:setup",
1194
1222
  plugins: {
1195
1223
  test: {
1196
- ...default13,
1224
+ ...pluginVitest,
1197
1225
  rules: {
1198
- ...default13.rules,
1226
+ ...pluginVitest.rules,
1199
1227
  // extend `test/no-only-tests` rule
1200
- ...default12.rules
1228
+ ...pluginNoOnlyTests.rules
1201
1229
  }
1202
1230
  }
1203
1231
  }
@@ -1219,12 +1247,12 @@ function test(options = {}) {
1219
1247
  }
1220
1248
 
1221
1249
  // src/configs/perfectionist.ts
1222
- function perfectionist() {
1250
+ async function perfectionist() {
1223
1251
  return [
1224
1252
  {
1225
1253
  name: "antfu:perfectionist",
1226
1254
  plugins: {
1227
- perfectionist: default14
1255
+ perfectionist: default7
1228
1256
  }
1229
1257
  }
1230
1258
  ];
@@ -1247,7 +1275,7 @@ var VuePackages = [
1247
1275
  "vitepress",
1248
1276
  "@slidev/cli"
1249
1277
  ];
1250
- function antfu(options = {}, ...userConfigs) {
1278
+ async function antfu(options = {}, ...userConfigs) {
1251
1279
  const {
1252
1280
  componentExts = [],
1253
1281
  gitignore: enableGitignore = true,
@@ -1262,10 +1290,10 @@ function antfu(options = {}, ...userConfigs) {
1262
1290
  const configs = [];
1263
1291
  if (enableGitignore) {
1264
1292
  if (typeof enableGitignore !== "boolean") {
1265
- configs.push([gitignore(enableGitignore)]);
1293
+ configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
1266
1294
  } else {
1267
1295
  if (fs.existsSync(".gitignore"))
1268
- configs.push([gitignore()]);
1296
+ configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
1269
1297
  }
1270
1298
  }
1271
1299
  configs.push(
@@ -1376,32 +1404,13 @@ export {
1376
1404
  src_default as default,
1377
1405
  ignores,
1378
1406
  imports,
1407
+ interopDefault,
1379
1408
  javascript,
1380
1409
  jsdoc,
1381
1410
  jsonc,
1382
1411
  markdown,
1383
1412
  node,
1384
- default17 as parserJsonc,
1385
- parserTs,
1386
- default15 as parserVue,
1387
- default16 as parserYaml,
1388
1413
  perfectionist,
1389
- default2 as pluginAntfu,
1390
- default3 as pluginComments,
1391
- pluginImport,
1392
- default4 as pluginJsdoc,
1393
- pluginJsonc,
1394
- default5 as pluginMarkdown,
1395
- default12 as pluginNoOnlyTests,
1396
- default6 as pluginNode,
1397
- default14 as pluginPerfectionist,
1398
- default7 as pluginStylistic,
1399
- default8 as pluginTs,
1400
- default9 as pluginUnicorn,
1401
- default10 as pluginUnusedImports,
1402
- default13 as pluginVitest,
1403
- default11 as pluginVue,
1404
- pluginYaml,
1405
1414
  renameRules,
1406
1415
  sortPackageJson,
1407
1416
  sortTsconfig,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antfu/eslint-config",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "2.0.0",
5
5
  "packageManager": "pnpm@8.10.5",
6
6
  "description": "Anthony's ESLint config",
7
7
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -30,9 +30,9 @@
30
30
  "dependencies": {
31
31
  "@antfu/eslint-define-config": "^1.23.0-2",
32
32
  "@eslint-types/jsdoc": "46.8.2-1",
33
- "@eslint-types/typescript-eslint": "^6.9.1",
33
+ "@eslint-types/typescript-eslint": "^6.11.0",
34
34
  "@eslint-types/unicorn": "^49.0.0",
35
- "@stylistic/eslint-plugin": "^1.3.1",
35
+ "@stylistic/eslint-plugin": "^1.4.0",
36
36
  "@typescript-eslint/eslint-plugin": "^6.11.0",
37
37
  "@typescript-eslint/parser": "^6.11.0",
38
38
  "eslint-config-flat-gitignore": "^0.1.1",
@@ -69,8 +69,8 @@
69
69
  "@types/prompts": "^2.4.8",
70
70
  "@types/yargs": "^17.0.31",
71
71
  "bumpp": "^9.2.0",
72
- "eslint": "^8.53.0",
73
- "eslint-flat-config-viewer": "^0.1.1",
72
+ "eslint": "^8.54.0",
73
+ "eslint-flat-config-viewer": "^0.1.2",
74
74
  "esno": "^4.0.0",
75
75
  "fast-glob": "^3.3.2",
76
76
  "fs-extra": "^11.1.1",
@@ -80,7 +80,7 @@
80
80
  "tsup": "^7.3.0",
81
81
  "typescript": "^5.2.2",
82
82
  "vitest": "^0.34.6",
83
- "@antfu/eslint-config": "1.2.0"
83
+ "@antfu/eslint-config": "2.0.0"
84
84
  },
85
85
  "simple-git-hooks": {
86
86
  "pre-commit": "pnpm lint-staged"