@lincy/eslint-config 6.0.0 → 6.1.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
@@ -2,6 +2,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_chunk = require('./chunk-DWy1uDak.cjs');
3
3
  let eslint_flat_config_utils = require("eslint-flat-config-utils");
4
4
  eslint_flat_config_utils = require_chunk.__toESM(eslint_flat_config_utils);
5
+ let node_process = require("node:process");
6
+ node_process = require_chunk.__toESM(node_process);
7
+ let node_url = require("node:url");
8
+ node_url = require_chunk.__toESM(node_url);
9
+ let node_fs = require("node:fs");
10
+ node_fs = require_chunk.__toESM(node_fs);
11
+ let node_path = require("node:path");
12
+ node_path = require_chunk.__toESM(node_path);
5
13
  let local_pkg = require("local-pkg");
6
14
  local_pkg = require_chunk.__toESM(local_pkg);
7
15
  let __eslint_community_eslint_plugin_eslint_comments = require("@eslint-community/eslint-plugin-eslint-comments");
@@ -18,10 +26,6 @@ let eslint_plugin_unicorn = require("eslint-plugin-unicorn");
18
26
  eslint_plugin_unicorn = require_chunk.__toESM(eslint_plugin_unicorn);
19
27
  let eslint_plugin_unused_imports = require("eslint-plugin-unused-imports");
20
28
  eslint_plugin_unused_imports = require_chunk.__toESM(eslint_plugin_unused_imports);
21
- let node_process = require("node:process");
22
- node_process = require_chunk.__toESM(node_process);
23
- let node_url = require("node:url");
24
- node_url = require_chunk.__toESM(node_url);
25
29
  let globals = require("globals");
26
30
  globals = require_chunk.__toESM(globals);
27
31
  let eslint_merge_processors = require("eslint-merge-processors");
@@ -31,6 +35,25 @@ eslint_parser_plain = require_chunk.__toESM(eslint_parser_plain);
31
35
  let eslint_plugin_regexp = require("eslint-plugin-regexp");
32
36
  eslint_plugin_regexp = require_chunk.__toESM(eslint_plugin_regexp);
33
37
 
38
+ //#region node_modules/.pnpm/find-up-simple@1.0.1/node_modules/find-up-simple/index.js
39
+ const toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, node_url.fileURLToPath)(urlOrPath) : urlOrPath;
40
+ function findUpSync(name, { cwd = node_process.default.cwd(), type = "file", stopAt } = {}) {
41
+ let directory = node_path.default.resolve(toPath(cwd) ?? "");
42
+ const { root } = node_path.default.parse(directory);
43
+ stopAt = node_path.default.resolve(directory, toPath(stopAt) ?? root);
44
+ const isAbsoluteName = node_path.default.isAbsolute(name);
45
+ while (directory) {
46
+ const filePath = isAbsoluteName ? name : node_path.default.join(directory, name);
47
+ try {
48
+ const stats = node_fs.default.statSync(filePath, { throwIfNoEntry: false });
49
+ if (type === "file" && stats?.isFile() || type === "directory" && stats?.isDirectory()) return filePath;
50
+ } catch {}
51
+ if (directory === stopAt || directory === root) break;
52
+ directory = node_path.default.dirname(directory);
53
+ }
54
+ }
55
+
56
+ //#endregion
34
57
  //#region src/configs/comments.ts
