@pengzhanbo/eslint-config 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +736 -494
  2. package/dist/index.js +313 -157
  3. package/package.json +40 -40
package/dist/index.js CHANGED
@@ -504,7 +504,6 @@ async function stylistic(options = {}) {
504
504
  }
505
505
  //#endregion
506
506
  //#region src/configs/formatters.ts
507
- const formatPackages = ["eslint-plugin-format"];
508
507
  function mergePrettierOptions(options, overrides) {
509
508
  return {
510
509
  ...options,
@@ -512,22 +511,122 @@ function mergePrettierOptions(options, overrides) {
512
511
  plugins: [...overrides.plugins || [], ...options.plugins || []]
513
512
  };
514
513
  }
515
- async function formatters(options = {}, stylistic = {}) {
516
- if (options === true) {
517
- const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
518
- options = {
519
- astro: isPackageInScope("prettier-plugin-astro"),
520
- css: true,
521
- graphql: true,
522
- html: true,
523
- markdown: true,
524
- svg: isPrettierPluginXmlInScope,
525
- xml: isPrettierPluginXmlInScope
526
- };
527
- }
528
- if (options.astro) formatPackages.push("prettier-plugin-astro");
529
- if (options.svg || options.xml) formatPackages.push("@prettier/plugin-xml");
530
- await ensurePackages(formatPackages);
514
+ function buildCssConfigs(prettierOptions) {
515
+ return [
516
+ [
517
+ [GLOB_CSS, GLOB_POSTCSS],
518
+ "css",
519
+ "config/formatter/css"
520
+ ],
521
+ [
522
+ [GLOB_SCSS],
523
+ "scss",
524
+ "config/formatter/scss"
525
+ ],
526
+ [
527
+ [GLOB_LESS],
528
+ "less",
529
+ "config/formatter/less"
530
+ ]
531
+ ].map(([files, parser, name]) => ({
532
+ files: [...files],
533
+ languageOptions: { parser: parserPlain },
534
+ name,
535
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser })] }
536
+ }));
537
+ }
538
+ function buildXmlLikeConfig(prettierOptions, prettierXmlOptions, files, name) {
539
+ return {
540
+ files,
541
+ languageOptions: { parser: parserPlain },
542
+ name,
543
+ rules: { "format/prettier": ["error", mergePrettierOptions({
544
+ ...prettierXmlOptions,
545
+ ...prettierOptions
546
+ }, {
547
+ parser: "xml",
548
+ plugins: ["@prettier/plugin-xml"]
549
+ })] }
550
+ };
551
+ }
552
+ function buildMarkdownConfigs(options, prettierOptions, dprintOptions) {
553
+ const formater = options.markdown === true ? "prettier" : options.markdown;
554
+ return [{
555
+ files: [GLOB_MARKDOWN],
556
+ ignores: [],
557
+ languageOptions: { parser: parserPlain },
558
+ name: "config/formatter/markdown",
559
+ rules: { [`format/${formater}`]: ["error", formater === "prettier" ? mergePrettierOptions(prettierOptions, {
560
+ embeddedLanguageFormatting: "off",
561
+ parser: "markdown"
562
+ }) : {
563
+ ...dprintOptions,
564
+ language: "markdown"
565
+ }] }
566
+ }];
567
+ }
568
+ function buildAstroConfigs(prettierOptions) {
569
+ return [{
570
+ files: [GLOB_ASTRO],
571
+ languageOptions: { parser: parserPlain },
572
+ name: "config/formatter/astro",
573
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, {
574
+ parser: "astro",
575
+ plugins: ["prettier-plugin-astro"]
576
+ })] }
577
+ }, {
578
+ files: [GLOB_ASTRO, GLOB_ASTRO_TS],
579
+ name: "config/formatter/astro/disables",
580
+ rules: {
581
+ "style/arrow-parens": "off",
582
+ "style/block-spacing": "off",
583
+ "style/comma-dangle": "off",
584
+ "style/indent": "off",
585
+ "style/no-multi-spaces": "off",
586
+ "style/quotes": "off",
587
+ "style/semi": "off"
588
+ }
589
+ }];
590
+ }
591
+ function resolveFormattersOptions(options) {
592
+ if (options !== true) return options;
593
+ const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
594
+ return {
595
+ astro: isPackageInScope("prettier-plugin-astro"),
596
+ css: true,
597
+ graphql: true,
598
+ html: true,
599
+ markdown: true,
600
+ svg: isPrettierPluginXmlInScope,
601
+ xml: isPrettierPluginXmlInScope
602
+ };
603
+ }
604
+ function buildHtmlConfig(prettierOptions) {
605
+ return {
606
+ files: [GLOB_HTML],
607
+ languageOptions: { parser: parserPlain },
608
+ name: "config/formatter/html",
609
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
610
+ };
611
+ }
612
+ function buildGraphqlConfig(prettierOptions) {
613
+ return {
614
+ files: [GLOB_GRAPHQL],
615
+ languageOptions: { parser: parserPlain },
616
+ name: "config/formatter/graphql",
617
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
618
+ };
619
+ }
620
+ function getFormattersPackagesToEnsure(options) {
621
+ return [
622
+ "eslint-plugin-format",
623
+ options.astro ? "prettier-plugin-astro" : void 0,
624
+ options.xml || options.svg ? "@prettier/plugin-xml" : void 0
625
+ ];
626
+ }
627
+ async function formatters(rawOptions = {}, stylistic = {}) {
628
+ const options = resolveFormattersOptions(rawOptions);
629
+ await ensurePackages(getFormattersPackagesToEnsure(options));
531
630
  const { indent, quotes, semi } = {
532
631
  ...StylisticConfigDefaults,
533
632
  ...stylistic
@@ -554,100 +653,16 @@ async function formatters(options = {}, stylistic = {}) {
554
653
  ...options.dprintOptions || {}
555
654
  };
556
655
  const configs = [{
557
- name: "config/formatters/setup",
656
+ name: "config/formatter/setup",
558
657
  plugins: { format: await interopDefault(import("eslint-plugin-format")) }
559
658
  }];
560
- if (options.css) configs.push({
561
- files: [GLOB_CSS, GLOB_POSTCSS],
562
- languageOptions: { parser: parserPlain },
563
- name: "config/formatter/css",
564
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "css" })] }
565
- }, {
566
- files: [GLOB_SCSS],
567
- languageOptions: { parser: parserPlain },
568
- name: "config/formatter/scss",
569
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "scss" })] }
570
- }, {
571
- files: [GLOB_LESS],
572
- languageOptions: { parser: parserPlain },
573
- name: "config/formatter/less",
574
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "less" })] }
575
- });
576
- if (options.html) configs.push({
577
- files: [GLOB_HTML],
578
- languageOptions: { parser: parserPlain },
579
- name: "config/formatter/html",
580
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
581
- });
582
- if (options.xml) configs.push({
583
- files: [GLOB_XML],
584
- languageOptions: { parser: parserPlain },
585
- name: "config/formatter/xml",
586
- rules: { "format/prettier": ["error", mergePrettierOptions({
587
- ...prettierXmlOptions,
588
- ...prettierOptions
589
- }, {
590
- parser: "xml",
591
- plugins: ["@prettier/plugin-xml"]
592
- })] }
593
- });
594
- if (options.svg) configs.push({
595
- files: [GLOB_SVG],
596
- languageOptions: { parser: parserPlain },
597
- name: "config/formatter/svg",
598
- rules: { "format/prettier": ["error", mergePrettierOptions({
599
- ...prettierXmlOptions,
600
- ...prettierOptions
601
- }, {
602
- parser: "xml",
603
- plugins: ["@prettier/plugin-xml"]
604
- })] }
605
- });
606
- if (options.markdown) {
607
- const formater = options.markdown === true ? "prettier" : options.markdown;
608
- configs.push({
609
- files: [GLOB_MARKDOWN],
610
- languageOptions: { parser: parserPlain },
611
- name: "config/formatter/markdown",
612
- rules: { [`format/${formater}`]: ["error", formater === "prettier" ? mergePrettierOptions(prettierOptions, {
613
- embeddedLanguageFormatting: "off",
614
- parser: "markdown"
615
- }) : {
616
- ...dprintOptions,
617
- language: "markdown"
618
- }] }
619
- });
620
- }
621
- if (options.astro) {
622
- configs.push({
623
- files: [GLOB_ASTRO],
624
- languageOptions: { parser: parserPlain },
625
- name: "config/formatter/astro",
626
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, {
627
- parser: "astro",
628
- plugins: ["prettier-plugin-astro"]
629
- })] }
630
- });
631
- configs.push({
632
- files: [GLOB_ASTRO, GLOB_ASTRO_TS],
633
- name: "config/formatter/astro/disables",
634
- rules: {
635
- "style/arrow-parens": "off",
636
- "style/block-spacing": "off",
637
- "style/comma-dangle": "off",
638
- "style/indent": "off",
639
- "style/no-multi-spaces": "off",
640
- "style/quotes": "off",
641
- "style/semi": "off"
642
- }
643
- });
644
- }
645
- if (options.graphql) configs.push({
646
- files: [GLOB_GRAPHQL],
647
- languageOptions: { parser: parserPlain },
648
- name: "config/formatter/graphql",
649
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
650
- });
659
+ if (options.css) configs.push(...buildCssConfigs(prettierOptions));
660
+ if (options.html) configs.push(buildHtmlConfig(prettierOptions));
661
+ if (options.xml) configs.push(buildXmlLikeConfig(prettierOptions, prettierXmlOptions, [GLOB_XML], "config/formatter/xml"));
662
+ if (options.svg) configs.push(buildXmlLikeConfig(prettierOptions, prettierXmlOptions, [GLOB_SVG], "config/formatter/svg"));
663
+ if (options.markdown) configs.push(...buildMarkdownConfigs(options, prettierOptions, dprintOptions));
664
+ if (options.astro) configs.push(...buildAstroConfigs(prettierOptions));
665
+ if (options.graphql) configs.push(buildGraphqlConfig(prettierOptions));
651
666
  return configs;
