@infra-x/create-eslint-config 0.1.4 → 0.2.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.
Files changed (31) hide show
  1. package/dist/index.mjs +8 -10
  2. package/dist/template/.turbo/turbo-build.log +13 -0
  3. package/dist/template/CHANGELOG.md +7 -0
  4. package/dist/template/README.md +95 -1
  5. package/dist/template/eslint.config.mts +1 -2
  6. package/dist/template/package.json +25 -13
  7. package/dist/template/src/configs/a11y.ts +2 -2
  8. package/dist/template/src/configs/better-tailwindcss.ts +3 -3
  9. package/dist/template/src/configs/boundaries.ts +1 -1
  10. package/dist/template/src/configs/depend.ts +3 -4
  11. package/dist/template/src/configs/global-ignores.ts +70 -0
  12. package/dist/template/src/configs/imports.ts +23 -22
  13. package/dist/template/src/configs/javascript.ts +1 -1
  14. package/dist/template/src/configs/jsdoc.ts +1 -1
  15. package/dist/template/src/configs/nextjs.ts +2 -2
  16. package/dist/template/src/configs/oxlint.ts +16 -0
  17. package/dist/template/src/configs/package-json.ts +1 -1
  18. package/dist/template/src/configs/react.ts +16 -7
  19. package/dist/template/src/configs/storybook.ts +1 -1
  20. package/dist/template/src/configs/stylistic.ts +1 -1
  21. package/dist/template/src/configs/typescript.ts +3 -11
  22. package/dist/template/src/configs/unicorn.ts +1 -1
  23. package/dist/template/src/configs/vitest.ts +3 -4
  24. package/dist/template/src/index.ts +59 -73
  25. package/dist/template/src/types.ts +44 -37
  26. package/dist/template/src/utils.ts +17 -17
  27. package/dist/template/tsconfig.json +1 -1
  28. package/package.json +16 -17
  29. package/README.md +0 -14
  30. package/dist/template/src/configs/ignores.ts +0 -78
  31. package/dist/template/src/configs/prettier.ts +0 -25
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @workspace/eslint-config
3
3
  *
4
- * 统一 ESLint 配置工具
4
+ * Composable ESLint configuration factory
5
5
  *
6
6
  * @example
7
7
  * ```typescript
@@ -12,27 +12,23 @@
12
12
  * react: true,
13
13
  * tailwind: true,
14
14
  * imports: { typescript: true },
15
- * prettier: true,
16
15
  * })
17
16
  * ```
18
17
  */
19
18
 
20
- import { defineConfig } from 'eslint/config'
21
- import { configs as tsConfigs, parser as tsParser } from 'typescript-eslint'
22
-
23
19
  import { a11y } from './configs/a11y'
24
20
  import { tailwind } from './configs/better-tailwindcss'
25
21
  import { boundaries } from './configs/boundaries'
26
22
  import { depend } from './configs/depend'
27
- import { ignores } from './configs/ignores'
23
+ import { ignores } from './configs/global-ignores'
28
24
  import { imports } from './configs/imports'
29
25
  import { javascript } from './configs/javascript'
30
26
  import { jsdoc } from './configs/jsdoc'
31
27
  import { nextjs } from './configs/nextjs'
32
28
  import { packageJson } from './configs/package-json'
33
- import { prettier } from './configs/prettier'
34
29
  import { react } from './configs/react'
35
30
  import { storybook } from './configs/storybook'
31
+ import { oxlintConfig } from './configs/oxlint'
36
32
  import { stylistic } from './configs/stylistic'
37
33
  import { typescript } from './configs/typescript'
38
34
  import { unicorn } from './configs/unicorn'
