@pengzhanbo/eslint-config 1.3.4 → 1.5.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
@@ -62,6 +62,8 @@ __export(src_exports, {
62
62
  createConfig: () => createConfig,
63
63
  default: () => src_default,
64
64
  defaultPreset: () => defaultPreset,
65
+ formatters: () => formatters,
66
+ getOverrides: () => getOverrides,
65
67
  html: () => html,
66
68
  ignores: () => ignores,
67
69
  imports: () => imports,
@@ -71,6 +73,7 @@ __export(src_exports, {
71
73
  jsonc: () => jsonc,
72
74
  markdown: () => markdown,
73
75
  node: () => node,
76
+ parserPlain: () => parserPlain,
74
77
  perfectionist: () => perfectionist,
75
78
  pluginAntfu: () => import_eslint_plugin_antfu.default,
76
79
  pluginComments: () => import_eslint_plugin_eslint_comments.default,
@@ -80,6 +83,7 @@ __export(src_exports, {
80
83
  pluginUnicorn: () => import_eslint_plugin_unicorn.default,
81
84
  pluginUnusedImports: () => import_eslint_plugin_unused_imports.default,
82
85
  renameRules: () => renameRules,
86
+ resolveSubOptions: () => resolveSubOptions,
83
87
  sortPackageJson: () => sortPackageJson,
84
88
  sortTsconfig: () => sortTsconfig,
85
89
  stylistic: () => stylistic,
@@ -95,6 +99,26 @@ __export(src_exports, {
95
99
  module.exports = __toCommonJS(src_exports);
96
100
 
97
101
  // src/utils.ts
102
+ var parserPlain = {
103
+ meta: {
104
+ name: "parser-plain"
105
+ },
106
+ parseForESLint: (code) => ({
107
+ ast: {
108
+ body: [],
109
+ comments: [],
110
+ loc: { end: code.length, start: 0 },
111
+ range: [0, code.length],
112
+ tokens: [],
113
+ type: "Program"
114
+ },
115
+ scopeManager: null,
116
+ services: { isPlain: true },
117
+ visitorKeys: {
118
+ Program: []
119
+ }
120
+ })
121
+ };
98
122
  async function combine(...configs) {
99
123
  const resolved = await Promise.all(configs);
100
124
  return resolved.flat();
@@ -243,6 +267,7 @@ async function imports(options = {}) {
243
267
  },
244
268
  rules: {
245
269
  "antfu/import-dedupe": "error",
270
+ "antfu/no-import-dist": "error",
246
271
  "antfu/no-import-node-modules-by-path": "error",
247
272
  "import/first": "error",
248
273
  "import/no-duplicates": "error",
@@ -255,6 +280,14 @@ async function imports(options = {}) {
255
280
  "import/newline-after-import": ["error", { considerComments: true, count: 1 }]
256
281
  } : {}
257
282
  }
283
+ },
284
+ {
285
+ files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
286
+ name: "antfu:imports:bin",
287
+ rules: {
288
+ "antfu/no-import-dist": "off",
289
+ "antfu/no-import-node-modules-by-path": "off"
290
+ }
258
291
  }
259
292
  ];
260
293
  }
@@ -589,6 +622,7 @@ async function jsonc(options = {}) {
589
622
  }
590
623
 
591
624
  // src/configs/markdown.ts
625
+ var import_eslint_merge_processors = require("eslint-merge-processors");
592
626
  async function markdown(options = {}) {
593
627
  const {
594
628
  componentExts = [],
@@ -606,7 +640,20 @@ async function markdown(options = {}) {
606
640
  {
607
641
  files,
608
642
  name: "config:markdown:processor",
609
- processor: "markdown/markdown"
643
+ // `eslint-plugin-markdown` only creates virtual files for code blocks,
644
+ // but not the markdown file itself. We use `eslint-merge-processors` to
645
+ // add a pass-through processor for the markdown file itself.
646
+ processor: (0, import_eslint_merge_processors.mergeProcessors)([
647
+ markdown2.processors.markdown,
648
+ import_eslint_merge_processors.processorPassThrough
649
+ ])
650
+ },
651
+ {
652
+ files,
653
+ languageOptions: {
654
+ parser: parserPlain
655
+ },
656
+ name: "config:markdown:parser"
610
657
  },
611
658
  {
612
659
  files: [
@@ -758,15 +805,11 @@ async function sortPackageJson() {
758
805
  },
759
806
  {
760
807
  order: { type: "asc" },
761
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$"
762
- },
763
- {
764
- order: { type: "asc" },
765
- pathPattern: "^resolutions$"
808
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
766
809
  },
767
810
  {
768
811
  order: { type: "asc" },
769
- pathPattern: "^pnpm.overrides$"
812
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
770
813
  },
771
814
  {
772
815
  order: [
@@ -919,6 +962,7 @@ async function stylistic(options = {}) {
919
962
  const {
920
963
  indent,
921
964
  jsx,
965
+ overrides = {},
922
966
  quotes,
923
967
  semi
924
968
  } = {
@@ -946,7 +990,8 @@ async function stylistic(options = {}) {
946
990
  "antfu/consistent-list-newline": "error",
947
991
  "antfu/if-newline": "error",
948
992
  "antfu/top-level-function": "error",
949
- "curly": ["error", "multi-or-nest", "consistent"]
993
+ "curly": ["error", "multi-or-nest", "consistent"],
994
+ ...overrides
950
995
  }
951
996
  }
952
997
  ];
@@ -964,6 +1009,7 @@ async function typescript(options = {}) {
964
1009
  GLOB_SRC,
965
1010
  ...componentExts.map((ext) => `**/*.${ext}`)
966
1011
  ];
1012
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
967
1013
  const typeAwareRules = {
968
1014
  "dot-notation": "off",
969
1015
  "no-implied-eval": "off",
@@ -1053,6 +1099,13 @@ async function typescript(options = {}) {
1053
1099
  "ts/prefer-ts-expect-error": "error",
1054
1100
  "ts/triple-slash-reference": "off",
1055
1101
  "ts/unified-signatures": "off",
1102
+ ...overrides
1103
+ }
1104
+ },
1105
+ {
1106
+ files: filesTypeAware,
1107
+ name: "config:typescript:rules-type-aware",
1108
+ rules: {
1056
1109
  ...tsconfigPath ? typeAwareRules : {},
1057
1110
  ...overrides
1058
1111
  }
@@ -1220,6 +1273,7 @@ async function test(options = {}) {
1220
1273
  "node/prefer-global/process": "off",
1221
1274
  "test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
1222
1275
  "test/no-identical-title": "error",
1276
+ "test/no-import-node-test": "error",
1223
1277
  "test/no-only-tests": isInEditor ? "off" : "error",
1224
1278
  "test/prefer-hooks-in-order": "error",
1225
1279
  "test/prefer-lowercase-title": "error",
@@ -1410,11 +1464,27 @@ async function toml(options = {}) {
1410
1464
  },
1411
1465
  name: "config:toml:rules",
1412
1466
  rules: {
1413
- ...pluginToml.configs.standard.rules,
1414
- ...pluginToml.configs.recommended.rules,
1415
1467
  "style/spaced-comment": "off",
1468
+ "toml/comma-style": "error",
1469
+ "toml/keys-order": "error",
1470
+ "toml/no-space-dots": "error",
1471
+ "toml/no-unreadable-number-separator": "error",
1472
+ "toml/precision-of-fractional-seconds": "error",
1473
+ "toml/precision-of-integer": "error",
1474
+ "toml/tables-order": "error",
1475
+ "toml/vue-custom-block/no-parsing-error": "error",
1416
1476
  ...stylistic2 ? {
1417
- "toml/indent": ["error", indent === "tab" ? 2 : indent]
1477
+ "toml/array-bracket-newline": "error",
1478
+ "toml/array-bracket-spacing": "error",
1479
+ "toml/array-element-newline": "error",
1480
+ "toml/indent": ["error", indent === "tab" ? 2 : indent],
1481
+ "toml/inline-table-curly-spacing": "error",
1482
+ "toml/key-spacing": "error",
1483
+ "toml/padding-line-between-pairs": "error",
1484
+ "toml/padding-line-between-tables": "error",
1485
+ "toml/quoted-keys": "error",
1486
+ "toml/spaced-comment": "error",
1487
+ "toml/table-bracket-spacing": "error"
1418
1488
  } : {},
1419
1489
  ...overrides
1420
1490
  }
@@ -1422,13 +1492,181 @@ async function toml(options = {}) {
1422
1492
  ];
1423
1493
  }
1424
1494
 
1495
+ // src/configs/formatters.ts
1496
+ var import_local_pkg3 = require("local-pkg");
1497
+ var formatPackages = ["eslint-plugin-format"];
1498
+ async function formatters(options = {}, stylistic2 = {}) {
1499
+ const unInstalled = formatPackages.filter((i) => !(0, import_local_pkg3.isPackageExists)(i));
1500
+ if (unInstalled.length > 0) {
1501
+ console.warn(`${unInstalled.join(", ")} is not installed, please install it first.
1502
+ Run \`npm install -D ${unInstalled.join(" ")}\``);
1503
+ return [];
1504
+ }
1505
+ if (options === true) {
1506
+ options = {
1507
+ css: true,
1508
+ graphql: true,
1509
+ html: true,
1510
+ markdown: true
1511
+ };
1512
+ }
1513
+ const {
1514
+ indent,
1515
+ quotes,
1516
+ semi
1517
+ } = {
1518
+ ...StylisticConfigDefaults,
1519
+ ...stylistic2
1520
+ };
1521
+ const prettierOptions = Object.assign(
1522
+ {
1523
+ endOfLine: "auto",
1524
+ semi,
1525
+ singleQuote: quotes === "single",
1526
+ tabWidth: typeof indent === "number" ? indent : 2,
1527
+ trailingComma: "all",
1528
+ useTabs: indent === "tab"
1529
+ },
1530
+ options.prettierOptions || {}
1531
+ );
1532
+ const dprintOptions = Object.assign(
1533
+ {
1534
+ indentWidth: typeof indent === "number" ? indent : 2,
1535
+ quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
1536
+ useTabs: indent === "tab"
1537
+ },
1538
+ options.dprintOptions || {}
1539
+ );
1540
+ const pluginFormat = await interopDefault(import("eslint-plugin-format"));
1541
+ const configs = [
1542
+ {
1543
+ name: "config:formatters:setup",
1544
+ plugins: {
1545
+ format: pluginFormat
1546
+ }
1547
+ }
1548
+ ];
1549
+ if (options.css) {
1550
+ configs.push(
1551
+ {
1552
+ files: [GLOB_CSS, GLOB_POSTCSS],
1553
+ languageOptions: {
1554
+ parser: parserPlain
1555
+ },
1556
+ name: "config:formatter:css",
1557
+ rules: {
1558
+ "format/prettier": [
1559
+ "error",
1560
+ {
1561
+ ...prettierOptions,
1562
+ parser: "css"
1563
+ }
1564
+ ]
1565
+ }
1566
+ },
1567
+ {
1568
+ files: [GLOB_SCSS],
1569
+ languageOptions: {
1570
+ parser: parserPlain
1571
+ },
1572
+ name: "config:formatter:scss",
1573
+ rules: {
1574
+ "format/prettier": [
1575
+ "error",
1576
+ {
1577
+ ...prettierOptions,
1578
+ parser: "scss"
1579
+ }
1580
+ ]
1581
+ }
1582
+ },
1583
+ {
1584
+ files: [GLOB_LESS],
1585
+ languageOptions: {
1586
+ parser: parserPlain
1587
+ },
1588
+ name: "config:formatter:less",
1589
+ rules: {
1590
+ "format/prettier": [
1591
+ "error",
1592
+ {
1593
+ ...prettierOptions,
1594
+ parser: "less"
1595
+ }
1596
+ ]
1597
+ }
1598
+ }
1599
+ );
1600
+ }
1601
+ if (options.html) {
1602
+ configs.push({
1603
+ files: ["**/*.html"],
1604
+ languageOptions: {
1605
+ parser: parserPlain
1606
+ },
1607
+ name: "config:formatter:html",
1608
+ rules: {
1609
+ "format/prettier": [
1610
+ "error",
1611
+ {
1612
+ ...prettierOptions,
1613
+ parser: "html"
1614
+ }
1615
+ ]
1616
+ }
1617
+ });
1618
+ }
1619
+ if (options.markdown) {
1620
+ const formater = options.markdown === true ? "prettier" : options.markdown;
1621
+ configs.push({
1622
+ files: [GLOB_MARKDOWN],
1623
+ languageOptions: {
1624
+ parser: parserPlain
1625
+ },
1626
+ name: "config:formatter:markdown",
1627
+ rules: {
1628
+ [`format/${formater}`]: [
1629
+ "error",
1630
+ formater === "prettier" ? {
1631
+ printWidth: 120,
1632
+ ...prettierOptions,
1633
+ embeddedLanguageFormatting: "off",
1634
+ parser: "markdown"
1635
+ } : {
1636
+ ...dprintOptions,
1637
+ language: "markdown"
1638
+ }
1639
+ ]
1640
+ }
1641
+ });
1642
+ }
1643
+ if (options.graphql) {
1644
+ configs.push({
1645
+ files: ["**/*.graphql"],
1646
+ languageOptions: {
1647
+ parser: parserPlain
1648
+ },
1649
+ name: "config:formatter:graphql",
1650
+ rules: {
1651
+ "format/prettier": [
1652
+ "error",
1653
+ {
1654
+ ...prettierOptions,
1655
+ parser: "graphql"
1656
+ }
1657
+ ]
1658
+ }
1659
+ });
1660
+ }
1661
+ return configs;
1662
+ }
1663
+
1425
1664
  // src/preset.ts
1426
1665
  var defaultPreset = (options) => {
1427
1666
  const {
1428
1667
  componentExts,
1429
1668
  gitignore: enableGitignore,
1430
1669
  isInEditor,
1431
- overrides,
1432
1670
  typescript: enableTypeScript,
1433
1671
  stylistic: stylisticOptions
1434
1672
  } = options;
@@ -1450,7 +1688,7 @@ var defaultPreset = (options) => {
1450
1688
  ignores(),
1451
1689
  javascript({
1452
1690
  isInEditor,
1453
- overrides: overrides.javascript
1691
+ overrides: getOverrides(options, "javascript")
1454
1692
  }),
1455
1693
  comments(),
1456
1694
  node(),
@@ -1466,23 +1704,26 @@ var defaultPreset = (options) => {
1466
1704
  );
1467
1705
  if (enableTypeScript) {
1468
1706
  configs.push(typescript({
1469
- ...typeof enableTypeScript !== "boolean" ? enableTypeScript : {},
1470
- componentExts,
1471
- overrides: overrides.typescript
1707
+ ...resolveSubOptions(options, "typescript"),
1708
+ componentExts
1709
+ }));
1710
+ }
1711
+ if (stylisticOptions) {
1712
+ configs.push(stylistic({
1713
+ ...typeof stylisticOptions === "boolean" ? {} : stylisticOptions,
1714
+ overrides: getOverrides(options, "stylistic")
1472
1715
  }));
1473
1716
  }
1474
- if (stylisticOptions)
1475
- configs.push(stylistic(stylisticOptions));
1476
1717
  if (options.test) {
1477
1718
  configs.push(test({
1478
1719
  isInEditor,
1479
- overrides: overrides.test
1720
+ overrides: getOverrides(options, "test")
1480
1721
  }));
1481
1722
  }
1482
1723
  if (options.jsonc) {
1483
1724
  configs.push(
1484
1725
  jsonc({
1485
- overrides: overrides.jsonc,
1726
+ overrides: getOverrides(options, "jsonc"),
1486
1727
  stylistic: stylisticOptions
1487
1728
  }),
1488
1729
  sortPackageJson(),
@@ -1491,40 +1732,54 @@ var defaultPreset = (options) => {
1491
1732
  }
1492
1733
  if (options.yaml) {
1493
1734
  configs.push(yaml({
1494
- overrides: overrides.yaml,
1735
+ overrides: getOverrides(options, "yaml"),
1495
1736
  stylistic: stylisticOptions
1496
1737
  }));
1497
1738
  }
1498
1739
  if (options.toml) {
1499
1740
  configs.push(toml({
1500
- overrides: overrides.toml,
1741
+ overrides: getOverrides(options, "toml"),
1501
1742
  stylistic: stylisticOptions
1502
1743
  }));
1503
1744
  }
1504
1745
  if (options.html) {
1505
1746
  configs.push(html({
1506
- overrides: overrides.html,
1747
+ overrides: getOverrides(options, "html"),
1507
1748
  stylistic: stylisticOptions
1508
1749
  }));
1509
1750
  }
1510
- if (options.unocss)
1511
- configs.push(unocss(options.unocss === true ? {} : options.unocss));
1512
- if (options.tailwindcss)
1513
- configs.push(tailwindcss(options.tailwindcss === true ? {} : options.tailwindcss));
1751
+ if (options.unocss) {
1752
+ configs.push(unocss({
1753
+ ...resolveSubOptions(options, "unocss"),
1754
+ overrides: getOverrides(options, "unocss")
1755
+ }));
1756
+ }
1757
+ if (options.tailwindcss) {
1758
+ configs.push(tailwindcss({
1759
+ ...resolveSubOptions(options, "tailwindcss"),
1760
+ overrides: getOverrides(options, "tailwindcss")
1761
+ }));
1762
+ }
1514
1763
  if (options.markdown) {
1515
1764
  configs.push(
1516
1765
  markdown({
1517
1766
  componentExts,
1518
- overrides: overrides.markdown
1767
+ overrides: getOverrides(options, "markdown")
1519
1768
  })
1520
1769
  );
1521
1770
  }
1771
+ if (options.formatters) {
1772
+ configs.push(formatters(
1773
+ options.formatters,
1774
+ typeof stylisticOptions === "boolean" ? {} : stylisticOptions
1775
+ ));
1776
+ }
1522
1777
  return configs;
1523
1778
  };
1524
1779
 
1525
1780
  // src/resolvedOptions.ts
1526
1781
  var import_node_process2 = __toESM(require("process"), 1);
1527
- var import_local_pkg3 = require("local-pkg");
1782
+ var import_local_pkg4 = require("local-pkg");
1528
1783
  var VuePackages = [
1529
1784
  "vue",
1530
1785
  "nuxt",
@@ -1536,9 +1791,8 @@ function resolveOptions(options = {}) {
1536
1791
  componentExts = [],
1537
1792
  preset = [],
1538
1793
  gitignore = true,
1539
- isInEditor = !!((import_node_process2.default.env.VSCODE_PID || import_node_process2.default.env.JETBRAINS_IDE) && !import_node_process2.default.env.CI),
1540
- overrides = {},
1541
- typescript: typescript2 = (0, import_local_pkg3.isPackageExists)("typescript"),
1794
+ isInEditor = !!((import_node_process2.default.env.VSCODE_PID || import_node_process2.default.env.JETBRAINS_IDE || import_node_process2.default.env.VIM) && !import_node_process2.default.env.CI),
1795
+ typescript: typescript2 = (0, import_local_pkg4.isPackageExists)("typescript"),
1542
1796
  jsx = true,
1543
1797
  test: test2 = true,
1544
1798
  jsonc: jsonc2 = true,
@@ -1546,6 +1800,7 @@ function resolveOptions(options = {}) {
1546
1800
  toml: toml2 = true,
1547
1801
  markdown: markdown2 = true,
1548
1802
  html: html2 = true,
1803
+ formatters: formatters2 = false,
1549
1804
  unocss: enableUnocss = false,
1550
1805
  tailwindcss: enableTailwindcss = false
1551
1806
  } = options;
@@ -1554,11 +1809,11 @@ function resolveOptions(options = {}) {
1554
1809
  stylistic2.jsx = options.jsx ?? true;
1555
1810
  const unocss2 = enableUnocss === false ? false : typeof enableUnocss === "object" ? enableUnocss : {};
1556
1811
  const tailwindcss2 = enableTailwindcss === false ? false : typeof enableTailwindcss === "object" ? enableTailwindcss : {};
1557
- if (VuePackages.some((i) => (0, import_local_pkg3.isPackageExists)(i)))
1812
+ if (VuePackages.some((i) => (0, import_local_pkg4.isPackageExists)(i)))
1558
1813
  componentExts.push("vue");
1559
- if ((0, import_local_pkg3.isPackageExists)("astro"))
1814
+ if ((0, import_local_pkg4.isPackageExists)("astro"))
1560
1815
  componentExts.push("astro");
1561
- if ((0, import_local_pkg3.isPackageExists)("svelte"))
1816
+ if ((0, import_local_pkg4.isPackageExists)("svelte"))
1562
1817
  componentExts.push("svelte");
1563
1818
  return {
1564
1819
  ...options,
@@ -1566,7 +1821,6 @@ function resolveOptions(options = {}) {
1566
1821
  preset,
1567
1822
  gitignore,
1568
1823
  isInEditor,
1569
- overrides,
1570
1824
  typescript: typescript2,
1571
1825
  stylistic: stylistic2,
1572
1826
  jsx,
@@ -1577,7 +1831,8 @@ function resolveOptions(options = {}) {
1577
1831
  markdown: markdown2,
1578
1832
  unocss: unocss2,
1579
1833
  tailwindcss: tailwindcss2,
1580
- html: html2
1834
+ html: html2,
1835
+ formatters: formatters2
1581
1836
  };
1582
1837
  }
1583
1838
 
@@ -1620,6 +1875,16 @@ function createConfig(preset) {
1620
1875
  return eslintFlatConfig(options, ...userConfigs);
1621
1876
  };
1622
1877
  }
1878
+ function resolveSubOptions(options, key) {
1879
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
1880
+ }
1881
+ function getOverrides(options, key) {
1882
+ const sub = resolveSubOptions(options, key);
1883
+ return {
1884
+ ...options.overrides?.[key],
1885
+ ..."overrides" in sub ? sub.overrides || {} : {}
1886
+ };
1887
+ }
1623
1888
 
1624
1889
  // src/index.ts
1625
1890
  var src_default = eslintFlatConfig;
@@ -1656,6 +1921,8 @@ var src_default = eslintFlatConfig;
1656
1921
  comments,
1657
1922
  createConfig,
1658
1923
  defaultPreset,
1924
+ formatters,
1925
+ getOverrides,
1659
1926
  html,
1660
1927
  ignores,
1661
1928
  imports,
@@ -1665,6 +1932,7 @@ var src_default = eslintFlatConfig;
1665
1932
  jsonc,
1666
1933
  markdown,
1667
1934
  node,
1935
+ parserPlain,
1668
1936
  perfectionist,
1669
1937
  pluginAntfu,
1670
1938
  pluginComments,
@@ -1674,6 +1942,7 @@ var src_default = eslintFlatConfig;
1674
1942
  pluginUnicorn,
1675
1943
  pluginUnusedImports,
1676
1944
  renameRules,
1945
+ resolveSubOptions,
1677
1946
  sortPackageJson,
1678
1947
  sortTsconfig,
1679
1948
  stylistic,