@coderwyd/eslint-config 2.6.3 → 2.7.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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/plugins/index.ts
2
2
  import { default as default2 } from "eslint-plugin-antfu";
3
- import { default as default3 } from "eslint-plugin-eslint-comments";
3
+ import { default as default3 } from "@eslint-community/eslint-plugin-eslint-comments";
4
4
  import * as pluginImport from "eslint-plugin-import-x";
5
5
  import { default as default4 } from "eslint-plugin-n";
6
6
  import { default as default5 } from "eslint-plugin-unicorn";
@@ -90,10 +90,14 @@ var GLOB_EXCLUDE = [
90
90
  ];
91
91
 
92
92
  // src/configs/ignores.ts
93
- function ignores() {
93
+ function ignores(userIgnores = []) {
94
94
  return [
95
95
  {
96
- ignores: GLOB_EXCLUDE
96
+ ignores: [
97
+ ...GLOB_EXCLUDE,
98
+ ...userIgnores
99
+ ],
100
+ name: "coderwyd/ignores"
97
101
  }
98
102
  ];
99
103
  }
@@ -268,9 +272,6 @@ function javascript(options = {}) {
268
272
  ],
269
273
  "no-restricted-syntax": [
270
274
  "error",
271
- "DebuggerStatement",
272
- "LabeledStatement",
273
- "WithStatement",
274
275
  "TSEnumDeclaration[const=true]",
275
276
  "TSExportAssignment"
276
277
  ],
@@ -386,7 +387,10 @@ function javascript(options = {}) {
386
387
 
387
388
  // src/shared/index.ts
388
389
  import process from "node:process";
390
+ import { fileURLToPath } from "node:url";
389
391
  import { getPackageInfoSync, isPackageExists } from "local-pkg";
392
+ var scopeUrl = fileURLToPath(new URL(".", import.meta.url));
393
+ var isCwdInScope = isPackageExists("@coderwyd/eslint-config");
390
394
  var parserPlain = {
391
395
  meta: {
392
396
  name: "parser-plain"
@@ -452,10 +456,13 @@ async function interopDefault(m) {
452
456
  const resolved = await m;
453
457
  return resolved.default || resolved;
454
458
  }
459
+ function isPackageInScope(name) {
460
+ return isPackageExists(name, { paths: [scopeUrl] });
461
+ }
455
462
  async function ensurePackages(packages) {
456
- if (process.env.CI || process.stdout.isTTY === false)
463
+ if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false)
457
464
  return;
458
- const nonExistingPackages = packages.filter((i) => !isPackageExists(i));
465
+ const nonExistingPackages = packages.filter((i) => !isPackageInScope(i));
459
466
  if (nonExistingPackages.length === 0)
460
467
  return;
461
468
  const { default: prompts } = await import("prompts");
@@ -481,6 +488,16 @@ function getOverrides(options, key) {
481
488
  ..."overrides" in sub ? sub.overrides || {} : {}
482
489
  };
483
490
  }
491
+ function isInEditorEnv() {
492
+ if (process.env.CI)
493
+ return false;
494
+ if (isInGitHooksOrLintStaged())
495
+ return false;
496
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
497
+ }
498
+ function isInGitHooksOrLintStaged() {
499
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("nano-staged") || false);
500
+ }
484
501
 
485
502
  // src/configs/jsdoc.ts
486
503
  async function jsdoc(options = {}) {
@@ -895,7 +912,7 @@ async function stylistic(options = {}) {
895
912
  // src/configs/typescript.ts
896
913
  import process2 from "node:process";
897
914
  async function typescript(options = {}) {
898
- const { componentExts = [], overrides = {}, parserOptions = {} } = options;
915
+ const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {} } = options;
899
916
  const files = options.files ?? [
900
917
  GLOB_TS,
901
918
  GLOB_TSX,
@@ -968,8 +985,8 @@ async function typescript(options = {}) {
968
985
  },
969
986
  // assign type-aware parser for type-aware files and type-unaware parser for the rest
970
987
  ...isTypeAware ? [
971
- makeParser(true, filesTypeAware, ignoresTypeAware),
972
- makeParser(false, files, filesTypeAware)
988
+ makeParser(false, files),
989
+ makeParser(true, filesTypeAware, ignoresTypeAware)
973
990
  ] : [makeParser(false, files)],
974
991
  {
975
992
  files,
@@ -1036,8 +1053,8 @@ async function typescript(options = {}) {
1036
1053
  ignores: ignoresTypeAware,
1037
1054
  name: "coderwyd/typescript/rules-type-aware",
1038
1055
  rules: {
1039
- ...tsconfigPath ? typeAwareRules : {},
1040
- ...overrides
1056
+ ...typeAwareRules,
1057
+ ...overridesTypeAware
1041
1058
  }
1042
1059
  }
1043
1060
  ] : [],
@@ -1457,39 +1474,6 @@ function perfectionist() {
1457
1474
  "perfectionist/sort-named-imports": [
1458
1475
  "warn",
1459
1476
  { groupKind: "values-first" }
1460
- ],
1461
- "perfectionist/sort-vue-attributes": [
1462
- "error",
1463
- {
1464
- // Based on: https://vuejs.org/style-guide/rules-recommended.html#element-attribute-order
1465
- customGroups: {
1466
- CONDITIONALS: "v-*(else-if|if|else|show|cloak)",
1467
- CONTENT: "v-*(html|text)",
1468
- DEFINITION: "*(is|:is|v-is)",
1469
- // OTHER_DIRECTIVES e.g. 'v-custom-directive'
1470
- EVENTS: "*(v-on|@*)",
1471
- GLOBAL: "*(:id|id)",
1472
- LIST_RENDERING: "v-for",
1473
- RENDER_MODIFIERS: "v-*(pre|once)",
1474
- SLOT: "*(v-slot|slot)",
1475
- TWO_WAY_BINDING: "*(v-model|v-model:*)",
1476
- UNIQUE: "*(ref|key|:ref|:key)"
1477
- },
1478
- groups: [
1479
- "DEFINITION",
1480
- "LIST_RENDERING",
1481
- "CONDITIONALS",
1482
- "RENDER_MODIFIERS",
1483
- "GLOBAL",
1484
- "UNIQUE",
1485
- "SLOT",
1486
- "TWO_WAY_BINDING",
1487
- "unknown",
1488
- "EVENTS",
1489
- "CONTENT"
1490
- ],
1491
- type: "natural"
1492
- }
1493
1477
  ]
1494
1478
  }
1495
1479
  }
@@ -1957,8 +1941,6 @@ function jsx() {
1957
1941
  // src/index.ts
1958
1942
  var flatConfigProps = [
1959
1943
  "name",
1960
- "files",
1961
- "ignores",
1962
1944
  "languageOptions",
1963
1945
  "linterOptions",
1964
1946
  "processor",
@@ -1987,7 +1969,6 @@ async function defineConfig(options = {}, ...userConfigs) {
1987
1969
  html: true
1988
1970
  },
1989
1971
  gitignore: enableGitignore = true,
1990
- isInEditor: isInEditor2 = isInEditor,
1991
1972
  jsx: enableJsx = true,
1992
1973
  react: enableReact = false,
1993
1974
  regexp: enableRegexp = true,
@@ -1997,6 +1978,12 @@ async function defineConfig(options = {}, ...userConfigs) {
1997
1978
  unocss: enableUnoCSS = false,
1998
1979
  vue: enableVue = hasVue
1999
1980
  } = options;
1981
+ let isInEditor2 = options.isInEditor;
1982
+ if (isInEditor2 == null) {
1983
+ isInEditor2 = isInEditorEnv();
1984
+ if (isInEditor2)
1985
+ console.log("[@coderwyd/eslint-config] Detected running in editor, some rules are disabled.");
1986
+ }
2000
1987
  const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
2001
1988
  if (stylisticOptions && !("jsx" in stylisticOptions))
2002
1989
  stylisticOptions.jsx = enableJsx;
@@ -2005,17 +1992,20 @@ async function defineConfig(options = {}, ...userConfigs) {
2005
1992
  if (typeof enableGitignore !== "boolean") {
2006
1993
  configs2.push(
2007
1994
  interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
2008
- r(enableGitignore)
1995
+ r({
1996
+ ...enableGitignore,
1997
+ name: "coderwyd/gitignore"
1998
+ })
2009
1999
  ])
2010
2000
  );
2011
2001
  } else {
2012
- configs2.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({ strict: false })]));
2002
+ configs2.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({ name: "coderwyd/gitignore", strict: false })]));
2013
2003
  }
