@zjutjh/eslint-config 2.0.0-beta.0 → 2.0.0-beta.1

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
@@ -104,7 +104,10 @@ export default zjutjh({
104
104
  },
105
105
  ignores: [
106
106
  "**/build"
107
- ]
107
+ ],
108
+ // 默认关闭。设为 true 自动读取项目根目录下的 .gitignore(不存在则跳过)
109
+ // 也可传入 string 指定其他 gitignore 文件路径
110
+ // gitignore: true
108
111
  })
109
112
  ```
110
113
 
package/dist/index.d.mts CHANGED
@@ -17,6 +17,7 @@ interface OptionsConfig extends OptionsComponentExts {
17
17
  react?: boolean;
18
18
  oxfmt?: boolean | OptionsOxfmt;
19
19
  ignores?: string[];
20
+ gitignore?: boolean | string;
20
21
  overrides?: OverridesConfigs;
21
22
  }
22
23
  interface OptionsComponentExts {
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  import { isPackageExists } from "local-pkg";
2
+ import { existsSync } from "node:fs";
3
+ import { isAbsolute, resolve } from "node:path";
4
+ import { includeIgnoreFile } from "@eslint/compat";
2
5
  import importXPlugin, { flatConfigs } from "eslint-plugin-import-x";
3
6
  import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
4
7
  import eslintJS from "@eslint/js";
@@ -57,10 +60,18 @@ const GLOBS_EXCLUDES = [
57
60
  //#endregion
58
61
  //#region src/configs/ignores.ts
59
62
  function ignores(options) {
60
- return [{
63
+ const { gitignore = false } = options ?? {};
64
+ const configs = [{
61
65
  name: "zjutjh/ignores",
62
66
  ignores: [...GLOBS_EXCLUDES, ...options?.userIgnores ?? []]
63
67
  }];
68
+ if (gitignore !== false) {
69
+ const path = gitignore === true ? ".gitignore" : gitignore;
70
+ const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);
71
+ if (existsSync(absolute)) configs.push(includeIgnoreFile(absolute, "zjutjh/gitignore"));
72
+ else if (gitignore !== true) throw new Error(`gitignore file not found: ${absolute}`);
73
+ }
74
+ return configs;
64
75
  }
65
76
  //#endregion
66
77
  //#region src/configs/imports.ts
@@ -435,9 +446,12 @@ async function vue(options) {
435
446
  //#endregion
436
447
  //#region src/factory.ts
437
448
  async function zjutjh(options = {}, ...userConfigs) {
438
- const { componentExts = [], vue: enableVue = isPackageExists("vue"), ts: enableTs = isPackageExists("typescript"), taro: enableTaro = isPackageExists("@tarojs/taro"), jsx: enableJSX = isPackageExists("react"), react: enableReact = isPackageExists("react"), ignores: userIgnores, oxfmt: enableOxfmt = false } = options;
449
+ const { componentExts = [], vue: enableVue = isPackageExists("vue"), ts: enableTs = isPackageExists("typescript"), taro: enableTaro = isPackageExists("@tarojs/taro"), jsx: enableJSX = isPackageExists("react"), react: enableReact = isPackageExists("react"), ignores: userIgnores, gitignore: enableGitignore = false, oxfmt: enableOxfmt = false } = options;
439
450
  const configs = [];
440
- configs.push(ignores({ userIgnores }), javascript(), imports(), stylistic({ overrides: getOverrides(options, "stylistic") }), misc());
451
+ configs.push(ignores({
452
+ userIgnores,
453
+ gitignore: enableGitignore
454
+ }), javascript(), imports(), stylistic({ overrides: getOverrides(options, "stylistic") }), misc());
441
455
  if (enableVue) componentExts.push("vue");
442
456
  const typescriptOptions = resolveSubOptions(options, "ts");
443
457
  if (enableTs) configs.push(await typescript({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zjutjh/eslint-config",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.0",
4
+ "version": "2.0.0-beta.1",
5
5
  "license": "ISC",
6
6
  "author": "zjutjh",
7
7
  "description": "ESLint config used by zjutjh",
@@ -71,6 +71,7 @@
71
71
  "dependencies": {
72
72
  "@antfu/install-pkg": "^1.1.0",
73
73
  "@clack/prompts": "^1.2.0",
74
+ "@eslint/compat": "^2.0.5",
74
75
  "@eslint/js": "^10.0.1",
75
76
  "@stylistic/eslint-plugin": "^5.10.0",
76
77
  "eslint-plugin-import-x": "^4.16.2",