@coderwyd/eslint-config 2.1.5 → 2.1.6

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/README.md CHANGED
@@ -218,10 +218,11 @@ interface OptionsConfig {
218
218
  * {
219
219
  * "html": true,
220
220
  * "css": true,
221
- * "graphql": true,
222
- * "markdown": true
223
- * "yaml": true
224
- * "toml": true
221
+ * "json": true,
222
+ * "graphql": false,
223
+ * "markdown": false
224
+ * "yaml": false
225
+ * "toml": false
225
226
  * }
226
227
  */
227
228
  formatter?: OptionsFormatters
package/dist/cli.cjs CHANGED
@@ -46,7 +46,7 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
46
46
  var import_picocolors = __toESM(require("picocolors"), 1);
47
47
 
48
48
  // package.json
49
- var version = "2.1.5";
49
+ var version = "2.1.6";
50
50
  var devDependencies = {
51
51
  "@antfu/ni": "^0.21.12",
52
52
  "@types/eslint": "^8.56.2",
@@ -131,7 +131,11 @@ async function run(options = {}) {
131
131
  const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
132
132
  const pathESLintIngore = import_node_path.default.join(cwd, ".eslintignore");
133
133
  if (import_node_fs.default.existsSync(pathFlatConfig)) {
134
- console.log(import_picocolors2.default.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
134
+ console.log(
135
+ import_picocolors2.default.yellow(
136
+ `${WARN} eslint.config.js already exists, migration wizard exited.`
137
+ )
138
+ );
135
139
  return import_node_process.default.exit(1);
136
140
  }
137
141
  if (!SKIP_GIT_CHECK && !isGitClean()) {
@@ -163,7 +167,9 @@ async function run(options = {}) {
163
167
  if (glob.type === "ignore")
164
168
  eslintIgnores.push(...glob.patterns);
165
169
  else if (glob.type === "unignore")
166
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
170
+ eslintIgnores.push(
171
+ ...glob.patterns.map((pattern) => `!${pattern}`)
172
+ );
167
173
  }
168
174
  }
169
175
  let eslintConfigContent = "";
@@ -240,8 +246,10 @@ ${coderwydConfig}
240
246
  }
241
247
  }
242
248
  console.log(import_picocolors2.default.green(`${CHECK} migration completed`));
243
- console.log(`Now you can update the dependencies and run ${import_picocolors2.default.blue("eslint . --fix")}
244
- `);
249
+ console.log(
250
+ `Now you can update the dependencies and run ${import_picocolors2.default.blue("eslint . --fix")}
251
+ `
252
+ );
245
253
  }
246
254
 
247
255
  // src/cli/index.ts
package/dist/cli.js CHANGED
@@ -17,7 +17,7 @@ import parse from "parse-gitignore";
17
17
  import c from "picocolors";
18
18
 
19
19
  // package.json
20
- var version = "2.1.5";
20
+ var version = "2.1.6";
21
21
  var devDependencies = {
22
22
  "@antfu/ni": "^0.21.12",
23
23
  "@types/eslint": "^8.56.2",
@@ -102,7 +102,11 @@ async function run(options = {}) {
102
102
  const pathPackageJSON = path.join(cwd, "package.json");
103
103
  const pathESLintIngore = path.join(cwd, ".eslintignore");
104
104
  if (fs.existsSync(pathFlatConfig)) {
105
- console.log(c2.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
105
+ console.log(
106
+ c2.yellow(
107
+ `${WARN} eslint.config.js already exists, migration wizard exited.`
108
+ )
109
+ );
106
110
  return process.exit(1);
107
111
  }
108
112
  if (!SKIP_GIT_CHECK && !isGitClean()) {
@@ -134,7 +138,9 @@ async function run(options = {}) {
134
138
  if (glob.type === "ignore")
135
139
  eslintIgnores.push(...glob.patterns);
136
140
  else if (glob.type === "unignore")
137
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
141
+ eslintIgnores.push(
142
+ ...glob.patterns.map((pattern) => `!${pattern}`)
143
+ );
138
144
  }
139
145
  }
140
146
  let eslintConfigContent = "";
@@ -211,8 +217,10 @@ ${coderwydConfig}
211
217
  }
212
218
  }
213
219
  console.log(c2.green(`${CHECK} migration completed`));
214
- console.log(`Now you can update the dependencies and run ${c2.blue("eslint . --fix")}
215
- `);
220
+ console.log(
221
+ `Now you can update the dependencies and run ${c2.blue("eslint . --fix")}
222
+ `
223
+ );
216
224
  }
217
225
 
218
226
  // src/cli/index.ts
package/dist/index.cjs CHANGED
@@ -156,7 +156,10 @@ async function imports() {
156
156
  "antfu/no-import-dist": "error",
157
157
  "antfu/no-import-node-modules-by-path": "error",
158
158
  "import/first": "error",
159
- "import/newline-after-import": ["error", { considerComments: true, count: 1 }],
159
+ "import/newline-after-import": [
160
+ "error",
161
+ { considerComments: true, count: 1 }
162
+ ],
160
163
  "import/no-duplicates": "error",
161
164
  "import/no-mutable-exports": "error",
162
165
  "import/no-named-default": "error",
@@ -165,7 +168,16 @@ async function imports() {
165
168
  "import/order": [
166
169
  "error",
167
170
  {
168
- groups: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
171
+ groups: [
172
+ "builtin",
173
+ "external",
174
+ "internal",
175
+ "parent",
176
+ "sibling",
177
+ "index",
178
+ "object",
179
+ "type"
180
+ ],
169
181
  pathGroups: [{ group: "internal", pattern: "{{@,~}/,#}**" }],
170
182
  pathGroupsExcludedImportTypes: ["type"]
171
183
  }
@@ -216,14 +228,20 @@ async function javascript(options = {}) {
216
228
  "unused-imports": import_eslint_plugin_unused_imports.default
217
229
  },
218
230
  rules: {
219
- "accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
231
+ "accessor-pairs": [
232
+ "error",
233
+ { enforceForClassMembers: true, setWithoutGet: true }
234
+ ],
220
235
  "array-callback-return": "error",
221
236
  "block-scoped-var": "error",
222
237
  "constructor-super": "error",
223
238
  "default-case-last": "error",
224
239
  "dot-notation": ["error", { allowKeywords: true }],
225
240
  eqeqeq: ["error", "smart"],
226
- "new-cap": ["error", { capIsNew: false, newIsCap: true, properties: true }],
241
+ "new-cap": [
242
+ "error",
243
+ { capIsNew: false, newIsCap: true, properties: true }
244
+ ],
227
245
  "no-alert": "error",
228
246
  "no-array-constructor": "error",
229
247
  "no-async-promise-executor": "error",
@@ -344,7 +362,10 @@ async function javascript(options = {}) {
344
362
  vars: "all"
345
363
  }
346
364
  ],
347
- "no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
365
+ "no-use-before-define": [
366
+ "error",
367
+ { classes: false, functions: false, variables: true }
368
+ ],
348
369
  "no-useless-backreference": "error",
349
370
  "no-useless-call": "error",
350
371
  "no-useless-catch": "error",
@@ -405,7 +426,10 @@ async function javascript(options = {}) {
405
426
  varsIgnorePattern: "^_"
406
427
  }
407
428
  ],
408
- "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
429
+ "use-isnan": [
430
+ "error",
431
+ { enforceForIndexOf: true, enforceForSwitchCase: true }
432
+ ],
409
433
  "valid-typeof": ["error", { requireStringLiterals: true }],
410
434
  "vars-on-top": "error",
411
435
  yoda: ["error", "never"],
@@ -488,7 +512,9 @@ async function ensurePackages(packages) {
488
512
  }
489
513
  ]);
490
514
  if (result)
491
- await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
515
+ await import("@antfu/install-pkg").then(
516
+ (i) => i.installPackage(nonExistingPackages, { dev: true })
517
+ );
492
518
  }
