@infra-x/create-eslint-config 0.1.2 → 0.1.4

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 ADDED
@@ -0,0 +1,14 @@
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,56 +1,3 @@
1
- # @workspace/eslint-config
1
+ # @infra-x/eslint-config
2
2
 
3
- 统一基础设施配置工具 - 集成 ESLint、Prettier、TypeScript、EditorConfig
4
-
5
- ## 安装
6
-
7
- ```bash
8
- pnpm add -D @workspace/eslint-config eslint prettier typescript
9
- ```
10
-
11
- ## 使用
12
-
13
- ```typescript
14
- // eslint.config.mts
15
- import { composeConfig } from '@workspace/eslint-config'
16
-
17
- export default composeConfig({
18
- typescript: { tsconfigRootDir: import.meta.dirname },
19
- react: true,
20
- imports: { typescript: true },
21
- prettier: true,
22
- })
23
- ```
24
-
25
- ## 配置项
26
-
27
- ### 默认开启
28
-
29
- - `ignores` - 忽略文件配置
30
- - `javascript` - JavaScript 基础规则
31
- - `typescript` - TypeScript 规则
32
- - `stylistic` - 代码风格规则
33
- - `unicorn` - 最佳实践
34
- - `depend` - 依赖优化建议
35
-
36
- ### 可选配置
37
-
38
- - `react` - React 规则
39
- - `nextjs` - Next.js 规则
40
- - `imports` - Import 排序和规则
41
- - `prettier` - Prettier 格式化
42
- - `a11y` - 无障碍访问规则
43
- - `jsdoc` - JSDoc 文档规则
44
- - `boundaries` - 模块边界规则
45
- - `packageJson` - package.json 规则
46
- - `vitest` - Vitest 测试规则
47
- - `storybook` - Storybook 规则
48
-
49
- 每个配置项支持:
50
- - `true` - 使用默认配置
51
- - `{ ...options }` - 自定义配置
52
- - `false` - 禁用(仅限默认开启的配置)
53
-
54
- ## License
55
-
56
- PROPRIETARY
3
+ 共享 ESLint flat config 配置工厂。完整使用说明见[根目录 README](../../README.md)。
@@ -29,16 +29,15 @@
29
29
  "vitest": "^4.0.18"
30
30
  },
31
31
  "dependencies": {
32
- "@eslint-react/eslint-plugin": "^2.11.0",
32
+ "@eslint-react/eslint-plugin": "^2.13.0",
33
33
  "@eslint/compat": "1.4.1",
34
34
  "@eslint/core": "0.17.0",
35
- "@eslint/js": "^9.39.2",
35
+ "@eslint/js": "^9.39.3",
36
36
  "@next/eslint-plugin-next": "^16.1.6",
37
- "@stylistic/eslint-plugin": "^5.7.1",
38
- "@vitest/eslint-plugin": "^1.6.6",
39
- "eslint-config-prettier": "^10.1.8",
37
+ "@stylistic/eslint-plugin": "^5.9.0",
38
+ "@vitest/eslint-plugin": "^1.6.9",
40
39
  "eslint-import-resolver-typescript": "^4.4.4",
41
- "eslint-plugin-better-tailwindcss": "^4.1.1",
40
+ "eslint-plugin-better-tailwindcss": "^4.3.1",
42
41
  "eslint-plugin-boundaries": "^5.4.0",
43
42
  "eslint-plugin-depend": "^1.4.0",
44
43
  "eslint-plugin-import-x": "4.16.1",
@@ -48,9 +47,9 @@
48
47
  "eslint-plugin-prettier": "^5.5.5",
49
48
  "eslint-plugin-react-hooks": "^7.0.1",
50
49
  "eslint-plugin-react-refresh": "^0.4.26",
51
- "eslint-plugin-storybook": "^10.2.7",
50
+ "eslint-plugin-storybook": "^10.2.12",
52
51
  "eslint-plugin-unicorn": "^57.0.0",
53
- "typescript-eslint": "^8.54.0"
52
+ "typescript-eslint": "^8.56.1"
54
53
  },
