@lincy/eslint-config 4.3.1 → 4.4.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/README.md CHANGED
@@ -135,7 +135,7 @@ export default lincy({
135
135
  /**
136
136
  * 是否启用 stylistic 格式化规则
137
137
  * @default 默认值: true
138
- * @example 可选: false | { indent?: number | 'tab'; quotes?: 'single' | 'double'; jsx?: boolean; semi?: boolean }
138
+ * @example 可选: false | { indent?: number | 'tab'; quotes?: 'single' | 'double'; jsx?: boolean; semi?: boolean; lessOpinionated?: boolean; }
139
139
  */
140
140
  stylistic: true,
141
141
  /**
package/dist/index.cjs CHANGED
@@ -440,7 +440,7 @@ async function javascript(options = {}) {
440
440
  "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
441
441
  "unused-imports/no-unused-vars": [
442
442
  "error",
443
- { args: "after-used", argsIgnorePattern: "^_", vars: "all", varsIgnorePattern: "^_" }
443
+ { args: "after-used", argsIgnorePattern: "^_", ignoreRestSiblings: true, vars: "all", varsIgnorePattern: "^_" }
444
444
  ],
445
445
  "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }],
446
446
  "valid-typeof": ["error", { requireStringLiterals: true }],
@@ -470,8 +470,9 @@ function renameRules(rules, map) {
470
470
  return Object.fromEntries(
471
471
  Object.entries(rules).map(([key, value]) => {
472
472
  for (const [from, to] of Object.entries(map)) {
473
- if (key.startsWith(`${from}/`))
473
+ if (key.startsWith(`${from}/`)) {
474
474
  return [to + key.slice(from.length), value];
475
+ }
475
476
  }
476
477
  return [key, value];
477
478
  })
@@ -480,13 +481,15 @@ function renameRules(rules, map) {
480
481
  function renamePluginInConfigs(configs, map) {
481
482
  return configs.map((i) => {
482
483
  const clone = { ...i };
483
- if (clone.rules)
484
+ if (clone.rules) {
484
485
  clone.rules = renameRules(clone.rules, map);
486
+ }
485
487
  if (clone.plugins) {
486
488
  clone.plugins = Object.fromEntries(
487
489
  Object.entries(clone.plugins).map(([key, value]) => {
488
- if (key in map)
490
+ if (key in map) {
489
491
  return [map[key], value];
492
+ }
490
493
  return [key, value];
491
494
  })
492
495
  );
@@ -502,11 +505,13 @@ async function interopDefault(m) {
502
505
  return resolved.default || resolved;
503
506
  }
504
507
  async function ensurePackages(packages) {
505
- if (import_node_process.default.stdout.isTTY === false)
508
+ if (import_node_process.default.stdout.isTTY === false) {
506
509
  return;
510
+ }
507
511
  const nonExistingPackages = packages.filter((i) => !(0, import_local_pkg.isPackageExists)(i));
508
- if (nonExistingPackages.length === 0)
512
+ if (nonExistingPackages.length === 0) {
509
513
  return;
514
+ }
510
515
  const { default: prompts } = await import("prompts");
511
516
  const { result } = await prompts([
512
517
  {
@@ -515,8 +520,9 @@ async function ensurePackages(packages) {
515
520
  type: "confirm"
516
521
  }
517
522
  ]);
518
- if (result)
523
+ if (result) {
519
524
  await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
525
+ }
520
526
  }
521
527
 
522
528
  // src/configs/jsdoc.ts
@@ -741,6 +747,7 @@ var parserPlain2 = __toESM(require("eslint-parser-plain"), 1);
741
747
  var StylisticConfigDefaults = {
742
748
  indent: 4,
743
749
  jsx: true,
750
+ lessOpinionated: true,
744
751
  quotes: "single",
745
752
  semi: false
746
753
  };
@@ -752,6 +759,7 @@ async function stylistic(options = {}) {
752
759
  const {
753
760
  indent,
754
761
  jsx,
762
+ lessOpinionated,
755
763
  quotes,
756
764
  semi
757
765
  } = typeof stylistic2 === "boolean" ? StylisticConfigDefaults : { ...StylisticConfigDefaults, ...stylistic2 };
@@ -774,9 +782,13 @@ async function stylistic(options = {}) {
774
782
  rules: {
775
783
  ...config.rules,
776
784
  "antfu/consistent-list-newline": "off",
777
- "antfu/if-newline": "error",
778
- "antfu/top-level-function": "error",
779
- "curly": ["error", "multi-or-nest", "consistent"],
785
+ ...lessOpinionated ? {
786
+ curly: ["error", "all"]
787
+ } : {
788
+ "antfu/if-newline": "error",
789
+ "antfu/top-level-function": "error",
790
+ "curly": ["error", "multi-or-nest", "consistent"]
791
+ },
780
792
  // 覆盖`stylistic`默认规则
781
793
  "style/member-delimiter-style": ["error", { multiline: { delimiter: "none" } }],
782
794
  "style/multiline-ternary": ["error", "never"],
@@ -889,7 +901,7 @@ async function formatters(options = {}, stylistic2 = {}) {
889
901
  }
890
902
  if (options.html) {
891
903
  configs.push({
892
- files: ["**/*.html"],
904
+ files: [GLOB_HTML],
893
905
  languageOptions: {
894
906
  parser: parserPlain2
895
907
  },
@@ -1985,16 +1997,18 @@ function lincy(options = {}, ...userConfigs) {
1985
1997
  } = options;
1986
1998
  const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
1987
1999
  if (stylisticOptions) {
1988
- if (!("jsx" in stylisticOptions))
2000
+ if (!("jsx" in stylisticOptions)) {
1989
2001
  stylisticOptions.jsx = options.jsx ?? true;
2002
+ }
1990
2003
  }
1991
2004
  const configs = [];
1992
2005
  if (enableGitignore) {
1993
2006
  if (typeof enableGitignore !== "boolean") {
1994
2007
  configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r(enableGitignore)]));
1995
2008
  } else {
1996
- if (import_node_fs.default.existsSync(".gitignore"))
2009
+ if (import_node_fs.default.existsSync(".gitignore")) {
1997
2010
  configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r()]));