493
519
  async function loadPrettierConfig(cwd) {
494
520
  let prettierConfig = {};
@@ -704,7 +730,14 @@ function sortTsconfig() {
704
730
  "jsonc/sort-keys": [
705
731
  "error",
706
732
  {
707
- order: ["extends", "compilerOptions", "references", "files", "include", "exclude"],
733
+ order: [
734
+ "extends",
735
+ "compilerOptions",
736
+ "references",
737
+ "files",
738
+ "include",
739
+ "exclude"
740
+ ],
708
741
  pathPattern: "^$"
709
742
  },
710
743
  {
@@ -848,7 +881,10 @@ async function prettier(rules) {
848
881
  var import_node_process2 = __toESM(require("process"), 1);
849
882
  async function typescript(options = {}) {
850
883
  const { componentExts = [], overrides = {}, parserOptions = {} } = options;
851
- const files = options.files ?? [GLOB_SRC, ...componentExts.map((ext) => `**/*.${ext}`)];
884
+ const files = options.files ?? [
885
+ GLOB_SRC,
886
+ ...componentExts.map((ext) => `**/*.${ext}`)
887
+ ];
852
888
  const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
853
889
  const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
854
890
  const isTypeAware = !!tsconfigPath;
@@ -906,22 +942,41 @@ async function typescript(options = {}) {
906
942
  }
907
943
  },
908
944
  // assign type-aware parser for type-aware files and type-unaware parser for the rest
909
- ...isTypeAware ? [makeParser(true, filesTypeAware), makeParser(false, files, filesTypeAware)] : [makeParser(false, files)],
945
+ ...isTypeAware ? [
946
+ makeParser(true, filesTypeAware),
947
+ makeParser(false, files, filesTypeAware)
948
+ ] : [makeParser(false, files)],
910
949
  {
911
950
  files,
912
951
  name: "coderwyd:typescript:rules",
913
952
  rules: {
914
- ...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, "@typescript-eslint/", "ts/"),
915
- ...renameRules(pluginTs.configs.strict.rules, "@typescript-eslint/", "ts/"),
953
+ ...renameRules(
954
+ pluginTs.configs["eslint-recommended"].overrides[0].rules,
955
+ "@typescript-eslint/",
956
+ "ts/"
957
+ ),
958
+ ...renameRules(
959
+ pluginTs.configs.strict.rules,
960
+ "@typescript-eslint/",
961
+ "ts/"
962
+ ),
916
963
  "no-dupe-class-members": "off",
917
964
  "no-loss-of-precision": "off",
918
965
  "no-redeclare": "off",
919
966
  "no-use-before-define": "off",
920
967
  "no-useless-constructor": "off",
921
- "ts/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }],
968
+ "ts/ban-ts-comment": [
969
+ "error",
970
+ { "ts-ignore": "allow-with-description" }
971
+ ],
922
972
  "ts/ban-types": ["error", { types: { Function: false } }],
923
973
  "ts/consistent-type-definitions": ["error", "interface"],
924
- "ts/consistent-type-imports": ["error", { disallowTypeAnnotations: false, prefer: "type-imports" }],
974
+ "ts/consistent-type-imports": [
975
+ "error",
976
+ { disallowTypeAnnotations: false, prefer: "type-imports" }
977
+ ],
978
+ "ts/method-signature-style": ["error", "property"],
979
+ // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
925
980
  "ts/no-dupe-class-members": "error",
926
981
  "ts/no-dynamic-delete": "off",
927
982
  "ts/no-explicit-any": "off",
@@ -933,7 +988,10 @@ async function typescript(options = {}) {
933
988
  "ts/no-redeclare": "error",
934
989
  "ts/no-require-imports": "error",
935
990
  "ts/no-unused-vars": "off",
936
- "ts/no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
991
+ "ts/no-use-before-define": [
992
+ "error",
993
+ { classes: false, functions: false, variables: true }
994
+ ],
937
995
  "ts/no-useless-constructor": "off",
938
996
  "ts/prefer-ts-expect-error": "error",
939
997
  "ts/triple-slash-reference": "off",
@@ -1083,7 +1141,9 @@ async function vue(options = {}) {
1083
1141
  jsx: true
1084
1142
  },
1085
1143
  extraFileExtensions: [".vue"],
1086
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1144
+ parser: options.typescript ? await interopDefault(
1145
+ import("@typescript-eslint/parser")
1146
+ ) : null,
1087
1147
  sourceType: "module"
1088
1148
  }
1089
1149
  },
@@ -1105,7 +1165,12 @@ async function vue(options = {}) {
1105
1165
  "vue/define-macros-order": [
1106
1166
  "error",
1107
1167
  {
1108
- order: ["defineOptions", "defineProps", "defineEmits", "defineSlots"]
1168
+ order: [
1169
+ "defineOptions",
1170
+ "defineProps",
1171
+ "defineEmits",
1172
+ "defineSlots"
1173
+ ]
1109
1174
  }
1110
1175
  ],
1111
1176
  "vue/dot-location": ["error", "property"],
@@ -1133,7 +1198,12 @@ async function vue(options = {}) {
1133
1198
  "vue/no-extra-parens": ["error", "functions"],
1134
1199
  "vue/no-irregular-whitespace": "error",
1135
1200
  "vue/no-loss-of-precision": "error",
1136
- "vue/no-restricted-syntax": ["error", "DebuggerStatement", "LabeledStatement", "WithStatement"],
1201
+ "vue/no-restricted-syntax": [
1202
+ "error",
1203
+ "DebuggerStatement",
1204
+ "LabeledStatement",
1205
+ "WithStatement"
1206
+ ],
1137
1207
  "vue/no-restricted-v-bind": ["error", "/^v-/"],
1138
1208
  "vue/no-setup-props-reactivity-loss": "off",
1139
1209
  "vue/no-sparse-arrays": "error",
@@ -1190,7 +1260,10 @@ async function test(options = {}) {
1190
1260
  name: "coderwyd:test:rules",
1191
1261
  rules: {
1192
1262
  "node/prefer-global/process": "off",
1193
- "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
1263
+ "test/consistent-test-it": [
1264
+ "error",
1265
+ { fn: "it", withinDescribe: "it" }
1266
+ ],
1194
1267
  "test/no-identical-title": "error",
1195
1268
  "test/no-import-node-test": "error",
1196
1269
  "test/no-only-tests": isInEditor ? "off" : "error",
@@ -1218,14 +1291,26 @@ async function perfectionist() {
1218
1291
  var import_local_pkg2 = require("local-pkg");
1219
1292
  var ReactRefreshAllowConstantExportPackages = ["vite"];
1220
1293
  async function react(options = {}) {
1221
- const { files = [GLOB_JSX, GLOB_TSX], overrides = {}, typescript: typescript2 = true } = options;
1222
- await ensurePackages(["eslint-plugin-react", "eslint-plugin-react-hooks", "eslint-plugin-react-refresh"]);
1223
- const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
1224
- interopDefault(import("eslint-plugin-react")),
1225
- interopDefault(import("eslint-plugin-react-hooks")),
1226
- interopDefault(import("eslint-plugin-react-refresh"))
1294
+ const {
1295
+ files = [GLOB_JSX, GLOB_TSX],
1296
+ overrides = {},
1297
+ typescript: typescript2 = true
1298
+ } = options;
1299
+ await ensurePackages([
1300
+ "eslint-plugin-react",
1301
+ "eslint-plugin-react-hooks",
1302
+ "eslint-plugin-react-refresh"
1227
1303
  ]);
1228
- const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => (0, import_local_pkg2.isPackageExists)(i));
1304
+ const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
1305
+ [
1306
+ interopDefault(import("eslint-plugin-react")),
1307
+ interopDefault(import("eslint-plugin-react-hooks")),
1308
+ interopDefault(import("eslint-plugin-react-refresh"))
1309
+ ]
1310
+ );
1311
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1312
+ (i) => (0, import_local_pkg2.isPackageExists)(i)
1313
+ );
1229
1314
  return [
1230
1315
  {
1231
1316
  name: "coderwyd:react:setup",
@@ -1255,7 +1340,10 @@ async function react(options = {}) {
1255
1340
  "react-hooks/exhaustive-deps": "warn",
1256
1341
  "react-hooks/rules-of-hooks": "error",
1257
1342
  // react refresh
1258
- "react-refresh/only-export-components": ["warn", { allowConstantExport: isAllowConstantExport }],
1343
+ "react-refresh/only-export-components": [
1344
+ "warn",
1345
+ { allowConstantExport: isAllowConstantExport }
1346
+ ],
1259
1347
  // recommended rules react
1260
1348
  "react/display-name": "error",
1261
1349
  "react/jsx-key": "error",
@@ -1294,7 +1382,9 @@ async function react(options = {}) {
1294
1382
  async function unocss(options = {}) {
1295
1383
  const { attributify = true, strict = false } = options;
1296
1384
  await ensurePackages(["@unocss/eslint-plugin"]);
1297
- const [pluginUnoCSS] = await Promise.all([interopDefault(import("@unocss/eslint-plugin"))]);
1385
+ const [pluginUnoCSS] = await Promise.all([
1386
+ interopDefault(import("@unocss/eslint-plugin"))
1387
+ ]);
1298
1388
  return [
1299
1389
  {
1300
1390
  name: "coderwyd:unocss",
@@ -1317,7 +1407,15 @@ async function unocss(options = {}) {
1317
1407
  // src/configs/formatter.ts
1318
1408
  async function formatter(options = {}, prettierRules2 = {}) {
1319
1409
  await ensurePackages(["eslint-plugin-prettier"]);
1320
- const { css = true, graphql, html = true, markdown, toml, yaml } = options || {};
1410
+ const {
1411
+ css = true,
1412
+ graphql,
1413
+ html = true,
1414
+ json = true,
1415
+ markdown,
1416
+ toml,
1417
+ yaml
1418
+ } = options || {};
1321
1419
  const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
1322
1420
  function createPrettierFormatter(files, parser, plugins) {
1323
1421
  const rules = {
@@ -1342,7 +1440,10 @@ async function formatter(options = {}, prettierRules2 = {}) {
1342
1440
  prettier: pluginPrettier
1343
1441
  },
1344
1442
  rules: {
1345
- "prettier/prettier": ["warn", parser === "markdown" ? markdownRules : rules]
1443
+ "prettier/prettier": [
1444
+ "warn",
1445
+ parser === "markdown" ? markdownRules : rules
1446
+ ]
1346
1447
  }
1347
1448
  };
1348
1449
  return config;
@@ -1355,15 +1456,20 @@ async function formatter(options = {}, prettierRules2 = {}) {
1355
1456
  }
1356
1457
  }
1357
1458
  ];
1459
+ if (html) {
1460
+ const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
1461
+ configs.push(htmlConfig);
1462
+ }
1358
1463
  if (css) {
1359
1464
  const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], "css");
1360
1465
  const scssConfig = createPrettierFormatter([GLOB_SCSS], "scss");
1361
1466
  const lessConfig = createPrettierFormatter([GLOB_LESS], "less");
1362
1467
  configs.push(cssConfig, scssConfig, lessConfig);
1363
1468
  }
1364
- if (html) {
1365
- const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
1366
- configs.push(htmlConfig);
1469
+ if (json) {
1470
+ const jsonConfig = createPrettierFormatter([GLOB_JSON, GLOB_JSONC], "json");
1471
+ const json5Config = createPrettierFormatter([GLOB_JSON5], "json5");
1472
+ configs.push(jsonConfig, json5Config);
1367
1473
  }
1368
1474
  if (markdown) {
1369
1475
  const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], "markdown");
@@ -1379,7 +1485,9 @@ async function formatter(options = {}, prettierRules2 = {}) {
1379
1485
  }
1380
1486
  if (toml) {
1381
1487
  await ensurePackages(["@toml-tools/parser", "prettier-plugin-toml"]);
1382
- const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", ["prettier-plugin-toml"]);
1488
+ const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", [
1489
+ "prettier-plugin-toml"
1490
+ ]);
1383
1491
  configs.push(tomlConfig);
1384
1492
  }
1385
1493
  return configs;
@@ -1406,7 +1514,9 @@ async function svelte(options = {}) {
1406
1514
  parser: parserSvelte,
1407
1515
  parserOptions: {
1408
1516
  extraFileExtensions: [".svelte"],
1409
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null
1517
+ parser: options.typescript ? await interopDefault(
1518
+ import("@typescript-eslint/parser")
1519
+ ) : null
1410
1520
  }
1411
1521
  },
1412
1522
  name: "coderwyd:svelte:rules",
@@ -1463,6 +1573,7 @@ async function svelte(options = {}) {
1463
1573
 
1464
1574
  // src/index.ts
1465
1575
  var flatConfigProps = [
1576
+ "name",
1466
1577
  "files",
1467
1578
  "ignores",
1468
1579
  "languageOptions",
@@ -1488,10 +1599,18 @@ async function defineConfig(options = {}, ...userConfigs) {
1488
1599
  const configs = [];
1489
1600
  if (enableGitignore) {
1490
1601
  if (typeof enableGitignore !== "boolean") {
1491
- configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
1602
+ configs.push(
1603
+ interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1604
+ r(enableGitignore)
1605
+ ])
1606
+ );
1492
1607
  } else {
1493
1608
  if (import_node_fs.default.existsSync(".gitignore"))
1494
- configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
1609
+ configs.push(
1610
+ interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1611
+ r()
1612
+ ])
1613
+ );
1495
1614
  }
1496
1615
  }
1497
1616
  configs.push(
@@ -1576,10 +1695,15 @@ async function defineConfig(options = {}, ...userConfigs) {
1576
1695
  prettierRules2 = { ...prettierRules2, ...options.prettierRules };
1577
1696
  }
1578
1697
  if (usePrettierrc) {
1579
- const prettierConfig = await loadPrettierConfig(options.cwd ?? import_node_process3.default.cwd());
1698
+ const prettierConfig = await loadPrettierConfig(
1699
+ options.cwd ?? import_node_process3.default.cwd()
1700
+ );
1580
1701
  Object.assign(prettierRules2, prettierConfig);
1581
1702
  }
1582
- configs.push(prettier(prettierRules2), formatter(options.formatter, prettierRules2));
1703
+ configs.push(
1704
+ prettier(prettierRules2),
1705
+ formatter(options.formatter, prettierRules2)
1706
+ );
1583
1707
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
1584
1708
  if (key in options)
1585
1709
  acc[key] = options[key];
package/dist/index.d.cts CHANGED
@@ -36,14 +36,18 @@ type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
36
36
  type Awaitable<T> = T | Promise<T>;
37
37
  type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
38
38
  interface OptionsFormatters {
39
+ /**
40
+ * Enable formatting support for HTML.
41
+ */
42
+ html?: boolean;
39
43
  /**
40
44
  * Enable formatting support for CSS, Less, Sass, and SCSS.
41
45
  */
42
46
  css?: boolean;
43
47
  /**
44
- * Enable formatting support for HTML.
48
+ * Enable formatting support for Json.
45
49
  */
46
- html?: boolean;
50
+ json?: boolean;
47
51
  /**
48
52
  * Enable formatting support for Markdown.
49
53
  */
@@ -204,6 +208,7 @@ interface OptionsConfig extends OptionsComponentExts {
204
208
  * {
205
209
  * "html": true,
206
210
  * "css": true,
211
+ * "json": true,
207
212
  * "graphql": false,
208
213
  * "markdown": false
209
214
  * "yaml": false
package/dist/index.d.ts CHANGED
@@ -36,14 +36,18 @@ type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
36
36
  type Awaitable<T> = T | Promise<T>;
37
37
  type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
38
38
  interface OptionsFormatters {
39
+ /**
40
+ * Enable formatting support for HTML.
41
+ */
42
+ html?: boolean;
39
43
  /**
40
44
  * Enable formatting support for CSS, Less, Sass, and SCSS.
41
45
  */
42
46
  css?: boolean;
43
47
  /**
44
- * Enable formatting support for HTML.
48
+ * Enable formatting support for Json.
45
49
  */
46
- html?: boolean;
50
+ json?: boolean;
47
51
  /**
48
52
  * Enable formatting support for Markdown.
49
53
  */
@@ -204,6 +208,7 @@ interface OptionsConfig extends OptionsComponentExts {
204
208
  * {
205
209
  * "html": true,
206
210
  * "css": true,
211
+ * "json": true,
207
212
  * "graphql": false,
208
213
  * "markdown": false
209
214
  * "yaml": false
package/dist/index.js CHANGED
@@ -122,7 +122,10 @@ async function imports() {
122
122
  "antfu/no-import-dist": "error",
123
123
  "antfu/no-import-node-modules-by-path": "error",
124
124
  "import/first": "error",
125
- "import/newline-after-import": ["error", { considerComments: true, count: 1 }],
125
+ "import/newline-after-import": [
126
+ "error",
127
+ { considerComments: true, count: 1 }
128
+ ],
126
129
  "import/no-duplicates": "error",
127
130
  "import/no-mutable-exports": "error",
128
131
  "import/no-named-default": "error",
@@ -131,7 +134,16 @@ async function imports() {
131
134
  "import/order": [
132
135
  "error",
133
136
  {
134
- groups: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
137
+ groups: [
138
+ "builtin",
139
+ "external",
140
+ "internal",
141
+ "parent",
142
+ "sibling",
143
+ "index",
144
+ "object",
145
+ "type"
146
+ ],
135
147
  pathGroups: [{ group: "internal", pattern: "{{@,~}/,#}**" }],
136
148
  pathGroupsExcludedImportTypes: ["type"]
137
149
  }
@@ -182,14 +194,20 @@ async function javascript(options = {}) {
182
194
  "unused-imports": default6
183
195
  },
184
196
  rules: {
185
- "accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }],
197
+ "accessor-pairs": [
198
+ "error",
199
+ { enforceForClassMembers: true, setWithoutGet: true }
200
+ ],
186
201
  "array-callback-return": "error",
187
202
  "block-scoped-var": "error",
188
203
  "constructor-super": "error",
189
204
  "default-case-last": "error",
190
205
  "dot-notation": ["error", { allowKeywords: true }],
191
206
  eqeqeq: ["error", "smart"],
192
- "new-cap": ["error", { capIsNew: false, newIsCap: true, properties: true }],
207
+ "new-cap": [
208
+ "error",
209
+ { capIsNew: false, newIsCap: true, properties: true }
210
+ ],
193
211
  "no-alert": "error",
194
212
  "no-array-constructor": "error",
195
213
  "no-async-promise-executor": "error",
@@ -310,7 +328,10 @@ async function javascript(options = {}) {
310
328
  vars: "all"
311
329
  }
312
330
  ],
313
- "no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
331
+ "no-use-before-define": [
332
+ "error",
333
+ { classes: false, functions: false, variables: true }
334
+ ],
314
335
  "no-useless-backreference": "error",
315
336
  "no-useless-call": "error",
316
337
  "no-useless-catch": "error",
@@ -371,7 +392,10 @@ async function javascript(options = {}) {
371
392
  varsIgnorePattern: "^_"
372
393
  }
373
394
  ],
374
- "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
395
+ "use-isnan": [
396
+ "error",
397
+ { enforceForIndexOf: true, enforceForSwitchCase: true }
398
+ ],
375
399
  "valid-typeof": ["error", { requireStringLiterals: true }],
376
400
  "vars-on-top": "error",
377
401
  yoda: ["error", "never"],
@@ -454,7 +478,9 @@ async function ensurePackages(packages) {
454
478
  }
455
479
  ]);
456
480
  if (result)
457
- await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
481
+ await import("@antfu/install-pkg").then(
482
+ (i) => i.installPackage(nonExistingPackages, { dev: true })
483
+ );
458
484
  }
459
485
  async function loadPrettierConfig(cwd) {
460
486
  let prettierConfig = {};
@@ -670,7 +696,14 @@ function sortTsconfig() {
670
696
  "jsonc/sort-keys": [
671
697
  "error",
672
698
  {
673
- order: ["extends", "compilerOptions", "references", "files", "include", "exclude"],
699
+ order: [
700
+ "extends",
701
+ "compilerOptions",
702
+ "references",
703
+ "files",
704
+ "include",
705
+ "exclude"
706
+ ],
674
707
  pathPattern: "^$"
675
708
  },
676
709
  {
@@ -814,7 +847,10 @@ async function prettier(rules) {
814
847
  import process2 from "node:process";
815
848
  async function typescript(options = {}) {
816
849
  const { componentExts = [], overrides = {}, parserOptions = {} } = options;
817
- const files = options.files ?? [GLOB_SRC, ...componentExts.map((ext) => `**/*.${ext}`)];
850
+ const files = options.files ?? [
851
+ GLOB_SRC,
852
+ ...componentExts.map((ext) => `**/*.${ext}`)
853
+ ];
818
854
  const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
819
855
  const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
820
856
  const isTypeAware = !!tsconfigPath;
@@ -872,22 +908,41 @@ async function typescript(options = {}) {
872
908
  }
873
909
  },
874
910
  // assign type-aware parser for type-aware files and type-unaware parser for the rest
875
- ...isTypeAware ? [makeParser(true, filesTypeAware), makeParser(false, files, filesTypeAware)] : [makeParser(false, files)],
911
+ ...isTypeAware ? [
912
+ makeParser(true, filesTypeAware),
913
+ makeParser(false, files, filesTypeAware)
914
+ ] : [makeParser(false, files)],
876
915
  {
877
916
  files,
878
917
  name: "coderwyd:typescript:rules",
879
918
  rules: {
880
- ...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, "@typescript-eslint/", "ts/"),
881
- ...renameRules(pluginTs.configs.strict.rules, "@typescript-eslint/", "ts/"),
919
+ ...renameRules(
920
+ pluginTs.configs["eslint-recommended"].overrides[0].rules,
921
+ "@typescript-eslint/",
922
+ "ts/"
923
+ ),
924
+ ...renameRules(
925
+ pluginTs.configs.strict.rules,
926
+ "@typescript-eslint/",
927
+ "ts/"
928
+ ),
882
929
  "no-dupe-class-members": "off",
883
930
  "no-loss-of-precision": "off",
884
931
  "no-redeclare": "off",
885
932
  "no-use-before-define": "off",
886
933
  "no-useless-constructor": "off",
887
- "ts/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }],
934
+ "ts/ban-ts-comment": [
935
+ "error",
936
+ { "ts-ignore": "allow-with-description" }
937
+ ],
888
938
  "ts/ban-types": ["error", { types: { Function: false } }],
889
939
  "ts/consistent-type-definitions": ["error", "interface"],
890
- "ts/consistent-type-imports": ["error", { disallowTypeAnnotations: false, prefer: "type-imports" }],
940
+ "ts/consistent-type-imports": [
941
+ "error",
942
+ { disallowTypeAnnotations: false, prefer: "type-imports" }
943
+ ],
944
+ "ts/method-signature-style": ["error", "property"],
945
+ // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
891
946
  "ts/no-dupe-class-members": "error",
892
947
  "ts/no-dynamic-delete": "off",
893
948
  "ts/no-explicit-any": "off",
@@ -899,7 +954,10 @@ async function typescript(options = {}) {
899
954
  "ts/no-redeclare": "error",
900
955
  "ts/no-require-imports": "error",
901
956
  "ts/no-unused-vars": "off",
902
- "ts/no-use-before-define": ["error", { classes: false, functions: false, variables: true }],
957
+ "ts/no-use-before-define": [
958
+ "error",
959
+ { classes: false, functions: false, variables: true }
960
+ ],
903
961
  "ts/no-useless-constructor": "off",
904
962
  "ts/prefer-ts-expect-error": "error",
905
963
  "ts/triple-slash-reference": "off",
@@ -1049,7 +1107,9 @@ async function vue(options = {}) {
1049
1107
  jsx: true
1050
1108
  },
1051
1109
  extraFileExtensions: [".vue"],
1052
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1110
+ parser: options.typescript ? await interopDefault(
1111
+ import("@typescript-eslint/parser")
1112
+ ) : null,
1053
1113
  sourceType: "module"
1054
1114
  }
1055
1115
  },
@@ -1071,7 +1131,12 @@ async function vue(options = {}) {
1071
1131
  "vue/define-macros-order": [
1072
1132
  "error",
1073
1133
  {
1074
- order: ["defineOptions", "defineProps", "defineEmits", "defineSlots"]
1134
+ order: [
1135
+ "defineOptions",
1136
+ "defineProps",
1137
+ "defineEmits",
1138
+ "defineSlots"
1139
+ ]
1075
1140
  }
1076
1141
  ],
1077
1142
  "vue/dot-location": ["error", "property"],
@@ -1099,7 +1164,12 @@ async function vue(options = {}) {
1099
1164
  "vue/no-extra-parens": ["error", "functions"],
1100
1165
  "vue/no-irregular-whitespace": "error",
1101
1166
  "vue/no-loss-of-precision": "error",
1102
- "vue/no-restricted-syntax": ["error", "DebuggerStatement", "LabeledStatement", "WithStatement"],
1167
+ "vue/no-restricted-syntax": [
1168
+ "error",
1169
+ "DebuggerStatement",
1170
+ "LabeledStatement",
1171
+ "WithStatement"
1172
+ ],
1103
1173
  "vue/no-restricted-v-bind": ["error", "/^v-/"],
1104
1174
  "vue/no-setup-props-reactivity-loss": "off",
1105
1175
  "vue/no-sparse-arrays": "error",
@@ -1156,7 +1226,10 @@ async function test(options = {}) {
1156
1226
  name: "coderwyd:test:rules",
1157
1227
  rules: {
1158
1228
  "node/prefer-global/process": "off",
1159
- "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
1229
+ "test/consistent-test-it": [
1230
+ "error",
1231
+ { fn: "it", withinDescribe: "it" }
1232
+ ],
1160
1233
  "test/no-identical-title": "error",
1161
1234
  "test/no-import-node-test": "error",
1162
1235
  "test/no-only-tests": isInEditor ? "off" : "error",
@@ -1184,14 +1257,26 @@ async function perfectionist() {
1184
1257
  import { isPackageExists as isPackageExists2 } from "local-pkg";
1185
1258
  var ReactRefreshAllowConstantExportPackages = ["vite"];
1186
1259
  async function react(options = {}) {
1187
- const { files = [GLOB_JSX, GLOB_TSX], overrides = {}, typescript: typescript2 = true } = options;
1188
- await ensurePackages(["eslint-plugin-react", "eslint-plugin-react-hooks", "eslint-plugin-react-refresh"]);
1189
- const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
1190
- interopDefault(import("eslint-plugin-react")),
1191
- interopDefault(import("eslint-plugin-react-hooks")),
1192
- interopDefault(import("eslint-plugin-react-refresh"))
1260
+ const {
1261
+ files = [GLOB_JSX, GLOB_TSX],
1262
+ overrides = {},
1263
+ typescript: typescript2 = true
1264
+ } = options;
1265
+ await ensurePackages([
1266
+ "eslint-plugin-react",
1267
+ "eslint-plugin-react-hooks",
1268
+ "eslint-plugin-react-refresh"
1193
1269
  ]);
1194
- const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists2(i));
1270
+ const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
1271
+ [
1272
+ interopDefault(import("eslint-plugin-react")),
1273
+ interopDefault(import("eslint-plugin-react-hooks")),
1274
+ interopDefault(import("eslint-plugin-react-refresh"))
1275
+ ]
1276
+ );
1277
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1278
+ (i) => isPackageExists2(i)
1279
+ );
1195
1280
  return [
1196
1281
  {
1197
1282
  name: "coderwyd:react:setup",
@@ -1221,7 +1306,10 @@ async function react(options = {}) {
1221
1306
  "react-hooks/exhaustive-deps": "warn",
1222
1307
  "react-hooks/rules-of-hooks": "error",
1223
1308
  // react refresh
1224
- "react-refresh/only-export-components": ["warn", { allowConstantExport: isAllowConstantExport }],
1309
+ "react-refresh/only-export-components": [
1310
+ "warn",
1311
+ { allowConstantExport: isAllowConstantExport }
1312
+ ],
1225
1313
  // recommended rules react
1226
1314
  "react/display-name": "error",
1227
1315
  "react/jsx-key": "error",
@@ -1260,7 +1348,9 @@ async function react(options = {}) {
1260
1348
  async function unocss(options = {}) {
1261
1349
  const { attributify = true, strict = false } = options;
1262
1350
  await ensurePackages(["@unocss/eslint-plugin"]);
1263
- const [pluginUnoCSS] = await Promise.all([interopDefault(import("@unocss/eslint-plugin"))]);
1351
+ const [pluginUnoCSS] = await Promise.all([
1352
+ interopDefault(import("@unocss/eslint-plugin"))
1353
+ ]);
1264
1354
  return [
1265
1355
  {
1266
1356
  name: "coderwyd:unocss",
@@ -1283,7 +1373,15 @@ async function unocss(options = {}) {
1283
1373
  // src/configs/formatter.ts
1284
1374
  async function formatter(options = {}, prettierRules2 = {}) {
1285
1375
  await ensurePackages(["eslint-plugin-prettier"]);
1286
- const { css = true, graphql, html = true, markdown, toml, yaml } = options || {};
1376
+ const {
1377
+ css = true,
1378
+ graphql,
1379
+ html = true,
1380
+ json = true,
1381
+ markdown,
1382
+ toml,
1383
+ yaml
1384
+ } = options || {};
1287
1385
  const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
1288
1386
  function createPrettierFormatter(files, parser, plugins) {
1289
1387
  const rules = {
@@ -1308,7 +1406,10 @@ async function formatter(options = {}, prettierRules2 = {}) {
1308
1406
  prettier: pluginPrettier
1309
1407
  },
1310
1408
  rules: {
1311
- "prettier/prettier": ["warn", parser === "markdown" ? markdownRules : rules]
1409
+ "prettier/prettier": [
1410
+ "warn",
1411
+ parser === "markdown" ? markdownRules : rules
1412
+ ]
1312
1413
  }
1313
1414
  };
1314
1415
  return config;
@@ -1321,15 +1422,20 @@ async function formatter(options = {}, prettierRules2 = {}) {
1321
1422
  }
1322
1423
  }
1323
1424
  ];
1425
+ if (html) {
1426
+ const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
1427
+ configs.push(htmlConfig);
1428
+ }
1324
1429
  if (css) {
1325
1430
  const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], "css");
1326
1431
  const scssConfig = createPrettierFormatter([GLOB_SCSS], "scss");
1327
1432
  const lessConfig = createPrettierFormatter([GLOB_LESS], "less");
1328
1433
  configs.push(cssConfig, scssConfig, lessConfig);
1329
1434
  }
1330
- if (html) {
1331
- const htmlConfig = createPrettierFormatter([GLOB_HTML], "html");
1332
- configs.push(htmlConfig);
1435
+ if (json) {
1436
+ const jsonConfig = createPrettierFormatter([GLOB_JSON, GLOB_JSONC], "json");
1437
+ const json5Config = createPrettierFormatter([GLOB_JSON5], "json5");
1438
+ configs.push(jsonConfig, json5Config);
1333
1439
  }
1334
1440
  if (markdown) {
1335
1441
  const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], "markdown");
@@ -1345,7 +1451,9 @@ async function formatter(options = {}, prettierRules2 = {}) {
1345
1451
  }
1346
1452
  if (toml) {
1347
1453
  await ensurePackages(["@toml-tools/parser", "prettier-plugin-toml"]);
1348
- const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", ["prettier-plugin-toml"]);
1454
+ const tomlConfig = createPrettierFormatter([GLOB_TOML], "toml", [
1455
+ "prettier-plugin-toml"
1456
+ ]);
1349
1457
  configs.push(tomlConfig);
1350
1458
  }
1351
1459
  return configs;
@@ -1372,7 +1480,9 @@ async function svelte(options = {}) {
1372
1480
  parser: parserSvelte,
1373
1481
  parserOptions: {
1374
1482
  extraFileExtensions: [".svelte"],
1375
- parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null
1483
+ parser: options.typescript ? await interopDefault(
1484
+ import("@typescript-eslint/parser")
1485
+ ) : null
1376
1486
  }
1377
1487
  },
1378
1488
  name: "coderwyd:svelte:rules",
@@ -1429,6 +1539,7 @@ async function svelte(options = {}) {
1429
1539
 
1430
1540
  // src/index.ts
1431
1541
  var flatConfigProps = [
1542
+ "name",
1432
1543
  "files",
1433
1544
  "ignores",
1434
1545
  "languageOptions",
@@ -1454,10 +1565,18 @@ async function defineConfig(options = {}, ...userConfigs) {
1454
1565
  const configs = [];
1455
1566
  if (enableGitignore) {
1456
1567
  if (typeof enableGitignore !== "boolean") {
1457
- configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
1568
+ configs.push(
1569
+ interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1570
+ r(enableGitignore)
1571
+ ])
1572
+ );
1458
1573
  } else {
1459
1574
  if (fs.existsSync(".gitignore"))
1460
- configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
1575
+ configs.push(
1576
+ interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1577
+ r()
1578
+ ])
1579
+ );
1461
1580
  }
1462
1581
  }
1463
1582
  configs.push(
@@ -1542,10 +1661,15 @@ async function defineConfig(options = {}, ...userConfigs) {
1542
1661
  prettierRules2 = { ...prettierRules2, ...options.prettierRules };
1543
1662
  }
1544
1663
  if (usePrettierrc) {
1545
- const prettierConfig = await loadPrettierConfig(options.cwd ?? process3.cwd());
1664
+ const prettierConfig = await loadPrettierConfig(
1665
+ options.cwd ?? process3.cwd()
1666
+ );
1546
1667
  Object.assign(prettierRules2, prettierConfig);
1547
1668
  }
1548
- configs.push(prettier(prettierRules2), formatter(options.formatter, prettierRules2));
1669
+ configs.push(
1670
+ prettier(prettierRules2),
1671
+ formatter(options.formatter, prettierRules2)
1672
+ );
1549
1673
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
1550
1674
  if (key in options)
1551
1675
  acc[key] = options[key];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderwyd/eslint-config",
3
3
  "type": "module",
4
- "version": "2.1.5",
4
+ "version": "2.1.6",
5
5
  "packageManager": "pnpm@8.15.1",
6
6
  "description": "Donny's ESLint config",
7
7
  "author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",