2014
2004
  }
2015
2005
  const typescriptOptions = resolveSubOptions(options, "typescript");
2016
2006
  const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
2017
2007
  configs2.push(
2018
- ignores(),
2008
+ ignores(options.ignores),
2019
2009
  javascript({
2020
2010
  isInEditor: isInEditor2,
2021
2011
  overrides: getOverrides(options, "javascript")
@@ -2126,6 +2116,9 @@ async function defineConfig(options = {}, ...userConfigs) {
2126
2116
  )
2127
2117
  );
2128
2118
  }
2119
+ if ("files" in options) {
2120
+ throw new Error('[@coderwyd/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.');
2121
+ }
2129
2122
  const fusedConfig = flatConfigProps.reduce((acc, key) => {
2130
2123
  if (key in options)
2131
2124
  acc[key] = options[key];
@@ -2146,6 +2139,9 @@ export {
2146
2139
  getOverrides,
2147
2140
  getVueVersion,
2148
2141
  interopDefault,
2142
+ isInEditorEnv,
2143
+ isInGitHooksOrLintStaged,
2144
+ isPackageInScope,
2149
2145
  parserPlain,
2150
2146
  renamePluginInConfigs,
2151
2147
  renameRules,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderwyd/eslint-config",
3
3
  "type": "module",
4
- "version": "2.6.3",
4
+ "version": "2.7.0",
5
5
  "description": "Donny's ESLint config",
6
6
  "author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",
7
7
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "peerDependencies": {
38
38
  "@eslint-react/eslint-plugin": "^1.5.8",
39
39
  "@unocss/eslint-plugin": ">=0.50.0",
40
- "eslint": "^8.56.0 || ^9.0.0",
40
+ "eslint": "^9.5.0",
41
41
  "eslint-plugin-react-hooks": "^4.6.0",
42
42
  "eslint-plugin-react-refresh": "^0.4.4",
43
43
  "eslint-plugin-svelte": ">=2.35.1",
@@ -68,30 +68,31 @@
68
68
  }
69
69
  },
70
70
  "dependencies": {
71
- "@antfu/install-pkg": "^0.3.3",
72
- "@stylistic/eslint-plugin": "^2.6.2",
71
+ "@antfu/install-pkg": "^0.4.1",
72
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
73
+ "@stylistic/eslint-plugin": "^2.7.1",
73
74
  "@toml-tools/parser": "^1.0.0",
74
- "@typescript-eslint/eslint-plugin": "^8.0.1",
75
- "@typescript-eslint/parser": "^8.0.1",
76
- "@vitest/eslint-plugin": "^1.0.0",
77
- "eslint-config-flat-gitignore": "^0.1.8",
75
+ "@typescript-eslint/eslint-plugin": "^8.3.0",
76
+ "@typescript-eslint/parser": "^8.3.0",
77
+ "@vitest/eslint-plugin": "^1.1.0",
78
+ "eslint-config-flat-gitignore": "^0.3.0",
78
79
  "eslint-merge-processors": "^0.1.0",
79
- "eslint-plugin-antfu": "^2.3.4",
80
+ "eslint-plugin-antfu": "^2.3.6",
80
81
  "eslint-plugin-command": "^0.2.3",
81
82
  "eslint-plugin-eslint-comments": "^3.2.0",
82
83
  "eslint-plugin-format": "^0.1.2",
83
- "eslint-plugin-import-x": "^3.1.0",
84
- "eslint-plugin-jsdoc": "^50.0.1",
84
+ "eslint-plugin-import-x": "^4.1.1",
85
+ "eslint-plugin-jsdoc": "^50.2.2",
85
86
  "eslint-plugin-jsonc": "^2.16.0",
86
87
  "eslint-plugin-n": "^17.10.2",
87
- "eslint-plugin-no-only-tests": "^3.1.0",
88
- "eslint-plugin-perfectionist": "^3.1.3",
88
+ "eslint-plugin-no-only-tests": "^3.3.0",
89
+ "eslint-plugin-perfectionist": "^3.3.0",
89
90
  "eslint-plugin-regexp": "^2.6.0",
90
91
  "eslint-plugin-unicorn": "^55.0.0",
91
92
  "eslint-plugin-unused-imports": "^4.1.3",
92
93
  "eslint-plugin-vue": "^9.27.0",
93
94
  "eslint-processor-vue-blocks": "^0.1.2",
94
- "eslint-typegen": "^0.3.0",
95
+ "eslint-typegen": "^0.3.1",
95
96
  "globals": "^15.9.0",
96
97
  "jsonc-eslint-parser": "^2.4.0",
97
98
  "local-pkg": "^0.5.0",
@@ -103,44 +104,45 @@
103
104
  "yargs": "^17.7.2"
104
105
  },
105
106
  "devDependencies": {
106
- "@antfu/ni": "^0.22.1",
107
- "@eslint-react/eslint-plugin": "^1.9.1",
108
- "@eslint/config-inspector": "^0.5.2",
109
- "@stylistic/eslint-plugin-migrate": "^2.6.2",
110
- "@types/eslint": "^9.6.0",
107
+ "@antfu/ni": "^0.23.0",
108
+ "@eslint-react/eslint-plugin": "^1.12.3",
109
+ "@eslint/config-inspector": "^0.5.4",
110
+ "@stylistic/eslint-plugin-migrate": "^2.7.1",
111
+ "@types/eslint": "^9.6.1",
111
112
  "@types/fs-extra": "^11.0.4",
112
- "@types/node": "^20.14.15",
113
+ "@types/node": "^20.16.2",
113
114
  "@types/prompts": "^2.4.9",
114
115
  "@types/yargs": "^17.0.33",
115
- "@unocss/eslint-plugin": "^0.61.9",
116
- "bumpp": "^9.4.2",
117
- "eslint": "^9.9.0",
116
+ "@unocss/eslint-plugin": "^0.62.3",
117
+ "bumpp": "^9.5.2",
118
+ "eslint": "^9.9.1",
118
119
  "eslint-plugin-react-hooks": "^4.6.2",
119
- "eslint-plugin-react-refresh": "^0.4.9",
120
+ "eslint-plugin-react-refresh": "^0.4.11",
120
121
  "eslint-plugin-svelte": "2.43.0",
121
122
  "eslint-plugin-tailwindcss": "^3.17.4",
122
- "execa": "^9.3.0",
123
+ "execa": "^9.3.1",
123
124
  "fast-glob": "^3.3.2",
124
125
  "fs-extra": "^11.2.0",
125
- "lint-staged": "^15.2.8",
126
+ "jiti": "^1.21.6",
127
+ "lint-staged": "^15.2.9",
126
128
  "rimraf": "^6.0.1",
127
129
  "simple-git-hooks": "^2.11.1",
128
- "svelte": "^4.2.18",
130
+ "svelte": "^4.2.19",
129
131
  "svelte-eslint-parser": "^0.41.0",
130
132
  "tsup": "^8.2.4",
131
- "tsx": "^4.17.0",
133
+ "tsx": "^4.19.0",
132
134
  "typescript": "^5.5.4"
133
135
  },
134
136
  "simple-git-hooks": {
135
137
  "pre-commit": "pnpx nano-staged"
136
138
  },
137
139
  "nano-staged": {
138
- "*": "eslint --fix"
140
+ "*": "eslint --flag unstable_ts_config --fix"
139
141
  },
140
142
  "scripts": {
141
143
  "build": "nr build:typegen && tsup",
142
144
  "dev": "npx @eslint/config-inspector",
143
- "lint": "eslint .",
145
+ "lint": "eslint --flag unstable_ts_config .",
144
146
  "lint:fix": "eslint . --fix",
145
147
  "build:inspector": "pnpm build && npx @eslint/config-inspector build",
146
148
  "build:typegen": "tsx scripts/typegen.ts",