652
667
  }
653
668
  //#endregion
@@ -1230,7 +1245,7 @@ async function pnpm(options) {
1230
1245
  interopDefault(import("eslint-plugin-yml")),
1231
1246
  interopDefault(import("yaml-eslint-parser"))
1232
1247
  ]);
1233
- const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, yaml = true } = options;
1248
+ const { catalogs = await detectCatalogUsage(), isInEditor = false, json = true, sort = true, stylistic = true, yaml = true } = options;
1234
1249
  const configs = [];
1235
1250
  if (json) configs.push({
1236
1251
  files: ["package.json", "**/package.json"],
@@ -1254,6 +1269,7 @@ async function pnpm(options) {
1254
1269
  plugins: { pnpm: pluginPnpm },
1255
1270
  rules: {
1256
1271
  "pnpm/yaml-enforce-settings": ["error", { settings: {
1272
+ minimumReleaseAgeExcludePrune: true,
1257
1273
  shellEmulator: true,
1258
1274
  trustPolicy: "no-downgrade"
1259
1275
  } }],
@@ -1261,6 +1277,13 @@ async function pnpm(options) {
1261
1277
  "pnpm/yaml-no-unused-catalog-item": "error"
1262
1278
  }
1263
1279
  });
1280
+ if (stylistic) configs.push({
1281
+ files: ["pnpm-workspace.yaml"],
1282
+ languageOptions: { parser: yamlParser },
1283
+ name: "config/pnpm/pnpm-workspace-yaml-stylistic",
1284
+ plugins: { pnpm: pluginPnpm },
1285
+ rules: { "pnpm/yaml-blank-lines": "error" }
1286
+ });
1264
1287
  if (sort) configs.push({
1265
1288
  files: ["pnpm-workspace.yaml"],
1266
1289
  languageOptions: { parser: yamlParser },
@@ -1271,65 +1294,190 @@ async function pnpm(options) {
1271
1294
  {
1272
1295
  order: [
1273
1296
  ...[
1274
- "cacheDir",
1297
+ "dedupeInjectedDeps",
1298
+ "disallowWorkspaceCycles",
1299
+ "failIfNoMatch",
1300
+ "ignoreWorkspaceCycles",
1301
+ "ignoreWorkspaceRootCheck",
1302
+ "includeWorkspaceRoot",
1303
+ "injectWorkspacePackages",
1304
+ "legacyDirFiltering",
1305
+ "linkWorkspacePackages",
1306
+ "preferWorkspacePackages",
1307
+ "saveWorkspaceProtocol",
1308
+ "sharedWorkspaceLockfile",
1309
+ "syncInjectedDepsAfterScripts"
1310
+ ],
1311
+ ...[
1275
1312
  "catalogMode",
1276
- "cleanupUnusedCatalogs",
1277
- "dedupeDirectDeps",
1278
- "deployAllFiles",
1279
- "enablePrePostScripts",
1280
- "engineStrict",
1313
+ "catalogPrune",
1314
+ "cleanupUnusedCatalogs"
1315
+ ],
1316
+ ...[
1317
+ "allowedDeprecatedVersions",
1318
+ "blockExoticSubdeps",
1319
+ "ignoredOptionalDependencies",
1320
+ "minimumReleaseAge",
1321
+ "minimumReleaseAgeIgnoreMissingTime",
1322
+ "minimumReleaseAgeStrict",
1323
+ "minimumReleaseAgeExcludePrune",
1324
+ "minimumReleaseAgeExclude",
1325
+ "registrySupportsTimeField",
1326
+ "resolutionMode",
1327
+ "supportedArchitectures",
1328
+ "trustLockfile",
1329
+ "trustPolicy",
1330
+ "trustPolicyIgnoreAfter",
1331
+ "trustPolicyExclude",
1332
+ "update"
1333
+ ],
1334
+ ...[
1335
+ "autoInstallPeers",
1336
+ "dedupePeerDependents",
1337
+ "dedupePeers",
1338
+ "peerDependencyRules",
1339
+ "resolvePeersFromWorkspaceRoot",
1340
+ "strictPeerDependencies"
1341
+ ],
1342
+ ...[
1343
+ "fetchMinSpeedKiBps",
1344
+ "fetchRetries",
1345
+ "fetchRetryFactor",
1346
+ "fetchRetryMaxtimeout",
1347
+ "fetchRetryMintimeout",
1348
+ "fetchTimeout",
1349
+ "fetchWarnTimeoutMs",
1350
+ "gitShallowHosts",
1351
+ "httpProxy",
1352
+ "httpsProxy",
1353
+ "localAddress",
1354
+ "maxsockets",
1355
+ "namedRegistries",
1356
+ "networkConcurrency",
1357
+ "noProxy",
1358
+ "registries",
1359
+ "registry",
1360
+ "strictSsl"
1361
+ ],
1362
+ ...[
1363
+ "dlxCacheMaxAge",
1364
+ "enableGlobalVirtualStore",
1365
+ "enableModulesDir",
1281
1366
  "extendNodePath",
1367
+ "modulesCacheMaxAge",
1368
+ "modulesDir",
1369
+ "nodeExperimentalPackageMap",
1370
+ "nodeLinker",
1371
+ "nodePackageMapType",
1372
+ "packageImportMethod",
1373
+ "preferSymlinkedExecutables",
1374
+ "symlink",
1375
+ "virtualStoreDir",
1376
+ "virtualStoreDirMaxLength",
1377
+ "virtualStoreOnly",
1378
+ "virtualStoreType"
1379
+ ],
1380
+ ...[
1282
1381
  "hoist",
1382
+ "hoistingLimits",
1283
1383
  "hoistPattern",
1284
1384
  "hoistWorkspacePackages",
1285
- "ignoreCompatibilityDb",
1385
+ "publicHoistPattern",
1386
+ "shamefullyHoist"
1387
+ ],
1388
+ ...[
1389
+ "frozenStore",
1390
+ "storeDir",
1391
+ "strictStorePkgContentCheck",
1392
+ "useRunningStoreServer",
1393
+ "verifyStoreIntegrity"
1394
+ ],
1395
+ ...[
1396
+ "gitBranchLockfile",
1397
+ "lockfile",
1398
+ "lockfileIncludeTarballUrl",
1399
+ "mergeGitBranchLockfilesBranchPattern",
1400
+ "peersSuffixMaxLength",
1401
+ "preferFrozenLockfile"
1402
+ ],
1403
+ ...[
1404
+ "childConcurrency",
1405
+ "dangerouslyAllowAllBuilds",
1406
+ "enablePrePostScripts",
1286
1407
  "ignoreDepScripts",
1287
1408
  "ignoreScripts",
1288
- "ignoreWorkspaceRootCheck",
1409
+ "nodeOptions",
1410
+ "requiredScripts",
1411
+ "scriptShell",
1412
+ "shellEmulator",
1413
+ "sideEffectsCache",
1414
+ "sideEffectsCacheReadonly",
1415
+ "strictDepBuilds",
1416
+ "unsafePerm",
1417
+ "verifyDepsBeforeRun"
1418
+ ],
1419
+ ...[
1289
1420
  "managePackageManagerVersions",
1290
- "minimumReleaseAge",
1291
- "minimumReleaseAgeExclude",
1292
- "modulesDir",
1293
- "nodeLinker",
1421
+ "nodeDownloadMirrors",
1294
1422
  "nodeVersion",
1295
- "optimisticRepeatInstall",
1296
1423
  "packageManagerStrict",
1297
1424
  "packageManagerStrictVersion",
1298
- "preferSymlinkedExecutables",
1299
- "preferWorkspacePackages",
1300
- "publicHoistPattern",
1301
- "registrySupportsTimeField",
1302
- "requiredScripts",
1303
- "resolutionMode",
1425
+ "pmOnFail",
1426
+ "runtimeOnFail"
1427
+ ],
1428
+ ...[
1429
+ "ci",
1430
+ "color",
1431
+ "engineStrict",
1432
+ "loglevel",
1433
+ "npmPath",
1434
+ "recursiveInstall",
1435
+ "updateNotifier",
1436
+ "useBetaCli",
1437
+ "useStderr"
1438
+ ],
1439
+ ...[
1440
+ "cacheDir",
1441
+ "globalBinDir",
1442
+ "globalDir",
1443
+ "globalPnpmfile",
1444
+ "globalShims",
1445
+ "ignorePnpmfile",
1446
+ "npmrcAuthFile",
1447
+ "pnpmfile",
1448
+ "stateDir"
1449
+ ],
1450
+ ...["audit", "versioning"],
1451
+ ...[
1452
+ "allowNonAppliedPatches",
1453
+ "dedupeDirectDeps",
1454
+ "deployAllFiles",
1455
+ "ignoreCompatibilityDb",
1456
+ "initAuthorEmail",
1457
+ "initAuthorName",
1458
+ "initAuthorUrl",
1459
+ "initLicense",
1460
+ "initVersion",
1461
+ "optimisticRepeatInstall",
1462
+ "saveExact",
1304
1463
  "savePrefix",
1305
- "scriptShell",
1306
- "shamefullyHoist",
1307
- "shellEmulator",
1308
- "stateDir",
1309
- "supportedArchitectures",
1310
- "symlink",
1311
- "tag",
1312
- "trustPolicy",
1313
- "trustPolicyExclude",
1314
- "updateNotifier"
1464
+ "tag"
1315
1465
  ],
1316
1466
  "packages",
1467
+ "packageConfigs",
1317
1468
  "overrides",
1469
+ "packageExtensions",
1318
1470
  "patchedDependencies",
1319
- "catalog",
1320
- "catalogs",
1471
+ "configDependencies",
1472
+ "allowBuilds",
1321
1473
  ...[
1322
- "allowedDeprecatedVersions",
1323
- "allowNonAppliedPatches",
1324
- "configDependencies",
1325
1474
  "ignoredBuiltDependencies",
1326
- "ignoredOptionalDependencies",
1327
1475
  "neverBuiltDependencies",
1328
1476
  "onlyBuiltDependencies",
1329
- "onlyBuiltDependenciesFile",
1330
- "packageExtensions",
1331
- "peerDependencyRules"
1332
- ]
1477
+ "onlyBuiltDependenciesFile"
1478
+ ],
1479
+ "catalog",
1480
+ "catalogs"
1333
1481
  ],
1334
1482
  pathPattern: "^$"
1335
1483
  },
@@ -2042,6 +2190,7 @@ async function typescript(options = {}) {
2042
2190
  plugins: { "erasable-syntax-only": await interopDefault(import("eslint-plugin-erasable-syntax-only")) },
2043
2191
  rules: {
2044
2192
  "erasable-syntax-only/enums": "error",
2193
+ "erasable-syntax-only/export-aliases": "error",
2045
2194
  "erasable-syntax-only/import-aliases": "error",
2046
2195
  "erasable-syntax-only/namespaces": "error",
2047
2196
  "erasable-syntax-only/parameter-properties": "error"
@@ -2336,6 +2485,11 @@ async function yaml(options = {}) {
2336
2485
  "yaml/flow-sequence-bracket-spacing": "error",
2337
2486
  "yaml/indent": ["error", typeof indent === "number" ? indent : 2],
2338
2487
  "yaml/key-spacing": "error",
2488
+ "yaml/no-multiple-empty-lines": ["error", {
2489
+ max: 1,
2490
+ maxBOF: 0,
2491
+ maxEOF: 0
2492
+ }],
2339
2493
  "yaml/no-tab-indent": "error",
2340
2494
  "yaml/quotes": ["error", {
2341
2495
  avoidEscape: true,
@@ -2393,14 +2547,16 @@ function eslintFlatConfig(options = {}, ...userConfigs) {
2393
2547
  const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
2394
2548
  if (stylisticOptions && !("jsx" in stylisticOptions)) stylisticOptions.jsx = typeof enableJsx === "object" ? true : enableJsx;
2395
2549
  const configs = [];
2396
- if (enableGitignore) if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
2397
- name: "config/gitignore",
2398
- ...enableGitignore
2399
- })]));
2400
- else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
2401
- name: "config/gitignore",
2402
- strict: false
2403
- })]));
2550
+ if (enableGitignore) {
2551
+ if (typeof enableGitignore !== "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
2552
+ name: "config/gitignore",
2553
+ ...enableGitignore
2554
+ })]));
2555
+ else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
2556
+ name: "config/gitignore",
2557
+ strict: false
2558
+ })]));
2559
+ }
2404
2560
  const typescriptOptions = resolveSubOptions(options, "typescript");
2405
2561
  const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
2406
2562
  configs.push(ignores(userIgnores, !enableTypeScript), javascript({