@ithinkdt/lint 4.0.4 → 4.0.5
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 +120 -25
- package/package.json +20 -20
- package/src/base.js +1 -1
package/README.md
CHANGED
|
@@ -1,53 +1,148 @@
|
|
|
1
1
|
# @ithinkdt/lint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
iThinkDT 项目的 ESLint、StyleLint 统一配置。
|
|
4
|
+
|
|
5
|
+
## 许可证
|
|
6
|
+
|
|
7
|
+
MIT
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i -D @ithinkdt/lint
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> 需要您自行安装 peer 依赖 `eslint@>=9`、`stylelint@>=16` 与 `typescript@>=5.8`。
|
|
16
|
+
|
|
17
|
+
## 介绍
|
|
4
18
|
|
|
5
19
|
- 集成 `@eslint/js` 的 `recommended` 推荐规则;
|
|
6
|
-
- 集成
|
|
7
|
-
- 集成
|
|
20
|
+
- 集成 `@eslint/json` 的 JSON 校验规则;
|
|
21
|
+
- 集成 `@eslint/markdown` 的 Markdown 代码块校验;
|
|
22
|
+
- 集成 `typescript-eslint` 的 `recommendedTypeChecked`,启用 Type Aware Rules 类型感知规则,检查 ts、vue 文件的类型错误;
|
|
23
|
+
- 集成 `eslint-plugin-vue` 的 `flat/recommended` 推荐规则;
|
|
8
24
|
- 集成 `eslint-plugin-unicorn` 的 `flat/recommended` 推荐规则;
|
|
9
|
-
- 集成 `@unocss/eslint-config` 的
|
|
25
|
+
- 集成 `@unocss/eslint-config` 的 flat 推荐规则(可选开启);
|
|
26
|
+
- 集成 `@stylistic/eslint-plugin` 代码风格规则(可选开启);
|
|
10
27
|
- 集成 `eslint-plugin-tsdoc` 规则;
|
|
11
|
-
- 集成 `eslint-plugin-import-x`
|
|
12
|
-
- 集成 `eslint-plugin-
|
|
13
|
-
-
|
|
28
|
+
- 集成 `eslint-plugin-import-x` 规则;
|
|
29
|
+
- 集成 `eslint-plugin-format` 格式化规则(CSS / SCSS / Less 等);
|
|
30
|
+
- 集成 `@eslint-community/eslint-plugin-eslint-comments` 规则;
|
|
31
|
+
- 集成 `eslint-plugin-playwright`、`@vitest/eslint-plugin`、`eslint-plugin-no-only-tests` 测试代码规则;
|
|
32
|
+
- 提供自定义规则 `@ithinkdt/no-relative-parent-imports`、`@ithinkdt/prefer-import-alias`;
|
|
33
|
+
- 支持 StyleLint 配置。
|
|
14
34
|
|
|
15
|
-
>
|
|
35
|
+
> 由于启用了类型感知规则,TypeScript 会在整个项目上执行类型检查,`lint-staged` 效果可能不佳。
|
|
16
36
|
|
|
17
37
|
## ESLint
|
|
18
38
|
|
|
19
|
-
安装 `npm i -D eslint`
|
|
39
|
+
安装 `npm i -D eslint`,在项目根目录创建 `eslint.config.js`:
|
|
20
40
|
|
|
21
41
|
```js
|
|
22
42
|
// eslint.config.js
|
|
23
|
-
|
|
24
43
|
import ithinkdt from '@ithinkdt/lint'
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
45
|
+
export default ithinkdt({
|
|
46
|
+
unocss: true,
|
|
47
|
+
stylistic: true,
|
|
48
|
+
tsconfigRootDir: import.meta.dirname,
|
|
49
|
+
}).append({
|
|
50
|
+
// 在此追加项目自定义配置
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 配置选项 `LintOptions`
|
|
55
|
+
|
|
56
|
+
| 选项 | 类型 | 默认值 | 说明 |
|
|
57
|
+
|------|------|--------|------|
|
|
58
|
+
| `unocss` | `boolean` | `false` | 是否启用 `@unocss/eslint-config/flat` |
|
|
59
|
+
| `stylistic` | `boolean \| StylisticCustomizeOptions` | `false` | 是否启用 `@stylistic/eslint-plugin` |
|
|
60
|
+
| `tsconfigRootDir` | `string` | — | TSConfig 根目录路径,用于类型感知规则的项目引用 |
|
|
61
|
+
|
|
62
|
+
当 `stylistic` 设为 `true` 时,使用以下默认风格:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
{
|
|
66
|
+
indent: 4, // 4 空格缩进
|
|
67
|
+
quotes: 'single', // 单引号
|
|
68
|
+
semi: false, // 不加分号
|
|
69
|
+
jsx: true, // 启用 JSX 支持
|
|
70
|
+
braceStyle: '1tbs', // One True Brace Style
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
你也可以传入自定义的 `StylisticCustomizeOptions` 对象来覆盖默认值。
|
|
75
|
+
|
|
76
|
+
### CI 环境
|
|
77
|
+
|
|
78
|
+
在 CI 环境中(`CI` 环境变量为真值),ESLint 会将所有规则设为 `error` 级别,确保 CI 流程严格阻断。
|
|
79
|
+
|
|
80
|
+
### 针对测试文件
|
|
81
|
+
|
|
82
|
+
测试文件(`**/tests/**`、`**/*.test.*`、`**/*.spec.*` 等)会自动应用以下配置:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import { playwright, vitest } from '@ithinkdt/lint'
|
|
86
|
+
|
|
87
|
+
// 使用方式
|
|
88
|
+
export default ithinkdt().append(
|
|
89
|
+
playwright.configs.recommended,
|
|
90
|
+
vitest.configs.recommended,
|
|
91
|
+
)
|
|
33
92
|
```
|
|
34
93
|
|
|
94
|
+
### 导出的工具
|
|
95
|
+
|
|
96
|
+
| 导出 | 说明 |
|
|
97
|
+
|------|------|
|
|
98
|
+
| `defaultEsFiles` | 默认匹配的 ES 文件 glob |
|
|
99
|
+
| `defaultTsFiles` | 默认匹配的 TS 文件 glob |
|
|
100
|
+
| `defaultJsFiles` | 默认匹配的 JS 文件 glob |
|
|
101
|
+
| `defaultTsWithVueFiles` | 默认匹配的 TS + Vue 文件 glob |
|
|
102
|
+
| `disableTypeChecked` | 禁用类型检查的配置(仅作用于 JS 文件) |
|
|
103
|
+
| `createTypeScriptImportResolver` | 创建 TypeScript 路径别名解析器,用于 `eslint-plugin-import-x` |
|
|
104
|
+
| `tsParser` | TypeScript 解析器(支持 `.vue` 额外扩展名) |
|
|
105
|
+
| `vueParser` | `vue-eslint-parser` |
|
|
106
|
+
| `playwright` | `eslint-plugin-playwright` |
|
|
107
|
+
| `vitest` | `@vitest/eslint-plugin` |
|
|
108
|
+
| `vue` | `eslint-plugin-vue` |
|
|
109
|
+
|
|
110
|
+
### 自定义规则
|
|
111
|
+
|
|
112
|
+
| 规则 | 级别 | 说明 |
|
|
113
|
+
|------|------|------|
|
|
114
|
+
| `@ithinkdt/no-relative-parent-imports` | `warn` | 禁止使用 `../` 相对父级导入 |
|
|
115
|
+
| `@ithinkdt/prefer-import-alias` | `warn` | 建议使用路径别名替代深层相对导入 |
|
|
116
|
+
|
|
35
117
|
## StyleLint
|
|
36
118
|
|
|
37
|
-
安装 `npm i -D stylelint`
|
|
119
|
+
安装 `npm i -D stylelint`,在项目根目录创建 `stylelint.config.js`:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// stylelint.config.js
|
|
123
|
+
import stylelintConfig from '@ithinkdt/lint/stylelint'
|
|
124
|
+
|
|
125
|
+
export default stylelintConfig({
|
|
126
|
+
// 在此追加或覆盖自定义配置
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 内置配置
|
|
131
|
+
|
|
132
|
+
- 继承 `stylelint-config-standard` 和 `stylelint-config-standard-vue`;
|
|
133
|
+
- 集成 `stylelint-order` 插件;
|
|
134
|
+
- 忽略 `*.js`、`*.ts`、`*.json`、`*.md`、`*.yaml` 等非样式文件;
|
|
135
|
+
- `selector-class-pattern`:强制 kebab-case 或 BEM 命名规范;
|
|
136
|
+
- `custom-property-empty-line-before`:CSS 自定义属性前不要求空行。
|
|
38
137
|
|
|
39
138
|
```js
|
|
40
139
|
// stylelint.config.js
|
|
41
140
|
|
|
42
141
|
import ithinkdt from '@ithinkdt/lint/stylelint'
|
|
43
142
|
|
|
44
|
-
|
|
45
|
-
* @type {import('stylelint').Config}
|
|
46
|
-
*/
|
|
47
|
-
export default {
|
|
48
|
-
extends: [ithinkdt],
|
|
143
|
+
export default ithinkdt({
|
|
49
144
|
rules: {
|
|
50
|
-
//
|
|
145
|
+
// 规则配置
|
|
51
146
|
},
|
|
52
|
-
}
|
|
147
|
+
})
|
|
53
148
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ithinkdt/lint",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "iThinkDT 项目的 ESLint、StyleLint 配置",
|
|
6
6
|
"keywords": [
|
|
@@ -32,36 +32,36 @@
|
|
|
32
32
|
},
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.
|
|
35
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.2",
|
|
36
36
|
"@eslint/js": "^10.0.1",
|
|
37
|
-
"@eslint/json": ">=
|
|
38
|
-
"@eslint/markdown": "^8.0.
|
|
37
|
+
"@eslint/json": ">=2.0.0",
|
|
38
|
+
"@eslint/markdown": "^8.0.2",
|
|
39
39
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
40
|
-
"@typescript-eslint/parser": "^8.
|
|
41
|
-
"@unocss/eslint-config": "^66.
|
|
42
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
43
|
-
"@vue/compiler-sfc": "^3.5.
|
|
44
|
-
"eslint-flat-config-utils": "^3.0
|
|
40
|
+
"@typescript-eslint/parser": "^8.60.1",
|
|
41
|
+
"@unocss/eslint-config": "^66.7.0",
|
|
42
|
+
"@vitest/eslint-plugin": "^1.6.19",
|
|
43
|
+
"@vue/compiler-sfc": "^3.5.35",
|
|
44
|
+
"eslint-flat-config-utils": "^3.2.0",
|
|
45
45
|
"eslint-import-resolver-custom-alias": "^1.3.2",
|
|
46
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
46
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
47
47
|
"eslint-merge-processors": "^2.0.0",
|
|
48
48
|
"eslint-plugin-format": "^2.0.1",
|
|
49
49
|
"eslint-plugin-import": "npm:eslint-plugin-import-x@^4.16.2",
|
|
50
|
-
"eslint-plugin-no-only-tests": "^3.
|
|
51
|
-
"eslint-plugin-playwright": "^2.10.
|
|
50
|
+
"eslint-plugin-no-only-tests": "^3.4.0",
|
|
51
|
+
"eslint-plugin-playwright": "^2.10.4",
|
|
52
52
|
"eslint-plugin-tsdoc": ">=0.5.2",
|
|
53
|
-
"eslint-plugin-unicorn": "^
|
|
54
|
-
"eslint-plugin-vue": "^10.
|
|
53
|
+
"eslint-plugin-unicorn": "^65.0.0",
|
|
54
|
+
"eslint-plugin-vue": "^10.9.2",
|
|
55
55
|
"eslint-processor-vue-blocks": "^2.0.0",
|
|
56
|
-
"globals": "^17.
|
|
56
|
+
"globals": "^17.6.0",
|
|
57
57
|
"globby": "^16.2.0",
|
|
58
58
|
"is-glob": "^4.0.3",
|
|
59
59
|
"postcss-html": "^1.8.1",
|
|
60
60
|
"stylelint-config-standard": "^40.0.0",
|
|
61
61
|
"stylelint-config-standard-vue": "^1.0.0",
|
|
62
62
|
"stylelint-order": "^8.1.1",
|
|
63
|
-
"typescript-eslint": "^8.
|
|
64
|
-
"vue-eslint-parser": "^10.4.
|
|
63
|
+
"typescript-eslint": "^8.60.1",
|
|
64
|
+
"vue-eslint-parser": "^10.4.1"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"eslint": ">=9",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"typescript": ">=5.8"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"eslint": "^10.1
|
|
73
|
-
"stylelint": "~17.
|
|
74
|
-
"typescript": "~
|
|
72
|
+
"eslint": "^10.4.1",
|
|
73
|
+
"stylelint": "~17.13.0",
|
|
74
|
+
"typescript": "~6.0.3"
|
|
75
75
|
},
|
|
76
76
|
"license": "MIT",
|
|
77
77
|
"scripts": {
|
package/src/base.js
CHANGED