@@ -47,8 +43,8 @@ import type {
47
43
  JavaScriptOptions,
48
44
  JsdocOptions,
49
45
  NextjsOptions,
46
+ OxlintOptions,
50
47
  PackageJsonOptions,
51
- PrettierOptions,
52
48
  ReactOptions,
53
49
  StorybookOptions,
54
50
  StylisticOptions,
@@ -60,68 +56,72 @@ import type {
60
56
  import type { Linter } from 'eslint'
61
57
 
62
58
  // ============================================================================
63
- // 类型定义
59
+ // Type definitions
64
60
  // ============================================================================
65
61
 
66
62
  /**
67
- * composeConfig 配置选项
63
+ * Options for composeConfig
68
64
  *
69
- * 每个配置项支持:
70
- * - `true` - 使用默认选项
71
- * - `对象` - 传入自定义选项
72
- * - `false` - 关闭(默认开启的配置需要显式关闭)
73
- * - 不写 - 不启用(非默认开启的配置)
65
+ * Each config entry accepts:
66
+ * - `true` - enable with default options
67
+ * - `object` - enable with custom options
68
+ * - `false` - explicitly disable (required for configs that are on by default)
69
+ * - omitted - leave disabled (for configs that are off by default)
74
70
  */
75
71
  export interface ComposeConfigOptions {
76
- // 基础配置(默认开启)
77
- /** 忽略文件配置 @default true */
78
- ignores?: boolean | IgnoresOptions
79
- /** JavaScript 基础配置 @default true */
72
+ // Base configuration (enabled by default)
73
+ /** Ignore patterns configuration @default true */
74
+ globalIgnores?: boolean | IgnoresOptions
75
+ /** JavaScript base configuration @default true */
80
76
  javascript?: boolean | JavaScriptOptions
81
- /** TypeScript 配置 @default true */
77
+ /** TypeScript configuration @default true */
82
78
  typescript?: boolean | TypeScriptOptions
83
- /** 代码风格规则 @default true */
79
+ /** Code style rules @default true */
84
80
  stylistic?: boolean | StylisticOptions
85
- /** Unicorn 最佳实践 @default true */
81
+ /** Unicorn best practices @default true */
86
82
  unicorn?: boolean | UnicornOptions
87
- /** 依赖优化建议 @default true */
83
+ /** Dependency optimization suggestions @default true */
88
84
  depend?: boolean | DependOptions
89
- /** config 文件(*.config.ts)专属规则(不启用类型检查)@default true */
90
- configFiles?: boolean
91
-
92
- // 框架配置
93
- /** React 配置 */
85
+ // Framework configuration
86
+ /** React configuration */
94
87
  react?: boolean | ReactOptions
95
- /** Next.js 配置 */
88
+ /** Next.js configuration */
96
89
  nextjs?: boolean | NextjsOptions
97
- /** Tailwind CSS 配置 */
90
+ /** Tailwind CSS configuration */
98
91
  tailwind?: boolean | TailwindOptions
99
92
 
100
- // 工具配置
101
- /** Import 排序和规则 */
93
+ // Tooling configuration
94
+ /** Import ordering and rules */
102
95
  imports?: boolean | ImportsOptions
103
- /** Prettier 格式化 */
104
- prettier?: boolean | PrettierOptions
105
96
 
106
- // 质量配置
107
- /** 无障碍访问规则 */
97
+ // Quality configuration
98
+ /** Accessibility rules */
108
99
  a11y?: boolean | A11yOptions
109
- /** JSDoc 文档规则 */
100
+ /** JSDoc documentation rules */
110
101
  jsdoc?: boolean | JsdocOptions
111
- /** 模块边界规则 */
102
+ /** Module boundary rules */
112
103
  boundaries?: boolean | BoundariesOptions
113
- /** package.json 规则 */
104
+ /** package.json rules */
114
105
  packageJson?: boolean | PackageJsonOptions
115
106
 
116
- // 测试配置
117
- /** Vitest 测试规则 */
107
+ // Testing configuration
108
+ /** Vitest testing rules */
118
109
  vitest?: boolean | VitestOptions
119
- /** Storybook 规则 */
110
+ /** Storybook rules */
120
111
  storybook?: boolean | StorybookOptions
112
+
113
+ // Linter integration
114
+ /**
115
+ * Disable ESLint rules already covered by oxlint.
116
+ * Requires oxlint to be run separately.
117
+ * - `true` uses the `flat/recommended` preset
118
+ * - `{ configFile }` generates disabled rules from your oxlint config file
119
+ */
120
+ oxlint?: boolean | OxlintOptions
121
121
  }
122
122
 
123
123
  // ============================================================================
124
- // 主函数
124
+ // Core function
125
125
  // ============================================================================
126
126
 
127
127
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -131,13 +131,13 @@ type ConfigEntry = {
131
131
  key: keyof ComposeConfigOptions
132
132
  fn: ConfigFn
133
133
  defaultOn?: boolean
134
- /** 根据全局 options 派生注入值,优先级低于用户配置 */
134
+ /** Values derived from global options to inject; overridden by explicit user config */
135
135
  inject?: (options: ComposeConfigOptions) => Record<string, unknown>
136
136
  }
137
137
 
138
138
  const CONFIG_REGISTRY: ConfigEntry[] = [
139
- // 默认开启
140
- { key: 'ignores', fn: ignores, defaultOn: true },
139
+ // Enabled by default
140
+ { key: 'globalIgnores', fn: ignores, defaultOn: true },
141
141
  { key: 'javascript', fn: javascript, defaultOn: true },
142
142
  {
143
143
  key: 'typescript',
@@ -147,11 +147,16 @@ const CONFIG_REGISTRY: ConfigEntry[] = [
147
147
  { key: 'stylistic', fn: stylistic, defaultOn: true },
148
148
  { key: 'unicorn', fn: unicorn, defaultOn: true },
149
149
  { key: 'depend', fn: depend, defaultOn: true },
150
- // 按需开启(顺序固定,prettier 最后)
150
+ // Opt-in (order is fixed; prettier must come last)
151
151
  {
152
152
  key: 'imports',
153
153
  fn: imports,
154
- inject: (options) => ({ typescript: options.typescript !== false }),
154
+ inject: (options) => ({
155
+ typescript: options.typescript !== false,
156
+ tsconfigRootDir: typeof options.typescript === 'object'
157
+ ? options.typescript.tsconfigRootDir
158
+ : undefined,
159
+ }),
155
160
  },
156
161
  { key: 'react', fn: react },
157
162
  { key: 'nextjs', fn: nextjs },
@@ -162,10 +167,10 @@ const CONFIG_REGISTRY: ConfigEntry[] = [
162
167
  { key: 'packageJson', fn: packageJson },
163
168
  { key: 'vitest', fn: vitest },
164
169
  { key: 'storybook', fn: storybook },
165
- { key: 'prettier', fn: prettier },
170
+ { key: 'oxlint', fn: oxlintConfig },
166
171
  ]
167
172
 
168
- /** 组合 ESLint 配置,内部按正确顺序组合 */
173
+ /** Composes ESLint configs in the correct internal order */
169
174
  export function composeConfig(options: ComposeConfigOptions = {}): Linter.Config[] {
170
175
  const configs: Linter.Config[] = []
171
176
 
@@ -179,30 +184,11 @@ export function composeConfig(options: ComposeConfigOptions = {}): Linter.Config
179
184
  configs.push(...fn({ ...injected, ...base }))
180
185
  }
181
186
 
182
- return options.configFiles === false
183
- ? configs
184
- : defineConfig([
185
- {
186
- ignores: ['*.config.ts', '*.config.mts'],
187
- extends: [configs],
188
- },
189
- {
190
- name: 'typescript/config-files',
191
- files: ['*.config.ts', '*.config.mts'],
192
- extends: [tsConfigs.recommended],
193
- languageOptions: {
194
- parser: tsParser,
195
- parserOptions: {
196
- project: false,
197
- tsconfigRootDir: (typeof options.typescript === 'object' ? options.typescript.tsconfigRootDir : undefined) ?? process.cwd(),
198
- },
199
- },
200
- },
201
- ])
187
+ return configs
202
188
  }
203
189
 
204
190
  // ============================================================================
205
- // 类型导出
191
+ // Type exports
206
192
  // ============================================================================
207
193
 
208
194
  export type {
@@ -214,8 +200,8 @@ export type {
214
200
  JavaScriptOptions,
215
201
  JsdocOptions,
216
202
  NextjsOptions,
203
+ OxlintOptions,
217
204
  PackageJsonOptions,
218
- PrettierOptions,
219
205
  ReactOptions,
220
206
  StorybookOptions,
221
207
  StylisticOptions,
@@ -226,7 +212,7 @@ export type {
226
212
  } from './types'
227
213
 
228
214
  // ============================================================================
229
- // 常量导出
215
+ // Constant exports
230
216
  // ============================================================================
231
217
 
232
218
  export { GLOB_SRC, GLOB_JS, GLOB_TS, GLOB_JSX, GLOB_TESTS, GLOB_JSON, GLOB_MARKDOWN } from './utils'
@@ -1,38 +1,27 @@
1
1
  import type { RulesConfig } from '@eslint/core'
2
2
 
3
3
  /**
4
- * 规则覆盖选项
4
+ * Rule override options
5
5
  */
6
6
  export interface OptionsOverrides {
7
7
  /**
8
- * 自定义规则覆盖
8
+ * Custom rule overrides
9
9
  */
10
10
  overrides?: Partial<RulesConfig>
11
11
  }
12
12
 
13
13
  /**
14
- * 风格化选项
15
- */
16
- export interface OptionsStylistic {
17
- /**
18
- * 是否启用风格化规则
19
- * @default true
20
- */
21
- stylistic?: boolean
22
- }
23
-
24
- /**
25
- * 文件匹配选项
14
+ * File matching options
26
15
  */
27
16
  export interface OptionsFiles {
28
17
  /**
29
- * 自定义文件匹配模式
18
+ * Custom file glob patterns
30
19
  */
31
20
  files?: string[]
32
21
  }
33
22
 
34
23
  /**
35
- * TypeScript 配置选项
24
+ * TypeScript configuration options
36
25
  */
37
26
  export interface OptionsTypeScript {
38
27
  tsconfigRootDir?: string
@@ -41,18 +30,18 @@ export interface OptionsTypeScript {
41
30
  }
42
31
 
43
32
  /**
44
- * Tailwind CSS 配置选项
33
+ * Tailwind CSS configuration options
45
34
  */
46
35
  export interface OptionsTailwind {
47
36
  /**
48
- * Tailwind CSS 入口文件路径
37
+ * Path to the Tailwind CSS entry file
49
38
  * @default 'src/global.css'
50
39
  */
51
40
  entryPoint?: string
52
41
  }
53
42
 
54
43
  // ============================================================================
55
- // Config Options 类型
44
+ // Config option types
56
45
  // ============================================================================
57
46
 
58
47
  export type A11yOptions = OptionsFiles & OptionsOverrides
@@ -74,48 +63,53 @@ export interface BoundariesOptions extends OptionsFiles, OptionsOverrides {
74
63
 
75
64
  export interface DependOptions extends OptionsOverrides {
76
65
  /**
77
- * 预设列表
66
+ * Preset list
78
67
  *
79
- * - `native`: 检测可用原生 JavaScript API 替代的包( `is-nan` → `Number.isNaN()`)
80
- * - `microutilities`: 检测微型工具库(一行代码可实现的包)
81
- * - `preferred`: 推荐更轻量、维护更好的替代方案
68
+ * - `native`: Flags packages replaceable with native JavaScript APIs (e.g. `is-nan` → `Number.isNaN()`)
69
+ * - `microutilities`: Flags micro-utility packages implementable in a single line
70
+ * - `preferred`: Recommends lighter-weight, better-maintained alternatives
82
71
  *
83
72
  * @default ['native', 'microutilities', 'preferred']
84
73
  */
85
74
  presets?: ('native' | 'microutilities' | 'preferred')[]
86
75
 
87
76
  /**
88
- * 自定义禁用的模块列表
77
+ * Additional modules to ban
89
78
  * @default []
90
79
  */
91
80
  modules?: string[]
92
81
 
93
82
  /**
94
- * 允许使用的模块列表(即使在 presets 中)
83
+ * Modules to allow even if matched by a preset
95
84
  * @default []
96
85
  */
97
86
  allowed?: string[]
98
87
  }
99
88
 
100
89
  export interface IgnoresOptions {
101
- /** 用户自定义忽略规则,传入 false 禁用默认规则 */
102
- ignores?: string[] | false
103
- /** gitignore 文件路径或启用标志 */
104
- gitignore?: string | boolean
90
+ /** Additional ignore patterns to merge with DEFAULT_IGNORES; pass false to disable all global ignores */
91
+ ignores?: string | string[] | false
92
+ /** Whether to parse .gitignore and merge into global ignores @default true */
93
+ gitignore?: boolean
105
94
  }
106
95
 
107
- export interface ImportsOptions extends OptionsOverrides, OptionsStylistic {
96
+ export interface ImportsOptions extends OptionsOverrides {
108
97
  /**
109
- * 是否启用 TypeScript 支持
110
- * 当全局 typescript 开启时,由 composeConfig 自动注入为 true
111
- * @default false(独立调用时)/ 跟随全局 typescript 选项(通过 composeConfig
98
+ * Whether to enable TypeScript support
99
+ * Automatically injected as true by composeConfig when the global typescript option is enabled
100
+ * @default false (standalone) / follows global typescript option (via composeConfig)
112
101
  */
113
102
  typescript?: boolean
114
103
  /**
115
- * 禁止使用 ../ 父级相对导入
104
+ * Disallow parent-relative imports (paths starting with ../)
116
105
  * @default false
117
106
  */
118
107
  noRelativeParentImports?: boolean
108
+ /**
109
+ * Root directory for tsconfig.json lookup; restricts resolver scope in monorepo to avoid cross-app漫游
110
+ * Automatically injected by composeConfig from the global typescript.tsconfigRootDir option
111
+ */
112
+ tsconfigRootDir?: string
119
113
  }
120
114
 
121
115
  export type JavaScriptOptions = OptionsFiles & OptionsOverrides
@@ -135,9 +129,13 @@ export interface PackageJsonOptions extends OptionsOverrides {
135
129
  enforceForPrivate?: boolean
136
130
  }
137
131
 
138
- export type PrettierOptions = OptionsOverrides
139
-
140
- export type ReactOptions = OptionsFiles & OptionsOverrides
132
+ export interface ReactOptions extends OptionsFiles, OptionsOverrides {
133
+ /**
134
+ * Whether to enable react-refresh plugin (for Vite projects).
135
+ * @default false
136
+ */
137
+ vite?: boolean
138
+ }
141
139
 
142
140
  export type StorybookOptions = OptionsOverrides
143
141
 
@@ -152,3 +150,12 @@ export type UnicornOptions = OptionsFiles & OptionsOverrides
152
150
  export type VitestOptions = OptionsFiles & OptionsOverrides & {
153
151
  isInEditor?: boolean
154
152
  }
153
+
154
+ export interface OxlintOptions {
155
+ /**
156
+ * Path to oxlint config file for dynamic rule generation.
157
+ * When provided, uses `buildFromOxlintConfigFile()` instead of the `flat/recommended` preset.
158
+ * @example './.oxlintrc.json'
159
+ */
160
+ configFile?: string
161
+ }
@@ -1,13 +1,13 @@
1
1
  /**
2
- * 工具函数和常量
2
+ * Utility functions and constants
3
3
  */
4
4
 
5
5
  // ============================================================================
6
- // 环境检测
6
+ // Environment detection
7
7
  // ============================================================================
8
8
 
9
9
  /**
10
- * 检测是否在 Git Hooks lint-staged 中运行
10
+ * Detects whether running inside Git Hooks or lint-staged
11
11
  */
12
12
  function isInGitHooksOrLintStaged(): boolean {
13
13
  const envVars = [
@@ -18,14 +18,14 @@ function isInGitHooksOrLintStaged(): boolean {
18
18
  }
19
19
 
20
20
  /**
21
- * 检测是否在编辑器环境中运行
21
+ * Detects whether running in an editor environment
22
22
  *
23
- * 在以下情况返回 false
24
- * - CI 环境
23
+ * Returns false when:
24
+ * - CI environment
25
25
  * - Git Hooks
26
26
  * - lint-staged
27
27
  *
28
- * 在以下情况返回 true
28
+ * Returns true when:
29
29
  * - VSCode
30
30
  * - JetBrains IDE
31
31
  * - Vim / Neovim
@@ -46,35 +46,35 @@ export function isInEditorEnv(): boolean {
46
46
  }
47
47
 
48
48
  // ============================================================================
49
- // 文件匹配模式 (Globs)
49
+ // File matching patterns (Globs)
50
50
  // ============================================================================
51
51
 
52
52
  /**
53
- * ESLint 文件匹配模式常量
53
+ * ESLint file glob pattern constants
54
54
  *
55
- * 统一的 glob 模式,确保所有配置使用一致的文件匹配规则
55
+ * Unified glob patterns to ensure consistent file matching across all configurations
56
56
  */
57
57
 
58
- /** 所有 JS/TS 源文件(完整覆盖 ESM/CJS */
58
+ /** All JS/TS source files (full ESM/CJS coverage) */
59
59
  export const GLOB_SRC = '**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}'
60
60
 
61
- /** JavaScript 文件 */
61
+ /** JavaScript files only */
62
62
  export const GLOB_JS = '**/*.{js,mjs,cjs,jsx}'
63
63
 
64
- /** TypeScript 文件 */
64
+ /** TypeScript files only */
65
65
  export const GLOB_TS = '**/*.{ts,mts,cts,tsx}'
66
66
 
67
- /** JSX/TSX 文件(React 相关) */
67
+ /** JSX/TSX files (React-related) */
68
68
  export const GLOB_JSX = '**/*.{jsx,tsx}'
69
69
 
70
- /** 测试文件 */
70
+ /** Test files */
71
71
  export const GLOB_TESTS: string[] = [
72
72
  '**/*.{test,spec}.{js,mjs,cjs,jsx,ts,mts,cts,tsx}',
73
73
  '**/__tests__/**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}',
74
74
  ]
75
75
 
76
- /** JSON 文件 */
76
+ /** JSON files */
77
77
  export const GLOB_JSON = '**/*.json'
78
78
 
79
- /** Markdown 文件 */
79
+ /** Markdown files */
80
80
  export const GLOB_MARKDOWN = '**/*.md'
@@ -3,6 +3,6 @@
3
3
  "include": ["src", "*.config.ts", "*.config.mts"],
4
4
  "compilerOptions": {
5
5
  "types": ["node"],
6
- "isolatedDeclarations": false // 减少维护,在那时关闭吧,不然 config 需要繁琐的配置
6
+ "isolatedDeclarations": false // Disabled to reduce maintenance overhead; enabling it would require verbose type annotations across configs
7
7
  }
8
8
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infra-x/create-eslint-config",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.2.1",
5
5
  "description": "CLI to copy ESLint config source into a monorepo.",
6
6
  "author": "infra-x",
7
7
  "license": "MIT",
@@ -20,27 +20,26 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "scripts": {
24
- "build": "tsdown",
25
- "dev": "tsdown --watch",
26
- "typecheck": "tsc --noEmit",
27
- "prepublishOnly": "pnpm run build"
28
- },
29
23
  "dependencies": {
30
- "@clack/prompts": "^0.11.0"
24
+ "@clack/prompts": "^1.0.1"
31
25
  },
32
26
  "devDependencies": {
33
- "@infra-x/eslint-config": "workspace:*",
34
- "@infra-x/typescript-config": "workspace:*",
35
- "@types/node": "^25.3.1",
36
- "eslint": "^9.39.3",
37
- "tsdown": "^0.18.4",
38
- "typescript": "^5.9.3"
27
+ "@types/node": "^25.3.3",
28
+ "bumpp": "^10.4.1",
29
+ "eslint": "^10.0.2",
30
+ "tsdown": "^0.21.0",
31
+ "typescript": "^5.9.3",
32
+ "@infra-x/typescript-config": "0.1.6",
33
+ "@infra-x/eslint-config": "0.1.6"
39
34
  },
40
- "main": "./dist/index.mjs",
41
- "module": "./dist/index.mjs",
42
35
  "exports": {
43
36
  ".": "./dist/index.mjs",
44
37
  "./package.json": "./package.json"
38
+ },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "dev": "tsdown --watch",
42
+ "typecheck": "tsc --noEmit",
43
+ "release": "bumpp"
45
44
  }
46
- }
45
+ }
package/README.md DELETED
@@ -1,14 +0,0 @@
1
- # @infra-x/create-eslint-config
2
-
3
- CLI 工具,将完整的 ESLint 配置模板复制到 monorepo 的 `eslint-config/` 目录。
4
-
5
- ## 使用
6
-
7
- ```bash
8
- pnpm dlx @infra-x/create-eslint-config
9
- ```
10
-
11
- 在 monorepo 根目录执行,会将 `eslint-config/` 目录(含规则定义和 `composeConfig` 工厂函数)
12
- 复制到当前工作目录。如果目标路径存在冲突文件,会提示确认是否覆盖。
13
-
14
- 完整集成说明见[根目录 README](../../README.md)。
@@ -1,78 +0,0 @@
1
- /**
2
- * ESLint 忽略文件配置,支持默认忽略规则和 .gitignore 导入
3
- */
4
- import { existsSync } from 'node:fs'
5
- import path from 'node:path'
6
-
7
- import { includeIgnoreFile } from '@eslint/compat'
8
-
9
- import type { IgnoresOptions } from '../types'
10
- import type { Linter } from 'eslint'
11
-
12
- /**
13
- * 默认忽略的文件和目录
14
- */
15
- export const DEFAULT_IGNORES: string[] = [
16
- // 依赖目录
17
- '**/node_modules/**',
18
- '**/.pnp.*',
19
-
20
- // 构建产物
21
- '**/dist/**',
22
- '**/build/**',
23
- '**/out/**',
24
- '**/.next/**',
25
-
26
- // 缓存目录
27
- '**/.cache/**',
28
- '**/.turbo/**',
29
- '**/.eslintcache',
30
-
31
- // 版本控制
32
- '**/.git/**',
33
- '**/.svn/**',
34
- '**/.hg/**',
35
- '**/public/**',
36
-
37
- // 类型文件
38
- '**/*.d.ts',
39
- ]
40
-
41
- export function ignores(options: IgnoresOptions = {}): Linter.Config[] {
42
- const { ignores: userIgnores, gitignore: gitignorePath } = options
43
- const configs: Linter.Config[] = []
44
-
45
- if (gitignorePath !== false) {
46
- try {
47
- const gitignoreFile
48
- = typeof gitignorePath === 'string'
49
- ? path.resolve(gitignorePath)
50
- : path.resolve(process.cwd(), '.gitignore')
51
-
52
- if (existsSync(gitignoreFile)) {
53
- configs.push(includeIgnoreFile(gitignoreFile))
54
- }
55
- } catch {
56
- //
57
- }
58
- }
59
-
60
- const finalIgnores
61
- = userIgnores === false
62
- ? []
63
- : (userIgnores
64
- ? [...DEFAULT_IGNORES, ...userIgnores]
65
- : DEFAULT_IGNORES)
66
-
67
- if (finalIgnores.length > 0) {
68
- configs.push({
69
- name: 'defaults',
70
- ignores: finalIgnores,
71
- })
72
- }
73
-
74
- return configs.map((config) => ({
75
- ...config,
76
- name: `ignores/globals/${config.name}`,
77
- }))
78
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Prettier 代码格式化配置,使用官方推荐规则集
3
- */
4
- import { defineConfig } from 'eslint/config'
5
- import prettierConfig from 'eslint-plugin-prettier/recommended'
6
-
7
- import { GLOB_SRC } from '../utils'
8
-
9
- import type { PrettierOptions } from '../types'
10
- import type { Linter } from 'eslint'
11
-
12
- export function prettier(options: PrettierOptions = {}): Linter.Config[] {
13
- const { overrides = {} } = options
14
-
15
- const files = [GLOB_SRC]
16
-
17
- return defineConfig([
18
- {
19
- name: 'prettier/rules',
20
- files,
21
- extends: [prettierConfig],
22
- rules: overrides,
23
- },
24
- ])
25
- }