@pengzhanbo/eslint-config 1.2.5 → 1.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 pengzhanbo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -43,6 +43,8 @@ __export(src_exports, {
43
43
  GLOB_LESS: () => GLOB_LESS,
44
44
  GLOB_MARKDOWN: () => GLOB_MARKDOWN,
45
45
  GLOB_MARKDOWN_CODE: () => GLOB_MARKDOWN_CODE,
46
+ GLOB_MARKDOWN_IN_MARKDOWN: () => GLOB_MARKDOWN_IN_MARKDOWN,
47
+ GLOB_POSTCSS: () => GLOB_POSTCSS,
46
48
  GLOB_SCSS: () => GLOB_SCSS,
47
49
  GLOB_SRC: () => GLOB_SRC,
48
50
  GLOB_SRC_EXT: () => GLOB_SRC_EXT,
@@ -53,12 +55,13 @@ __export(src_exports, {
53
55
  GLOB_TSX: () => GLOB_TSX,
54
56
  GLOB_VUE: () => GLOB_VUE,
55
57
  GLOB_YAML: () => GLOB_YAML,
58
+ StylisticConfigDefaults: () => StylisticConfigDefaults,
56
59
  combine: () => combine,
57
60
  comments: () => comments,
58
61
  createConfig: () => createConfig,
59
62
  default: () => src_default,
60
63
  defaultPreset: () => defaultPreset,
61
- html: () => html,
64
+ formatters: () => formatters,
62
65
  ignores: () => ignores,
63
66
  imports: () => imports,
64
67
  interopDefault: () => interopDefault,
@@ -150,12 +153,14 @@ var GLOB_TS = "**/*.?([cm])ts";
150
153
  var GLOB_TSX = "**/*.?([cm])tsx";
151
154
  var GLOB_STYLE = "**/*.{c,le,sc}ss";
152
155
  var GLOB_CSS = "**/*.css";
156
+ var GLOB_POSTCSS = "**/*.{p,post}css";
153
157
  var GLOB_LESS = "**/*.less";
154
158
  var GLOB_SCSS = "**/*.scss";
155
159
  var GLOB_JSON = "**/*.json";
156
160
  var GLOB_JSON5 = "**/*.json5";
157
161
  var GLOB_JSONC = "**/*.jsonc";
158
162
  var GLOB_MARKDOWN = "**/*.md";
163
+ var GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
159
164
  var GLOB_VUE = "**/*.vue";
160
165
  var GLOB_YAML = "**/*.y?(a)ml";
161
166
  var GLOB_HTML = "**/*.htm?(l)";
@@ -581,24 +586,56 @@ async function jsonc(options = {}) {
581
586
  }
582
587
 
583
588
  // src/configs/markdown.ts
584
- async function markdown(options = {}) {
589
+ async function markdown(options = {}, formatMarkdown = false) {
585
590
  const {
586
591
  componentExts = [],
587
592
  files = [GLOB_MARKDOWN],
588
593
  overrides = {}
589
594
  } = options;
595
+ const markdown2 = await interopDefault(import("eslint-plugin-markdown"));
596
+ const baseProcessor = markdown2.processors.markdown;
597
+ const processor = !formatMarkdown ? {
598
+ meta: {
599
+ name: "markdown-processor"
600
+ },
601
+ supportsAutofix: true,
602
+ ...baseProcessor
603
+ } : {
604
+ meta: {
605
+ name: "markdown-processor-with-content"
606
+ },
607
+ postprocess(messages, filename) {
608
+ const markdownContent = messages.pop();
609
+ const codeSnippets = baseProcessor.postprocess(messages, filename);
610
+ return [
611
+ ...markdownContent || [],
612
+ ...codeSnippets || []
613
+ ];
614
+ },
615
+ preprocess(text, filename) {
616
+ const result = baseProcessor.preprocess(text, filename);
617
+ return [
618
+ ...result,
619
+ {
620
+ filename: ".__markdown_content__",
621
+ text
622
+ }
623
+ ];
624
+ },
625
+ supportsAutofix: true
626
+ };
590
627
  return [
591
628
  {
592
629
  name: "config:markdown:setup",
593
630
  plugins: {
594
- // @ts-expect-error missing types
595
- markdown: await interopDefault(import("eslint-plugin-markdown"))
631
+ markdown: markdown2
596
632
  }
597
633
  },
598
634
  {
599
635
  files,
636
+ ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
600
637
  name: "config:markdown:processor",
601
- processor: "markdown/markdown"
638
+ processor
602
639
  },
603
640
  {
604
641
  files: [
@@ -612,9 +649,8 @@ async function markdown(options = {}) {
612
649
  }
613
650
  }
614
651
  },
615
- name: "config:markdown:rules",
652
+ name: "config:markdown:disables",
616
653
  rules: {
617
- "antfu/no-ts-export-equal": "off",
618
654
  "import/newline-after-import": "off",
619
655
  "no-alert": "off",
620
656
  "no-console": "off",
@@ -902,13 +938,22 @@ function sortTsconfig() {
902
938
  }
903
939
 
904
940
  // src/configs/stylistic.ts
941
+ var StylisticConfigDefaults = {
942
+ indent: 2,
943
+ jsx: true,
944
+ quotes: "single",
945
+ semi: false
946
+ };
905
947
  async function stylistic(options = {}) {
906
948
  const {
907
- indent = 2,
908
- jsx = true,
909
- quotes = "single",
910
- semi = false
911
- } = options;
949
+ indent,
950
+ jsx,
951
+ quotes,
952
+ semi
953
+ } = {
954
+ ...StylisticConfigDefaults,
955
+ ...options
956
+ };
912
957
  const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
913
958
  const config = pluginStylistic.configs.customize({
914
959
  flat: true,
@@ -929,7 +974,6 @@ async function stylistic(options = {}) {
929
974
  ...config.rules,
930
975
  "antfu/consistent-list-newline": "error",
931
976
  "antfu/if-newline": "error",
932
- "antfu/indent-binary-ops": ["error", { indent }],
933
977
  "antfu/top-level-function": "error",
934
978
  "curly": ["error", "multi-or-nest", "consistent"]
935
979
  }
@@ -1013,8 +1057,6 @@ async function typescript(options = {}) {
1013
1057
  "@typescript-eslint/",
1014
1058
  "ts/"
1015
1059
  ),
1016
- "antfu/generic-spacing": "error",
1017
- "antfu/named-tuple-spacing": "error",
1018
1060
  "no-dupe-class-members": "off",
1019
1061
  "no-loss-of-precision": "off",
1020
1062
  "no-redeclare": "off",
@@ -1315,55 +1357,190 @@ async function tailwindcss(options = {}) {
1315
1357
  ];
1316
1358
  }
1317
1359
 
1318
- // src/configs/html.ts
1319
- async function html(options = {}) {
1320
- const {
1321
- files = [GLOB_HTML],
1322
- overrides = {},
1323
- stylistic: stylistic2 = true
1324
- } = options;
1360
+ // src/configs/formatters.ts
1361
+ var import_local_pkg3 = require("local-pkg");
1362
+ var formatterPackages = ["eslint-plugin-format"];
1363
+ async function formatters(options = {}, stylistic2 = {}, markdownEnabled = true) {
1364
+ const unInstalled = formatterPackages.filter((i) => !(0, import_local_pkg3.isPackageExists)(i));
1365
+ if (unInstalled.length > 0) {
1366
+ console.warn(`${unInstalled.join(", ")} is not installed, please install it first.
1367
+ Run \`npm install -D ${unInstalled.join(" ")}\``);
1368
+ return [];
1369
+ }
1370
+ if (options === true) {
1371
+ options = {
1372
+ css: true,
1373
+ graphql: true,
1374
+ html: true,
1375
+ markdown: true,
1376
+ toml: true
1377
+ };
1378
+ }
1325
1379
  const {
1326
- indent = 2
1327
- } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1328
- const [
1329
- pluginHtml,
1330
- parserHtml
1331
- ] = await Promise.all([
1332
- interopDefault(import("@html-eslint/eslint-plugin")),
1333
- interopDefault(import("@html-eslint/parser"))
1334
- ]);
1335
- return [
1380
+ indent,
1381
+ quotes,
1382
+ semi
1383
+ } = {
1384
+ ...StylisticConfigDefaults,
1385
+ ...stylistic2
1386
+ };
1387
+ const prettierOptions = Object.assign(
1336
1388
  {
1337
- name: "config:html:setup",
1338
- plugins: {
1339
- html: pluginHtml
1340
- }
1389
+ semi,
1390
+ singleQuote: quotes === "single",
1391
+ tabWidth: typeof indent === "number" ? indent : 2,
1392
+ trailingComma: "all",
1393
+ useTabs: indent === "tab"
1394
+ },
1395
+ options.prettierOptions || {}
1396
+ );
1397
+ const dprintOptions = Object.assign(
1398
+ {
1399
+ indentWidth: typeof indent === "number" ? indent : 2,
1400
+ quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
1401
+ useTabs: indent === "tab"
1341
1402
  },
1403
+ options.dprintOptions || {}
1404
+ );
1405
+ const pluginFormat = await interopDefault(import("eslint-plugin-format"));
1406
+ const configs = [
1342
1407
  {
1343
- files,
1344
- name: "config:html:rules",
1408
+ name: "antfu:formatters:setup",
1409
+ plugins: {
1410
+ format: pluginFormat
1411
+ }
1412
+ }
1413
+ ];
1414
+ if (options.css) {
1415
+ configs.push(
1416
+ {
1417
+ files: [GLOB_CSS, GLOB_POSTCSS],
1418
+ languageOptions: {
1419
+ parser: pluginFormat.parserPlain
1420
+ },
1421
+ name: "config:formatter:css",
1422
+ rules: {
1423
+ "format/prettier": [
1424
+ "error",
1425
+ {
1426
+ ...prettierOptions,
1427
+ parser: "css"
1428
+ }
1429
+ ]
1430
+ }
1431
+ },
1432
+ {
1433
+ files: [GLOB_SCSS],
1434
+ languageOptions: {
1435
+ parser: pluginFormat.parserPlain
1436
+ },
1437
+ name: "config:formatter:scss",
1438
+ rules: {
1439
+ "format/prettier": [
1440
+ "error",
1441
+ {
1442
+ ...prettierOptions,
1443
+ parser: "scss"
1444
+ }
1445
+ ]
1446
+ }
1447
+ },
1448
+ {
1449
+ files: [GLOB_LESS],
1450
+ languageOptions: {
1451
+ parser: pluginFormat.parserPlain
1452
+ },
1453
+ name: "config:formatter:less",
1454
+ rules: {
1455
+ "format/prettier": [
1456
+ "error",
1457
+ {
1458
+ ...prettierOptions,
1459
+ parser: "less"
1460
+ }
1461
+ ]
1462
+ }
1463
+ }
1464
+ );
1465
+ }
1466
+ if (options.html) {
1467
+ configs.push({
1468
+ files: ["**/*.html"],
1345
1469
  languageOptions: {
1346
- parser: parserHtml
1470
+ parser: pluginFormat.parserPlain
1347
1471
  },
1472
+ name: "config:formatter:html",
1348
1473
  rules: {
1349
- "html/require-lang": "error",
1350
- "html/require-img-alt": "error",
1351
- "html/require-doctype": "error",
1352
- "html/require-title": "error",
1353
- "html/no-extra-spacing-attrs": "error",
1354
- "html/no-duplicate-id": "error",
1355
- "html/indent": ["error", indent],
1356
- "html/require-li-container": "error",
1357
- "html/quotes": "error",
1358
- "html/require-closing-tags": "error",
1359
- "html/no-duplicate-attrs": "error",
1360
- "html/element-newline": ["error", {
1361
- skip: ["span", "i", "code", "pre"]
1362
- }],
1363
- ...overrides
1474
+ "format/prettier": [
1475
+ "error",
1476
+ {
1477
+ ...prettierOptions,
1478
+ parser: "html"
1479
+ }
1480
+ ]
1364
1481
  }
1365
- }
1366
- ];
1482
+ });
1483
+ }
1484
+ if (options.toml) {
1485
+ configs.push({
1486
+ files: ["**/*.toml"],
1487
+ languageOptions: {
1488
+ parser: pluginFormat.parserPlain
1489
+ },
1490
+ name: "config:formatter:toml",
1491
+ rules: {
1492
+ "format/dprint": [
1493
+ "error",
1494
+ {
1495
+ ...dprintOptions,
1496
+ language: "toml"
1497
+ }
1498
+ ]
1499
+ }
1500
+ });
1501
+ }
1502
+ if (options.markdown) {
1503
+ const formatter = options.markdown === true ? "prettier" : options.markdown;
1504
+ configs.push({
1505
+ files: markdownEnabled ? ["**/*.__markdown_content__"] : [GLOB_MARKDOWN],
1506
+ languageOptions: {
1507
+ parser: pluginFormat.parserPlain
1508
+ },
1509
+ name: "config:formatter:markdown",
1510
+ rules: {
1511
+ [`format/${formatter}`]: [
1512
+ "error",
1513
+ formatter === "prettier" ? {
1514
+ ...prettierOptions,
1515
+ embeddedLanguageFormatting: "off",
1516
+ parser: "markdown"
1517
+ } : {
1518
+ ...dprintOptions,
1519
+ language: "markdown"
1520
+ }
1521
+ ]
1522
+ }
1523
+ });
1524
+ }
1525
+ if (options.graphql) {
1526
+ configs.push({
1527
+ files: ["**/*.graphql"],
1528
+ languageOptions: {
1529
+ parser: pluginFormat.parserPlain
1530
+ },
1531
+ name: "config:formatter:graphql",
1532
+ rules: {
1533
+ "format/prettier": [
1534
+ "error",
1535
+ {
1536
+ ...prettierOptions,
1537
+ parser: "graphql"
1538
+ }
1539
+ ]
1540
+ }
1541
+ });
1542
+ }
1543
+ return configs;
1367
1544
  }
1368
1545
 
1369
1546
  // src/preset.ts
@@ -1433,12 +1610,6 @@ var defaultPreset = (options) => {
1433
1610
  sortTsconfig()
1434
1611
  );
1435
1612
  }
1436
- if (options.html) {
1437
- configs.push(html({
1438
- overrides: overrides.html,
1439
- stylistic: stylisticOptions
1440
- }));
1441
- }
1442
1613
  if (options.yaml) {
1443
1614
  configs.push(yaml({
1444
1615
  overrides: overrides.yaml,
@@ -1453,14 +1624,21 @@ var defaultPreset = (options) => {
1453
1624
  configs.push(markdown({
1454
1625
  componentExts,
1455
1626
  overrides: overrides.markdown
1456
- }));
1627
+ }, options.formatters === true || !!(options.formatters || {})?.markdown));
1628
+ }
1629
+ if (options.formatters) {
1630
+ configs.push(formatters(
1631
+ options.formatters,
1632
+ typeof stylisticOptions === "boolean" ? {} : stylisticOptions,
1633
+ options.markdown !== false
1634
+ ));
1457
1635
  }
1458
1636
  return configs;
1459
1637
  };
1460
1638
 
1461
1639
  // src/resolvedOptions.ts
1462
1640
  var import_node_process2 = __toESM(require("process"), 1);
1463
- var import_local_pkg3 = require("local-pkg");
1641
+ var import_local_pkg4 = require("local-pkg");
1464
1642
  var VuePackages = [
1465
1643
  "vue",
1466
1644
  "nuxt",
@@ -1474,13 +1652,13 @@ function resolveOptions(options = {}) {
1474
1652
  gitignore = true,
1475
1653
  isInEditor = !!((import_node_process2.default.env.VSCODE_PID || import_node_process2.default.env.JETBRAINS_IDE) && !import_node_process2.default.env.CI),
1476
1654
  overrides = {},
1477
- typescript: typescript2 = (0, import_local_pkg3.isPackageExists)("typescript"),
1655
+ typescript: typescript2 = (0, import_local_pkg4.isPackageExists)("typescript"),
1478
1656
  jsx = true,
1479
1657
  test: test2 = true,
1480
1658
  jsonc: jsonc2 = true,
1481
1659
  yaml: yaml2 = true,
1482
1660
  markdown: markdown2 = true,
1483
- html: html2 = true,
1661
+ formatters: formatters2 = false,
1484
1662
  unocss: enableUnocss = false,
1485
1663
  tailwindcss: enableTailwindcss = false
1486
1664
  } = options;
@@ -1489,11 +1667,11 @@ function resolveOptions(options = {}) {
1489
1667
  stylistic2.jsx = options.jsx ?? true;
1490
1668
  const unocss2 = enableUnocss === false ? false : typeof enableUnocss === "object" ? enableUnocss : {};
1491
1669
  const tailwindcss2 = enableTailwindcss === false ? false : typeof enableTailwindcss === "object" ? enableTailwindcss : {};
1492
- if (VuePackages.some((i) => (0, import_local_pkg3.isPackageExists)(i)))
1670
+ if (VuePackages.some((i) => (0, import_local_pkg4.isPackageExists)(i)))
1493
1671
  componentExts.push("vue");
1494
- if ((0, import_local_pkg3.isPackageExists)("astro"))
1672
+ if ((0, import_local_pkg4.isPackageExists)("astro"))
1495
1673
  componentExts.push("astro");
1496
- if ((0, import_local_pkg3.isPackageExists)("svelte"))
1674
+ if ((0, import_local_pkg4.isPackageExists)("svelte"))
1497
1675
  componentExts.push("svelte");
1498
1676
  return {
1499
1677
  ...options,
@@ -1511,7 +1689,7 @@ function resolveOptions(options = {}) {
1511
1689
  markdown: markdown2,
1512
1690
  unocss: unocss2,
1513
1691
  tailwindcss: tailwindcss2,
1514
- html: html2
1692
+ formatters: formatters2
1515
1693
  };
1516
1694
  }
1517
1695
 
@@ -1572,6 +1750,8 @@ var src_default = eslintFlatConfig;
1572
1750
  GLOB_LESS,
1573
1751
  GLOB_MARKDOWN,
1574
1752
  GLOB_MARKDOWN_CODE,
1753
+ GLOB_MARKDOWN_IN_MARKDOWN,
1754
+ GLOB_POSTCSS,
1575
1755
  GLOB_SCSS,
1576
1756
  GLOB_SRC,
1577
1757
  GLOB_SRC_EXT,
@@ -1582,11 +1762,12 @@ var src_default = eslintFlatConfig;
1582
1762
  GLOB_TSX,
1583
1763
  GLOB_VUE,
1584
1764
  GLOB_YAML,
1765
+ StylisticConfigDefaults,
1585
1766
  combine,
1586
1767
  comments,
1587
1768
  createConfig,
1588
1769
  defaultPreset,
1589
- html,
1770
+ formatters,
1590
1771
  ignores,
1591
1772
  imports,
1592
1773
  interopDefault,