2011
+ }
1998
2012
  }
1999
2013
  }
2000
2014
  configs.push(
@@ -2017,8 +2031,9 @@ function lincy(options = {}, ...userConfigs) {
2017
2031
  // Optional plugins (installed but not enabled by default)
2018
2032
  perfectionist()
2019
2033
  );
2020
- if (enableVue)
2034
+ if (enableVue) {
2021
2035
  componentExts.push("vue");
2036
+ }
2022
2037
  if (enableTypeScript) {
2023
2038
  configs.push(typescript({
2024
2039
  ...typeof enableTypeScript !== "boolean" ? enableTypeScript : {},
@@ -2098,20 +2113,23 @@ function lincy(options = {}, ...userConfigs) {
2098
2113
  ));
2099
2114
  }
2100
2115
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
2101
- if (key in options)
2116
+ if (key in options) {
2102
2117
  acc[key] = options[key];
2118
+ }
2103
2119
  return acc;
2104
2120
  }, {});
2105
- if (Object.keys(fusedConfig).length)
2121
+ if (Object.keys(fusedConfig).length) {
2106
2122
  configs.push([fusedConfig]);
2107
- let pipeline = new import_eslint_flat_config_utils.FlatConfigComposer();
2108
- pipeline = pipeline.append(
2123
+ }
2124
+ let composer = new import_eslint_flat_config_utils.FlatConfigComposer();
2125
+ composer = composer.append(
2109
2126
  ...configs,
2110
2127
  ...userConfigs
2111
2128
  );
2112
- if (autoRenamePlugins)
2113
- pipeline = pipeline.renamePlugins(defaultPluginRenaming);
2114
- return pipeline;
2129
+ if (autoRenamePlugins) {
2130
+ composer = composer.renamePlugins(defaultPluginRenaming);
2131
+ }
2132
+ return composer;
2115
2133
  }
2116
2134
 
2117
2135
  // src/index.ts