35
58
  async function comments(options = {}) {
36
59
  const { overrides = {} } = options;
@@ -880,6 +903,11 @@ async function nextjs(options = {}) {
880
903
  const { files = [GLOB_SRC], overrides = {} } = options;
881
904
  await ensurePackages(["@next/eslint-plugin-next"]);
882
905
  const pluginNextJS = await interopDefault(import("@next/eslint-plugin-next"));
906
+ function getRules(name) {
907
+ const rules = pluginNextJS.configs?.[name]?.rules;
908
+ if (!rules) throw new Error(`[@lincy/eslint-config] Failed to find config ${name} in @next/eslint-plugin-next`);
909
+ return normalizeRules(rules);
910
+ }
883
911
  return [{
884
912
  name: "eslint/nextjs/setup",
885
913
  plugins: { next: pluginNextJS }
@@ -891,8 +919,8 @@ async function nextjs(options = {}) {
891
919
  },
892
920
  name: "eslint/nextjs/rules",
893
921
  rules: {
894
- ...normalizeRules(pluginNextJS.configs.recommended.rules),
895
- ...normalizeRules(pluginNextJS.configs["core-web-vitals"].rules),
922
+ ...getRules("recommended"),
923
+ ...getRules("core-web-vitals"),
896
924
  ...overrides
897
925
  },
898
926
  settings: { react: { version: "detect" } }
@@ -979,7 +1007,7 @@ async function perfectionist(options = {}) {
979
1007
 
980
1008
  //#endregion
981
1009
  //#region src/configs/pnpm.ts
982
- async function pnpm() {
1010
+ async function pnpm(options = {}) {
983
1011
  const [pluginPnpm, yamlParser, jsoncParser] = await Promise.all([
984
1012
  interopDefault(import("eslint-plugin-pnpm")),
985
1013
  interopDefault(import("yaml-eslint-parser")),
@@ -991,9 +1019,9 @@ async function pnpm() {
991
1019
  name: "eslint/pnpm/package-json",
992
1020
  plugins: { pnpm: pluginPnpm },
993
1021
  rules: {
994
- "pnpm/json-enforce-catalog": "error",
995
- "pnpm/json-prefer-workspace-settings": "error",
996
- "pnpm/json-valid-catalog": "error"
1022
+ "pnpm/json-enforce-catalog": ["error", { autofix: !options.isInEditor }],
1023
+ "pnpm/json-prefer-workspace-settings": ["error", { autofix: !options.isInEditor }],
1024
+ "pnpm/json-valid-catalog": ["error", { autofix: !options.isInEditor }]
997
1025
  }
998
1026
  }, {
999
1027
  files: ["pnpm-workspace.yaml"],
@@ -1001,6 +1029,11 @@ async function pnpm() {
1001
1029
  name: "eslint/pnpm/pnpm-workspace-yaml",
1002
1030
  plugins: { pnpm: pluginPnpm },
1003
1031
  rules: {
1032
+ "pnpm/yaml-enforce-settings": ["error", { settings: {
1033
+ catalogMode: "prefer",
1034
+ cleanupUnusedCatalogs: true,
1035
+ shellEmulator: true
1036
+ } }],
1004
1037
  "pnpm/yaml-no-duplicate-catalog-item": "error",
1005
1038
  "pnpm/yaml-no-unused-catalog-item": "error"
1006
1039
  }
@@ -1631,7 +1664,7 @@ async function typescript(options = {}) {
1631
1664
  }] : [],
1632
1665
  ...erasableOnly ? [{
1633
1666
  name: "eslint/typescript/erasable-syntax-only",
1634
- plugins: { "erasable-syntax-only": await interopDefault(Promise.resolve().then(() => require("./lib-B2tdYoXA.cjs"))) },
1667
+ plugins: { "erasable-syntax-only": await interopDefault(Promise.resolve().then(() => require("./lib-DS4wQk2J.cjs"))) },
1635
1668
  rules: {
1636
1669
  "erasable-syntax-only/enums": "error",
1637
1670
  "erasable-syntax-only/import-aliases": "error",
@@ -1951,23 +1984,66 @@ async function yaml(options = {}) {
1951
1984
  "error",
1952
1985
  {
1953
1986
  order: [
1987
+ ...[
1988
+ "cacheDir",
1989
+ "catalogMode",
1990
+ "cleanupUnusedCatalogs",
1991
+ "dedupeDirectDeps",
1992
+ "deployAllFiles",
1993
+ "enablePrePostScripts",
1994
+ "engineStrict",
1995
+ "extendNodePath",
1996
+ "hoist",
1997
+ "hoistPattern",
1998
+ "hoistWorkspacePackages",
1999
+ "ignoreCompatibilityDb",
2000
+ "ignoreDepScripts",
2001
+ "ignoreScripts",
2002
+ "ignoreWorkspaceRootCheck",
2003
+ "managePackageManagerVersions",
2004
+ "minimumReleaseAge",
2005
+ "minimumReleaseAgeExclude",
2006
+ "modulesDir",
2007
+ "nodeLinker",
2008
+ "nodeVersion",
2009
+ "optimisticRepeatInstall",
2010
+ "packageManagerStrict",
2011
+ "packageManagerStrictVersion",
2012
+ "preferSymlinkedExecutables",
2013
+ "preferWorkspacePackages",
2014
+ "publicHoistPattern",
2015
+ "registrySupportsTimeField",
2016
+ "requiredScrpts",
2017
+ "resolutionMode",
2018
+ "savePrefix",
2019
+ "scriptShell",
2020
+ "shamefullyHoist",
2021
+ "shellEmulator",
2022
+ "stateDir",
2023
+ "supportedArchitectures",
2024
+ "symlink",
2025
+ "tag",
2026
+ "trustPolicy",
2027
+ "trustPolicyExclude",
2028
+ "updateNotifier"
2029
+ ],
1954
2030
  "packages",
1955
2031
  "overrides",
1956
2032
  "patchedDependencies",
1957
- "hoistPattern",
1958
2033
  "catalog",
1959
2034
  "catalogs",
1960
- "allowedDeprecatedVersions",
1961
- "allowNonAppliedPatches",
1962
- "configDependencies",
1963
- "ignoredBuiltDependencies",
1964
- "ignoredOptionalDependencies",
1965
- "neverBuiltDependencies",
1966
- "onlyBuiltDependencies",
1967
- "onlyBuiltDependenciesFile",
1968
- "packageExtensions",
1969
- "peerDependencyRules",
1970
- "supportedArchitectures"
2035
+ ...[
2036
+ "allowedDeprecatedVersions",
2037
+ "allowNonAppliedPatches",
2038
+ "configDependencies",
2039
+ "ignoredBuiltDependencies",
2040
+ "ignoredOptionalDependencies",
2041
+ "neverBuiltDependencies",
2042
+ "onlyBuiltDependencies",
2043
+ "onlyBuiltDependenciesFile",
2044
+ "packageExtensions",
2045
+ "peerDependencyRules"
2046
+ ]
1971
2047
  ],
1972
2048
  pathPattern: "^$"
1973
2049
  },
@@ -2021,7 +2097,7 @@ const defaultPluginRenaming = {
2021
2097
  * 合并的 ESLint 配置
2022
2098
  */
2023
2099
  function lincy(options = {}, ...userConfigs) {
2024
- const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores: ignoresList = [], imports: enableImports = true, jsx: enableJsx = true, nextjs: enableNextjs = false, overrides = {}, pnpm: enableCatalogs = false, react: enableReact = false, regexp: enableRegexp = true, typescript: enableTypeScript = (0, local_pkg.isPackageExists)("typescript"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false, vue: enableVue = VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)) } = options;
2100
+ const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, ignores: ignoresList = [], imports: enableImports = true, jsx: enableJsx = true, nextjs: enableNextjs = false, overrides = {}, pnpm: enableCatalogs = !!findUpSync("pnpm-workspace.yaml"), react: enableReact = false, regexp: enableRegexp = true, typescript: enableTypeScript = (0, local_pkg.isPackageExists)("typescript"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false, vue: enableVue = VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)) } = options;
2025
2101
  let isInEditor = options.isInEditor;
2026
2102
  if (isInEditor == null) {
2027
2103
  isInEditor = isInEditorEnv();
@@ -2099,7 +2175,7 @@ function lincy(options = {}, ...userConfigs) {
2099
2175
  overrides: getOverrides(options, "jsonc"),
2100
2176
  stylistic: stylisticOptions
2101
2177
  }), sortPackageJson(), sortTsconfig());
2102
- if (enableCatalogs) configs$1.push(pnpm());
2178
+ if (enableCatalogs) configs$1.push(pnpm({ isInEditor }));
2103
2179
  if (options.yaml ?? true) configs$1.push(yaml({
2104
2180
  ...resolveSubOptions(options, "yaml"),
2105
2181
  overrides: getOverrides(options, "yaml"),