55
54
  "peerDependencies": {
56
55
  "eslint": "^9.39.2",
@@ -13,7 +13,7 @@ import type { Linter } from 'eslint'
13
13
  * TypeScript 规则配置
14
14
  */
15
15
  export function typescript(options: TypeScriptOptions = {}): Linter.Config[] {
16
- const { files = [GLOB_TS], tsconfigRootDir, allowDefaultProject, defaultProject, overrides = {} } = options
16
+ const { files = [GLOB_TS], tsconfigRootDir, overrides = {} } = options
17
17
 
18
18
  return defineConfig({
19
19
  name: 'typescript/rules',
@@ -25,9 +25,7 @@ export function typescript(options: TypeScriptOptions = {}): Linter.Config[] {
25
25
  languageOptions: {
26
26
  parser,
27
27
  parserOptions: {
28
- projectService: allowDefaultProject
29
- ? { allowDefaultProject, defaultProject }
30
- : true,
28
+ projectService: true,
31
29
  tsconfigRootDir: tsconfigRootDir ?? process.cwd(),
32
30
  },
33
31
  },
@@ -17,7 +17,11 @@
17
17
  * ```
18
18
  */
19
19
 
20
+ import { defineConfig } from 'eslint/config'
21
+ import { configs as tsConfigs, parser as tsParser } from 'typescript-eslint'
22
+
20
23
  import { a11y } from './configs/a11y'
24
+ import { tailwind } from './configs/better-tailwindcss'
21
25
  import { boundaries } from './configs/boundaries'
22
26
  import { depend } from './configs/depend'
23
27
  import { ignores } from './configs/ignores'
@@ -30,7 +34,6 @@ import { prettier } from './configs/prettier'
30
34
  import { react } from './configs/react'
31
35
  import { storybook } from './configs/storybook'
32
36
  import { stylistic } from './configs/stylistic'
33
- import { tailwind } from './configs/tailwind'
34
37
  import { typescript } from './configs/typescript'
35
38
  import { unicorn } from './configs/unicorn'
36
39
  import { vitest } from './configs/vitest'
@@ -83,6 +86,8 @@ export interface ComposeConfigOptions {
83
86
  unicorn?: boolean | UnicornOptions
84
87
  /** 依赖优化建议 @default true */
85
88
  depend?: boolean | DependOptions
89
+ /** config 文件(*.config.ts)专属规则(不启用类型检查)@default true */
90
+ configFiles?: boolean
86
91
 
87
92
  // 框架配置
88
93
  /** React 配置 */
@@ -138,10 +143,6 @@ const CONFIG_REGISTRY: ConfigEntry[] = [
138
143
  key: 'typescript',
139
144
  fn: typescript,
140
145
  defaultOn: true,
141
- inject: () => ({
142
- allowDefaultProject: ['*.config.ts', '*.config.mts'],
143
- defaultProject: 'tsconfig.config.json',
144
- }),
145
146
  },
146
147
  { key: 'stylistic', fn: stylistic, defaultOn: true },
147
148
  { key: 'unicorn', fn: unicorn, defaultOn: true },
@@ -178,27 +179,26 @@ export function composeConfig(options: ComposeConfigOptions = {}): Linter.Config
178
179
  configs.push(...fn({ ...injected, ...base }))
179
180
  }
180
181
 
181
- // allowDefaultProject 文件附加宽松规则覆盖(内置默认值 + 用户覆盖)
182
- const tsEntry = CONFIG_REGISTRY.find((e) => e.key === 'typescript')
183
- const tsInjected = tsEntry?.inject ? tsEntry.inject(options) : {}
184
- const tsBase = typeof options.typescript === 'object' ? options.typescript : {}
185
- const tsOpts = { ...tsInjected, ...tsBase } as TypeScriptOptions
186
- if (options.typescript !== false && tsOpts.allowDefaultProject) {
187
- configs.push({
188
- name: 'typescript/config-files-relaxed',
189
- files: tsOpts.allowDefaultProject,
190
- rules: {
191
- '@typescript-eslint/no-unsafe-assignment': 'off',
192
- '@typescript-eslint/no-unsafe-member-access': 'off',
193
- '@typescript-eslint/no-unsafe-call': 'off',
194
- '@typescript-eslint/no-unsafe-return': 'off',
195
- '@typescript-eslint/no-unsafe-argument': 'off',
196
- 'unicorn/import-style': 'off',
197
- },
198
- })
199
- }
200
-
201
- return configs
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
+ ])
202
202
  }
203
203
 
204
204
  // ============================================================================
@@ -1,4 +1,8 @@
1
1
  {
2
2
  "extends": "@infra-x/typescript-config/tsconfig.library.json",
3
- "include": ["src"],
3
+ "include": ["src", "*.config.ts", "*.config.mts"],
4
+ "compilerOptions": {
5
+ "types": ["node"],
6
+ "isolatedDeclarations": false // 减少维护,在那时关闭吧,不然 config 需要繁琐的配置
7
+ }
4
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.2",
4
+ "version": "0.1.4",
5
5
  "description": "CLI to copy ESLint config source into a monorepo.",
6
6
  "author": "infra-x",
7
7
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "scripts": {
24
24
  "build": "tsdown",
25
25
  "dev": "tsdown --watch",
26
- "typecheck": "tsc --noEmit && tsc -p tsconfig.config.json --noEmit",
26
+ "typecheck": "tsc --noEmit",
27
27
  "prepublishOnly": "pnpm run build"
28
28
  },
29
29
  "dependencies": {
@@ -32,9 +32,9 @@
32
32
  "devDependencies": {
33
33
  "@infra-x/eslint-config": "workspace:*",
34
34
  "@infra-x/typescript-config": "workspace:*",
35
- "@types/node": "^25.0.3",
36
- "eslint": "^9.0.0",
37
- "tsdown": "^0.18.1",
35
+ "@types/node": "^25.3.1",
36
+ "eslint": "^9.39.3",
37
+ "tsdown": "^0.18.4",
38
38
  "typescript": "^5.9.3"
39
39
  },
40
40
  "main": "./dist/index.mjs",
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "@infra-x/typescript-config/tsconfig.config.json",
3
- "include": ["*.config.ts", "*.config.mts"]
4
- }