@infra-x/create-eslint-config 0.1.1 → 0.1.3
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 +14 -0
- package/dist/template/README.md +2 -55
- package/dist/template/src/configs/tailwind.ts +4 -2
- package/dist/template/src/configs/typescript.ts +4 -2
- package/dist/template/src/index.ts +29 -1
- package/dist/template/src/types.ts +2 -0
- package/dist/template/tsconfig.config.json +4 -0
- package/dist/template/tsconfig.json +1 -1
- package/package.json +4 -3
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)。
|
package/dist/template/README.md
CHANGED
|
@@ -1,56 +1,3 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @infra-x/eslint-config
|
|
2
2
|
|
|
3
|
-
|
|
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)。
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { defineConfig } from 'eslint/config'
|
|
5
5
|
import eslintPluginBetterTailwindcss from 'eslint-plugin-better-tailwindcss'
|
|
6
6
|
|
|
7
|
+
import { GLOB_JSX } from '../utils'
|
|
8
|
+
|
|
7
9
|
import type { TailwindOptions } from '../types'
|
|
8
10
|
import type { Linter } from 'eslint'
|
|
9
11
|
|
|
@@ -11,11 +13,11 @@ import type { Linter } from 'eslint'
|
|
|
11
13
|
* Tailwind CSS 规则配置
|
|
12
14
|
*/
|
|
13
15
|
export function tailwind(options: TailwindOptions = {}): Linter.Config[] {
|
|
14
|
-
const { files, overrides = {}, entryPoint = 'src/global.css' } = options
|
|
16
|
+
const { files = [GLOB_JSX], overrides = {}, entryPoint = 'src/global.css' } = options
|
|
15
17
|
|
|
16
18
|
return defineConfig({
|
|
17
19
|
name: 'tailwind/rules',
|
|
18
|
-
files
|
|
20
|
+
files,
|
|
19
21
|
extends: [
|
|
20
22
|
eslintPluginBetterTailwindcss.configs.recommended,
|
|
21
23
|
],
|
|
@@ -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, overrides = {} } = options
|
|
16
|
+
const { files = [GLOB_TS], tsconfigRootDir, allowDefaultProject, defaultProject, overrides = {} } = options
|
|
17
17
|
|
|
18
18
|
return defineConfig({
|
|
19
19
|
name: 'typescript/rules',
|
|
@@ -25,7 +25,9 @@ export function typescript(options: TypeScriptOptions = {}): Linter.Config[] {
|
|
|
25
25
|
languageOptions: {
|
|
26
26
|
parser,
|
|
27
27
|
parserOptions: {
|
|
28
|
-
projectService:
|
|
28
|
+
projectService: allowDefaultProject
|
|
29
|
+
? { allowDefaultProject, defaultProject }
|
|
30
|
+
: true,
|
|
29
31
|
tsconfigRootDir: tsconfigRootDir ?? process.cwd(),
|
|
30
32
|
},
|
|
31
33
|
},
|
|
@@ -134,7 +134,15 @@ const CONFIG_REGISTRY: ConfigEntry[] = [
|
|
|
134
134
|
// 默认开启
|
|
135
135
|
{ key: 'ignores', fn: ignores, defaultOn: true },
|
|
136
136
|
{ key: 'javascript', fn: javascript, defaultOn: true },
|
|
137
|
-
{
|
|
137
|
+
{
|
|
138
|
+
key: 'typescript',
|
|
139
|
+
fn: typescript,
|
|
140
|
+
defaultOn: true,
|
|
141
|
+
inject: () => ({
|
|
142
|
+
allowDefaultProject: ['*.config.ts', '*.config.mts'],
|
|
143
|
+
defaultProject: 'tsconfig.config.json',
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
138
146
|
{ key: 'stylistic', fn: stylistic, defaultOn: true },
|
|
139
147
|
{ key: 'unicorn', fn: unicorn, defaultOn: true },
|
|
140
148
|
{ key: 'depend', fn: depend, defaultOn: true },
|
|
@@ -170,6 +178,26 @@ export function composeConfig(options: ComposeConfigOptions = {}): Linter.Config
|
|
|
170
178
|
configs.push(...fn({ ...injected, ...base }))
|
|
171
179
|
}
|
|
172
180
|
|
|
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
|
+
|
|
173
201
|
return configs
|
|
174
202
|
}
|
|
175
203
|
|
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
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "CLI to copy ESLint config source into a monorepo.",
|
|
6
6
|
"author": "infra-x",
|
|
7
7
|
"license": "MIT",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
|
-
"create-eslint-config": "./dist/index.mjs"
|
|
17
|
+
"create-eslint-config": "./dist/index.mjs",
|
|
18
|
+
"cec": "./dist/index.mjs"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"dist"
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build": "tsdown",
|
|
24
25
|
"dev": "tsdown --watch",
|
|
25
|
-
"typecheck": "tsc --noEmit",
|
|
26
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.config.json --noEmit",
|
|
26
27
|
"prepublishOnly": "pnpm run build"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|