eslint-plugin-light 1.0.3 → 1.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/CHANGELOG.md +73 -50
- package/LICENSE +9 -0
- package/README.md +77 -24
- package/lib/configs/base.js +16 -0
- package/lib/configs/essential.js +5 -0
- package/lib/configs/recommended.js +7 -0
- package/lib/index.js +15 -0
- package/lib/rules/json-parse-try-catch.js +58 -0
- package/lib/rules/no-complex-key.js +62 -0
- package/lib/rules/no-import-all-in-one-api.js +50 -0
- package/lib/rules/no-import-vant.js +70 -0
- package/lib/rules/no-plus-turn-number.js +47 -0
- package/lib/rules/no-this-tip-uid.js +33 -0
- package/lib/rules/valid-vue-comp-import.js +282 -0
- package/package.json +19 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,158 +1,181 @@
|
|
|
1
|
-
##
|
|
1
|
+
## <small>1.0.5 (2025-05-16)</small>
|
|
2
|
+
|
|
3
|
+
* feat(eslint-plugin-light): add no-import-all-in-one-api rule ([f92123e](https://github.com/novlan1/plugin-light/commits/f92123e))
|
|
4
|
+
* docs: update docs ([0721738](https://github.com/novlan1/plugin-light/commits/0721738))
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## <small>1.0.4 (2025-04-18)</small>
|
|
9
|
+
|
|
10
|
+
* chore: update license ([5ba3e91](https://github.com/novlan1/plugin-light/commits/5ba3e91))
|
|
11
|
+
* chore: update license ([7f6a9d9](https://github.com/novlan1/plugin-light/commits/7f6a9d9))
|
|
12
|
+
* docs: update docs ([f055bcd](https://github.com/novlan1/plugin-light/commits/f055bcd))
|
|
13
|
+
* docs: update docs ([ddced10](https://github.com/novlan1/plugin-light/commits/ddced10))
|
|
14
|
+
* docs: update docs ([761f6c4](https://github.com/novlan1/plugin-light/commits/761f6c4))
|
|
15
|
+
* docs: update docs ([bba000b](https://github.com/novlan1/plugin-light/commits/bba000b))
|
|
16
|
+
* docs: update docs ([34dde24](https://github.com/novlan1/plugin-light/commits/34dde24))
|
|
17
|
+
* refactor: use eslint import/order rule ([41afa85](https://github.com/novlan1/plugin-light/commits/41afa85))
|
|
18
|
+
* feat(eslint): add eslint-config-light ([b7af1f7](https://github.com/novlan1/plugin-light/commits/b7af1f7))
|
|
19
|
+
* feat(eslint): use json-parse-try-catch rule ([eca21da](https://github.com/novlan1/plugin-light/commits/eca21da))
|
|
20
|
+
* ci: update build script ([b7ad1e3](https://github.com/novlan1/plugin-light/commits/b7ad1e3))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [1.0.0](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.16...v1.0.0) (2023-07-12)
|
|
2
25
|
|
|
3
26
|
|
|
4
27
|
### ✨ Features | 新功能
|
|
5
28
|
|
|
6
|
-
* 添加规则不能使用this.tip_uid,但是没有开启 ([d913d2b](https://
|
|
7
|
-
* 新增no-import-vant ([c5b8722](https://
|
|
8
|
-
* 优化插件 ([505f17f](https://
|
|
29
|
+
* 添加规则不能使用this.tip_uid,但是没有开启 ([d913d2b](https://github.com/novlan1/eslint-plugin-light/commit/d913d2be33aaa44dbb6615f2d4ac98d4a7acebb0))
|
|
30
|
+
* 新增no-import-vant ([c5b8722](https://github.com/novlan1/eslint-plugin-light/commit/c5b87222db44111338cd1d9d4356695efa20cb93))
|
|
31
|
+
* 优化插件 ([505f17f](https://github.com/novlan1/eslint-plugin-light/commit/505f17f2191fdd6a9f32c67d64420ae115909af2))
|
|
9
32
|
|
|
10
33
|
|
|
11
34
|
### ♻️ Code Refactoring | 代码重构
|
|
12
35
|
|
|
13
|
-
* 插件重命名为light ([21c1dd9](https://
|
|
36
|
+
* 插件重命名为light ([21c1dd9](https://github.com/novlan1/eslint-plugin-light/commit/21c1dd93dcd5e31265767cf53121a718826abaad))
|
|
14
37
|
|
|
15
38
|
|
|
16
39
|
### ✏️ Documentation | 文档
|
|
17
40
|
|
|
18
|
-
* 文档更新 ([4f33c36](https://
|
|
19
|
-
* 优化readme ([f0183d0](https://
|
|
41
|
+
* 文档更新 ([4f33c36](https://github.com/novlan1/eslint-plugin-light/commit/4f33c36f40bd8c872c586d05cd6ffbd0d21b5f62))
|
|
42
|
+
* 优化readme ([f0183d0](https://github.com/novlan1/eslint-plugin-light/commit/f0183d0b7cd66af9c47d3e389ccc11c572e1f54a))
|
|
20
43
|
|
|
21
44
|
|
|
22
45
|
### ✅ Tests | 测试
|
|
23
46
|
|
|
24
|
-
* 测试用例修正 ([70e9f36](https://
|
|
47
|
+
* 测试用例修正 ([70e9f36](https://github.com/novlan1/eslint-plugin-light/commit/70e9f36fdad34b72d94b85c2590bbb06489fd6aa))
|
|
25
48
|
|
|
26
49
|
|
|
27
50
|
### 🚀 Chore | 构建/工程依赖/工具
|
|
28
51
|
|
|
29
|
-
* 删除无效注释 ([96d5e9d](https://
|
|
52
|
+
* 删除无效注释 ([96d5e9d](https://github.com/novlan1/eslint-plugin-light/commit/96d5e9d158c10df93c6f714805eaf8d670d39eeb))
|
|
30
53
|
|
|
31
|
-
### [0.0.16](https://
|
|
54
|
+
### [0.0.16](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.15...v0.0.16) (2022-07-26)
|
|
32
55
|
|
|
33
56
|
|
|
34
57
|
### ✨ Features | 新功能
|
|
35
58
|
|
|
36
|
-
* 去掉打印信息 ([bde64c7](https://
|
|
59
|
+
* 去掉打印信息 ([bde64c7](https://github.com/novlan1/eslint-plugin-light/commit/bde64c765562f5842aa988ee07d2caac27786a6c))
|
|
37
60
|
|
|
38
|
-
### [0.0.15](https://
|
|
61
|
+
### [0.0.15](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.14...v0.0.15) (2022-07-26)
|
|
39
62
|
|
|
40
63
|
|
|
41
64
|
### ✨ Features | 新功能
|
|
42
65
|
|
|
43
|
-
* 优化包 ([906bcd7](https://
|
|
66
|
+
* 优化包 ([906bcd7](https://github.com/novlan1/eslint-plugin-light/commit/906bcd7a2ff0291d331feef961b479135f11c526))
|
|
44
67
|
|
|
45
|
-
### [0.0.14](https://
|
|
68
|
+
### [0.0.14](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.13...v0.0.14) (2022-07-26)
|
|
46
69
|
|
|
47
70
|
|
|
48
71
|
### ✨ Features | 新功能
|
|
49
72
|
|
|
50
|
-
* 脚本优化 ([d1e8172](https://
|
|
51
|
-
* 脚本优化 ([9c6d844](https://
|
|
52
|
-
* **complex-key:** 不要使用复杂的key ([00e981b](https://
|
|
73
|
+
* 脚本优化 ([d1e8172](https://github.com/novlan1/eslint-plugin-light/commit/d1e8172ac3777f1377864d3de76a50c55e4122dd))
|
|
74
|
+
* 脚本优化 ([9c6d844](https://github.com/novlan1/eslint-plugin-light/commit/9c6d844aad15475e1af7d97728dfcae84bd99693))
|
|
75
|
+
* **complex-key:** 不要使用复杂的key ([00e981b](https://github.com/novlan1/eslint-plugin-light/commit/00e981b8d81e097576163fa8078a09a315a22cba))
|
|
53
76
|
|
|
54
|
-
### [0.0.13](https://
|
|
77
|
+
### [0.0.13](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.12...v0.0.13) (2022-07-26)
|
|
55
78
|
|
|
56
79
|
|
|
57
80
|
### ✨ Features | 新功能
|
|
58
81
|
|
|
59
|
-
* 优化脚本 ([ad9b142](https://
|
|
82
|
+
* 优化脚本 ([ad9b142](https://github.com/novlan1/eslint-plugin-light/commit/ad9b142ee87aba73d45adcef3aa94ac3d5988b31))
|
|
60
83
|
|
|
61
|
-
### [0.0.12](https://
|
|
84
|
+
### [0.0.12](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.11...v0.0.12) (2022-07-26)
|
|
62
85
|
|
|
63
86
|
|
|
64
87
|
### ✨ Features | 新功能
|
|
65
88
|
|
|
66
|
-
* 脚本优化 ([62f1181](https://
|
|
89
|
+
* 脚本优化 ([62f1181](https://github.com/novlan1/eslint-plugin-light/commit/62f11815bb458201991cca99716e773a3281c65b))
|
|
67
90
|
|
|
68
|
-
### [0.0.11](https://
|
|
91
|
+
### [0.0.11](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.10...v0.0.11) (2022-07-26)
|
|
69
92
|
|
|
70
93
|
|
|
71
94
|
### ✨ Features | 新功能
|
|
72
95
|
|
|
73
|
-
* 脚本优化 ([3047f01](https://
|
|
74
|
-
* 优化发布脚本 ([a072ae8](https://
|
|
96
|
+
* 脚本优化 ([3047f01](https://github.com/novlan1/eslint-plugin-light/commit/3047f01b89fdbdb8c72b0c5e511afb587d8ffc99))
|
|
97
|
+
* 优化发布脚本 ([a072ae8](https://github.com/novlan1/eslint-plugin-light/commit/a072ae8715352c9452072e8dfa9c85a343cf4f26))
|
|
75
98
|
|
|
76
|
-
### [0.0.10](https://
|
|
99
|
+
### [0.0.10](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.9...v0.0.10) (2022-07-26)
|
|
77
100
|
|
|
78
101
|
|
|
79
102
|
### ✨ Features | 新功能
|
|
80
103
|
|
|
81
|
-
* 优化发布脚本 ([470a35f](https://
|
|
82
|
-
* 优化error信息 ([453430f](https://
|
|
104
|
+
* 优化发布脚本 ([470a35f](https://github.com/novlan1/eslint-plugin-light/commit/470a35fc55153d41a362cf61492fde120a9ed3f7))
|
|
105
|
+
* 优化error信息 ([453430f](https://github.com/novlan1/eslint-plugin-light/commit/453430ff437d062cd1efa7bff96b87e975b2b414))
|
|
83
106
|
|
|
84
|
-
### [0.0.9](https://
|
|
107
|
+
### [0.0.9](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.8...v0.0.9) (2022-07-22)
|
|
85
108
|
|
|
86
109
|
|
|
87
110
|
### ✨ Features | 新功能
|
|
88
111
|
|
|
89
|
-
* 优化插件 ([13a84d5](https://
|
|
112
|
+
* 优化插件 ([13a84d5](https://github.com/novlan1/eslint-plugin-light/commit/13a84d5ce25788f5d3b3b63b84a0731f179ff12d))
|
|
90
113
|
|
|
91
114
|
|
|
92
115
|
### ✏️ Documentation | 文档
|
|
93
116
|
|
|
94
|
-
* 用法更新 ([78e344d](https://
|
|
117
|
+
* 用法更新 ([78e344d](https://github.com/novlan1/eslint-plugin-light/commit/78e344d61c026f7c38960d41d7038888664ecb85))
|
|
95
118
|
|
|
96
|
-
### [0.0.8](https://
|
|
119
|
+
### [0.0.8](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.7...v0.0.8) (2022-07-22)
|
|
97
120
|
|
|
98
121
|
|
|
99
122
|
### ✏️ Documentation | 文档
|
|
100
123
|
|
|
101
|
-
* 更新文档 ([d6e3a23](https://
|
|
124
|
+
* 更新文档 ([d6e3a23](https://github.com/novlan1/eslint-plugin-light/commit/d6e3a23205244f41ecb8b8fff3bb9d9a07a2c734))
|
|
102
125
|
|
|
103
126
|
|
|
104
127
|
### 🚀 Chore | 构建/工程依赖/工具
|
|
105
128
|
|
|
106
|
-
* eslint ([63e2398](https://
|
|
129
|
+
* eslint ([63e2398](https://github.com/novlan1/eslint-plugin-light/commit/63e2398387b466c4e188a7f12a2d08586583f527))
|
|
107
130
|
|
|
108
131
|
|
|
109
132
|
### ✨ Features | 新功能
|
|
110
133
|
|
|
111
|
-
* **number:** 优化插件 ([003f290](https://
|
|
134
|
+
* **number:** 优化插件 ([003f290](https://github.com/novlan1/eslint-plugin-light/commit/003f290563b15d4cc1e8a6585a629bbfba2fce1e))
|
|
112
135
|
|
|
113
|
-
### [0.0.7](https://
|
|
136
|
+
### [0.0.7](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.6...v0.0.7) (2022-07-22)
|
|
114
137
|
|
|
115
138
|
|
|
116
139
|
### ✏️ Documentation | 文档
|
|
117
140
|
|
|
118
|
-
* 文档优化 ([e7f5bfb](https://
|
|
119
|
-
* 优化文档 ([44e7b1e](https://
|
|
141
|
+
* 文档优化 ([e7f5bfb](https://github.com/novlan1/eslint-plugin-light/commit/e7f5bfb9e67ac3f7cb9ea182200886feb22c9798))
|
|
142
|
+
* 优化文档 ([44e7b1e](https://github.com/novlan1/eslint-plugin-light/commit/44e7b1e5f5e230363dcfd6923d325e96db9509f4))
|
|
120
143
|
|
|
121
144
|
|
|
122
145
|
### ✨ Features | 新功能
|
|
123
146
|
|
|
124
|
-
* **no-plus-turn-number:** 转化+字符串 ([aa69796](https://
|
|
147
|
+
* **no-plus-turn-number:** 转化+字符串 ([aa69796](https://github.com/novlan1/eslint-plugin-light/commit/aa69796620c554d745c2b5133b9699c9be363805))
|
|
125
148
|
|
|
126
|
-
### [0.0.6](https://
|
|
149
|
+
### [0.0.6](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.5...v0.0.6) (2022-07-22)
|
|
127
150
|
|
|
128
151
|
|
|
129
152
|
### ✨ Features | 新功能
|
|
130
153
|
|
|
131
|
-
* 优化插件 ([c0e28fd](https://
|
|
154
|
+
* 优化插件 ([c0e28fd](https://github.com/novlan1/eslint-plugin-light/commit/c0e28fda4d5ba7c6c90a0ad7fe799342b79e9b49))
|
|
132
155
|
|
|
133
|
-
### [0.0.5](https://
|
|
156
|
+
### [0.0.5](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.4...v0.0.5) (2022-07-22)
|
|
134
157
|
|
|
135
|
-
### [0.0.4](https://
|
|
158
|
+
### [0.0.4](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.3...v0.0.4) (2022-07-22)
|
|
136
159
|
|
|
137
160
|
|
|
138
161
|
### 🐛 Bug Fixes | Bug 修复
|
|
139
162
|
|
|
140
|
-
* 兼容性处理 ([ba123c2](https://
|
|
163
|
+
* 兼容性处理 ([ba123c2](https://github.com/novlan1/eslint-plugin-light/commit/ba123c26093d66008e459cdc3bfaf5fea74588e1))
|
|
141
164
|
|
|
142
|
-
### [0.0.3](https://
|
|
165
|
+
### [0.0.3](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.2...v0.0.3) (2022-07-22)
|
|
143
166
|
|
|
144
167
|
|
|
145
168
|
### 🚀 Chore | 构建/工程依赖/工具
|
|
146
169
|
|
|
147
|
-
* 增加versionrc ([1a8b239](https://
|
|
148
|
-
* version ([dda6406](https://
|
|
170
|
+
* 增加versionrc ([1a8b239](https://github.com/novlan1/eslint-plugin-light/commit/1a8b2393618cbb16003298a1ec5e8b9bf44fb779))
|
|
171
|
+
* version ([dda6406](https://github.com/novlan1/eslint-plugin-light/commit/dda640604dd0bd34bf8937692781edd95b99d6ed))
|
|
149
172
|
|
|
150
173
|
### 0.0.2 (2022-07-22)
|
|
151
174
|
|
|
152
175
|
|
|
153
176
|
### Features
|
|
154
177
|
|
|
155
|
-
* 安装version ([a295b91](https://
|
|
156
|
-
* 优化插件 ([803d743](https://
|
|
157
|
-
* init ([44f3cb3](https://
|
|
158
|
-
* vue组件规则 ([80b3690](https://
|
|
178
|
+
* 安装version ([a295b91](https://github.com/novlan1/eslint-plugin-light/commit/a295b91936a3eaeeda3bbc53d3221d0c0ee4c6f8))
|
|
179
|
+
* 优化插件 ([803d743](https://github.com/novlan1/eslint-plugin-light/commit/803d7434d653776dd70d0ec85b8eb0c20bdbc578))
|
|
180
|
+
* init ([44f3cb3](https://github.com/novlan1/eslint-plugin-light/commit/44f3cb326e7fca1b4b4b54ec8f361b491b84f996))
|
|
181
|
+
* vue组件规则 ([80b3690](https://github.com/novlan1/eslint-plugin-light/commit/80b36908061aab76995f6b7bf1d7f6930bb6f7eb))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 novlan1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
##
|
|
1
|
+
## ESLint Plugin Light
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/dw/eslint-plugin-light">
|
|
5
|
+
<img src="https://img.shields.io/npm/unpacked-size/eslint-plugin-light">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/eslint-plugin-light">
|
|
7
|
+
<img src="https://img.shields.io/npm/l/eslint-plugin-light">
|
|
8
|
+
<img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
|
|
9
|
+
<img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
|
|
10
|
+
</p>
|
|
4
11
|
|
|
12
|
+
简单、易用的 ESLint 插件库。
|
|
5
13
|
|
|
6
|
-
### 1.
|
|
14
|
+
### 1. 安装
|
|
7
15
|
|
|
8
|
-
|
|
16
|
+
首先要安装 [ESLint](https://eslint.org/)。
|
|
9
17
|
|
|
10
18
|
```sh
|
|
11
|
-
|
|
19
|
+
pnpm i eslint -D
|
|
12
20
|
```
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
然后安装本插件 `eslint-plugin-light`。
|
|
15
23
|
|
|
16
24
|
```sh
|
|
17
25
|
npm i eslint-plugin-light -D
|
|
18
26
|
```
|
|
19
27
|
|
|
20
|
-
### 2.
|
|
28
|
+
### 2. 使用
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
在 `.eslintrc` 配置文件的 `plugins` 中增加本插件 `eslint-plugin-light`,或者省略 `eslint-plugin-` 前缀。
|
|
23
31
|
|
|
24
32
|
```json
|
|
25
33
|
{
|
|
@@ -29,8 +37,7 @@ Add `light` to the plugins section of your `.eslintrc` configuration file. You c
|
|
|
29
37
|
}
|
|
30
38
|
```
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
Then configure the rules you want to use under the rules section.
|
|
40
|
+
然后配置你想使用的规则。
|
|
34
41
|
|
|
35
42
|
```json
|
|
36
43
|
{
|
|
@@ -40,7 +47,7 @@ Then configure the rules you want to use under the rules section.
|
|
|
40
47
|
}
|
|
41
48
|
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
也可以使用本工具提供的扩展。
|
|
44
51
|
|
|
45
52
|
```json
|
|
46
53
|
{
|
|
@@ -48,16 +55,14 @@ or use extends:
|
|
|
48
55
|
}
|
|
49
56
|
```
|
|
50
57
|
|
|
58
|
+
### 3. 规则
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#### 3.1. light/valid-vue-comp-import
|
|
60
|
+
#### 3.1. valid-vue-comp-import
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
禁止从 `js` 文件中加载 `Vue` 组件。
|
|
57
63
|
|
|
58
64
|
比如,
|
|
59
65
|
|
|
60
|
-
|
|
61
66
|
1. 导入地址是`js/ts`文件
|
|
62
67
|
|
|
63
68
|
```js
|
|
@@ -75,8 +80,6 @@ import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
|
|
|
75
80
|
|
|
76
81
|
注意上面的`xxx.vue`是从`index.js`中分析得到的原始文件路径。
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
83
|
2. 导入一个目录,但目录存在`index.js`,这时候不管存不存在`index.vue`,`uni-app`转换都会失败
|
|
81
84
|
|
|
82
85
|
```js
|
|
@@ -109,9 +112,9 @@ import CComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
|
|
|
109
112
|
import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/d.vue';
|
|
110
113
|
```
|
|
111
114
|
|
|
112
|
-
#### 3.2.
|
|
115
|
+
#### 3.2. no-plus-turn-number
|
|
113
116
|
|
|
114
|
-
|
|
117
|
+
禁止在 `vue` 的 `template` 中用 `+` 号转换字符串为数字
|
|
115
118
|
|
|
116
119
|
比如:
|
|
117
120
|
|
|
@@ -121,7 +124,7 @@ import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
|
|
|
121
124
|
/>
|
|
122
125
|
```
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
如果加了 `--fix`,会被转化成:
|
|
125
128
|
|
|
126
129
|
```html
|
|
127
130
|
<ScheduleItem
|
|
@@ -129,7 +132,7 @@ import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
|
|
|
129
132
|
/>
|
|
130
133
|
```
|
|
131
134
|
|
|
132
|
-
#### 3.3 no-complex-key
|
|
135
|
+
#### 3.3. no-complex-key
|
|
133
136
|
|
|
134
137
|
不要在`vue`模板中使用复杂的`key`。包括:
|
|
135
138
|
|
|
@@ -169,7 +172,7 @@ getData() {
|
|
|
169
172
|
`uni-app`中,`key`重复的话,会造成挂载在组件上面的事件参数为`undefined`,从而不成功。
|
|
170
173
|
|
|
171
174
|
|
|
172
|
-
#### 3.4
|
|
175
|
+
#### 3.4. json-parse-try-catch
|
|
173
176
|
|
|
174
177
|
`JSON.parse` 应该加 `try catch`。
|
|
175
178
|
|
|
@@ -181,7 +184,6 @@ JSON.parse(JSON.stringify(abc));
|
|
|
181
184
|
|
|
182
185
|
可以配置 `strict` 参数为 `true`,开启检查。
|
|
183
186
|
|
|
184
|
-
|
|
185
187
|
```js
|
|
186
188
|
// .eslintrc.js
|
|
187
189
|
|
|
@@ -194,3 +196,54 @@ module.exports = {
|
|
|
194
196
|
},
|
|
195
197
|
}
|
|
196
198
|
```
|
|
199
|
+
|
|
200
|
+
#### 3.5. no-import-all-in-one-api
|
|
201
|
+
|
|
202
|
+
使用 `src/api` 子仓库时, 不应该导入全部接口,而应该按需引入。
|
|
203
|
+
|
|
204
|
+
Bad case:
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
// bad
|
|
208
|
+
import { pubg_fateClient } from 'src/api/git.a.com/itrpcprotocol/esport/esport_cgi/pubg_fate/pubg_fate.http';
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Good case:
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
// good
|
|
215
|
+
import { QueryGameListHomePageClient } from 'src/api/git.a.com/itrpcprotocol/esport/esport_cgi/pubg_fate/pubg_fate/QueryGameListHomePage.http';
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Usage:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// .eslintrc.js
|
|
222
|
+
|
|
223
|
+
module.exports = {
|
|
224
|
+
plugins: [
|
|
225
|
+
'light',
|
|
226
|
+
],
|
|
227
|
+
rules: {
|
|
228
|
+
'light/no-import-all-in-one-api': 2,
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
下面是一个案例,根据这个规则,对一个线上项目进行改造。仅仅改动了[几个文件的几行引入语句](https://git.a.com/pmd-mobile/match/gp-next/commit/20e0050fe10ed767dcb5d77dca76a9b51c23820e),就减少了主包 `50KB`,效果立竿见影。
|
|
234
|
+
|
|
235
|
+
之前:
|
|
236
|
+
|
|
237
|
+
<img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/5/own_mike_p8Sr7F4zjtry4mtR.png" width="600">
|
|
238
|
+
|
|
239
|
+
之后:
|
|
240
|
+
|
|
241
|
+
<img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/5/own_mike_MJ8Q5QXEyamnGZXz.png" width="600">
|
|
242
|
+
|
|
243
|
+
改动的几个文件:
|
|
244
|
+
|
|
245
|
+
<img src="https://mike-1255355338.cos.ap-guangzhou.myqcloud.com/article/2025/5/own_mike_rfMPwBYtZmhXrthT.png" width="600">
|
|
246
|
+
|
|
247
|
+
### 4. 更新日志
|
|
248
|
+
|
|
249
|
+
[点此查看](./CHANGELOG.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: ['eslint-plugin-light', 'vue'],
|
|
3
|
+
parser: require.resolve('vue-eslint-parser'),
|
|
4
|
+
parserOptions: {
|
|
5
|
+
ecmaVersion: 2020,
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
},
|
|
8
|
+
env: {
|
|
9
|
+
browser: true,
|
|
10
|
+
es6: true,
|
|
11
|
+
},
|
|
12
|
+
rules: {
|
|
13
|
+
'light/valid-vue-comp-import': 2,
|
|
14
|
+
'light/no-plus-turn-number': 2,
|
|
15
|
+
},
|
|
16
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const requireIndex = require('requireindex');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
rules: requireIndex(`${__dirname}/rules`),
|
|
8
|
+
configs: {
|
|
9
|
+
base: require('./configs/base'),
|
|
10
|
+
essential: require('./configs/essential'),
|
|
11
|
+
recommended: require('./configs/recommended'),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// 用于检测 JSON.parse 没有用 try catch
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const desc = 'JSON.parse need try catch';
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'suggestion',
|
|
9
|
+
docs: {
|
|
10
|
+
description: desc,
|
|
11
|
+
category: 'Best Practices',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
schema: [{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
strict: {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}],
|
|
22
|
+
create(context) {
|
|
23
|
+
const options = context.options?.[0];
|
|
24
|
+
let strict = options?.strict;
|
|
25
|
+
if (typeof strict === 'undefined') {
|
|
26
|
+
strict = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
CallExpression(node) {
|
|
31
|
+
const calleeObjectName = node.callee?.object?.name;
|
|
32
|
+
const calleePropertyName = node.callee?.property?.name;
|
|
33
|
+
|
|
34
|
+
const subNode = node.arguments?.[0];
|
|
35
|
+
const sbCalleeObjectName = subNode?.callee?.object?.name;
|
|
36
|
+
const subCalleePropertyName = subNode?.callee?.property?.name;
|
|
37
|
+
|
|
38
|
+
if (calleeObjectName === 'JSON'
|
|
39
|
+
&& calleePropertyName === 'parse'
|
|
40
|
+
&& (strict || !(sbCalleeObjectName === 'JSON' && subCalleePropertyName === 'stringify'))
|
|
41
|
+
) {
|
|
42
|
+
let p = node.parent;
|
|
43
|
+
let hasTryFlg = false;
|
|
44
|
+
|
|
45
|
+
while (p && !hasTryFlg) {
|
|
46
|
+
if (p.type === 'TryStatement') hasTryFlg = true;
|
|
47
|
+
p = p.parent;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!hasTryFlg) {
|
|
51
|
+
context.report(node, desc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
schema: [],
|
|
5
|
+
docs: {
|
|
6
|
+
description: 'vue模板中不要使用复杂的key',
|
|
7
|
+
},
|
|
8
|
+
messages: {
|
|
9
|
+
error: 'Do not use complex key',
|
|
10
|
+
funcError: 'Do not use function as key',
|
|
11
|
+
stringError: 'Do not use string concatenation as key',
|
|
12
|
+
tplError: 'Do not use template string as key',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
create(context) {
|
|
17
|
+
const fileName = context.getFilename();
|
|
18
|
+
if (!fileName.endsWith('.vue')) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
if (!context.parserServices?.defineTemplateBodyVisitor) {
|
|
22
|
+
return {
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return context.parserServices.defineTemplateBodyVisitor({
|
|
27
|
+
VAttribute(node) {
|
|
28
|
+
if (!node.key
|
|
29
|
+
|| node.key.type !== 'VDirectiveKey'
|
|
30
|
+
|| node.key?.argument?.type !== 'VIdentifier'
|
|
31
|
+
|| node.key?.argument?.name !== 'key'
|
|
32
|
+
) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (node?.value?.type === 'VExpressionContainer') {
|
|
37
|
+
if (node.value.expression?.type === 'CallExpression') {
|
|
38
|
+
// :key="getHoldKey(item)"
|
|
39
|
+
context.report({
|
|
40
|
+
node,
|
|
41
|
+
messageId: 'funcError',
|
|
42
|
+
});
|
|
43
|
+
} else if (node.value.expression?.type === 'BinaryExpression') {
|
|
44
|
+
// :key="index + 'hold'"
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: 'stringError',
|
|
48
|
+
});
|
|
49
|
+
} else if (node.value.expression?.type === 'TemplateLiteral') {
|
|
50
|
+
// :key="`${index}hold`"
|
|
51
|
+
context.report({
|
|
52
|
+
node,
|
|
53
|
+
messageId: 'tplError',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 合法的是MemberExpression,比如item.key
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const CORE_REG = /src\/api\/[\w.-_/]+\/[a-z][\w-]+.http(.ts)?$/;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'problem',
|
|
7
|
+
docs: {
|
|
8
|
+
description: '禁止从指定的文件中导入',
|
|
9
|
+
category: 'Possible Errors',
|
|
10
|
+
recommended: true,
|
|
11
|
+
},
|
|
12
|
+
schema: [
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
excludes: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
messages: {
|
|
27
|
+
restrictedImport: '不允许从 {{filePath}} 导入。',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
// const projectRoot = context.settings.projectRoot ?? process.cwd();
|
|
32
|
+
const options = context.options[0] || {};
|
|
33
|
+
const excludes = options.excludes || [];
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
ImportDeclaration(node) {
|
|
37
|
+
const sourceValue = node.source.value;
|
|
38
|
+
|
|
39
|
+
if (CORE_REG.test(sourceValue)
|
|
40
|
+
&& !excludes.includes(sourceValue)
|
|
41
|
+
) {
|
|
42
|
+
context.report({
|
|
43
|
+
node,
|
|
44
|
+
message: `不允许从 ${sourceValue} 导入全部接口,应按需导入`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
schema: [],
|
|
5
|
+
docs: {
|
|
6
|
+
description: '不要直接引用vant',
|
|
7
|
+
},
|
|
8
|
+
fixable: 'code',
|
|
9
|
+
messages: {
|
|
10
|
+
error: 'Do not import vant',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
create(context) {
|
|
15
|
+
const fileName = context.getFilename();
|
|
16
|
+
if (!fileName.endsWith('.vue')) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration: (node) => {
|
|
21
|
+
if (node.source.value === 'vant') {
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
messageId: 'error',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
// if (!context.parserServices?.defineTemplateBodyVisitor) {
|
|
30
|
+
// return {
|
|
31
|
+
// };
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// return context.parserServices.defineTemplateBodyVisitor({
|
|
35
|
+
// VAttribute(node) {
|
|
36
|
+
// if (!node.key
|
|
37
|
+
// || node.key.type !== 'VDirectiveKey'
|
|
38
|
+
// || node.key?.argument?.type !== 'VIdentifier'
|
|
39
|
+
// || node.key?.argument?.name !== 'key'
|
|
40
|
+
// ) {
|
|
41
|
+
// return;
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// if (node?.value?.type === 'VExpressionContainer') {
|
|
45
|
+
// if (node.value.expression?.type === 'CallExpression') {
|
|
46
|
+
// // :key="getHoldKey(item)"
|
|
47
|
+
// context.report({
|
|
48
|
+
// node,
|
|
49
|
+
// messageId: 'funcError',
|
|
50
|
+
// });
|
|
51
|
+
// } else if (node.value.expression?.type === 'BinaryExpression') {
|
|
52
|
+
// // :key="index + 'hold'"
|
|
53
|
+
// context.report({
|
|
54
|
+
// node,
|
|
55
|
+
// messageId: 'stringError',
|
|
56
|
+
// });
|
|
57
|
+
// } else if (node.value.expression?.type === 'TemplateLiteral') {
|
|
58
|
+
// // :key="`${index}hold`"
|
|
59
|
+
// context.report({
|
|
60
|
+
// node,
|
|
61
|
+
// messageId: 'tplError',
|
|
62
|
+
// });
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
// // 合法的是MemberExpression,比如item.key
|
|
66
|
+
// }
|
|
67
|
+
// },
|
|
68
|
+
// });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
schema: [],
|
|
5
|
+
docs: {
|
|
6
|
+
description: 'vue模板中不能使用+号转换字符串',
|
|
7
|
+
},
|
|
8
|
+
fixable: 'code',
|
|
9
|
+
messages: {
|
|
10
|
+
error: 'Do not use plus symbol to transfer string',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
create(context) {
|
|
15
|
+
const fileName = context.getFilename();
|
|
16
|
+
if (!fileName.endsWith('.vue')) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
if (!context.parserServices?.defineTemplateBodyVisitor) {
|
|
20
|
+
return {
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return context.parserServices.defineTemplateBodyVisitor({
|
|
25
|
+
VAttribute(node) {
|
|
26
|
+
if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression) {
|
|
27
|
+
const { operator } = node.value.expression;
|
|
28
|
+
const { argument } = node.value.expression;
|
|
29
|
+
|
|
30
|
+
// console.log('operator',operator)
|
|
31
|
+
// console.log('argument',argument && argument.type)
|
|
32
|
+
|
|
33
|
+
if (operator === '+' && argument && argument.type === 'Identifier') {
|
|
34
|
+
const { name } = node.value.expression.argument;
|
|
35
|
+
context.report({
|
|
36
|
+
node,
|
|
37
|
+
messageId: 'error',
|
|
38
|
+
fix(fixer) {
|
|
39
|
+
return fixer.replaceTextRange(node.value.expression.range, `parseInt(${name},10)`);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
5
|
+
module.exports = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
schema: [],
|
|
9
|
+
docs: {
|
|
10
|
+
description: '不能使用this.tip_uid',
|
|
11
|
+
},
|
|
12
|
+
fixable: null, // Or `code` or `whitespace`,
|
|
13
|
+
messages: {
|
|
14
|
+
noUseTipUidId: '不能使用this.tip_uid',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
MemberExpression: (node) => {
|
|
21
|
+
if (node.object.type === 'ThisExpression'
|
|
22
|
+
&& node.property.type === 'Identifier'
|
|
23
|
+
&& node.property.name === 'tip_uid') {
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: 'noUseTipUidId',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
// visitor functions for different types of nodes
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const jsParser = require('@babel/eslint-parser');
|
|
5
|
+
|
|
6
|
+
const ROOT_PATH = process.cwd();
|
|
7
|
+
|
|
8
|
+
const VALID_FILES = ['js', 'ts', 'vue'];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取引入文件的真实位置,如果是目录,返回目录,如果是文件,返回带后缀的文件
|
|
12
|
+
*/
|
|
13
|
+
function findCompDir(source = '', dirname = '') {
|
|
14
|
+
let compFile;
|
|
15
|
+
if (source.startsWith('.')) {
|
|
16
|
+
compFile = path.resolve(dirname, source);
|
|
17
|
+
} else if (source.startsWith('src')) {
|
|
18
|
+
compFile = path.resolve(process.cwd(), source);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (fs.existsSync(compFile)) {
|
|
22
|
+
return compFile;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < VALID_FILES.length; i++) {
|
|
26
|
+
const postfix = VALID_FILES[i];
|
|
27
|
+
const wholeFileName = `${compFile}.${postfix}`;
|
|
28
|
+
if (fs.existsSync(wholeFileName)) {
|
|
29
|
+
return wholeFileName;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.log('\x1B[31m%s\x1B[0m', '未找到引入文件');
|
|
33
|
+
return compFile;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getSourceAST(sourceFile) {
|
|
37
|
+
const jsData = fs.readFileSync(sourceFile, {
|
|
38
|
+
encoding: 'utf-8',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let scriptAST = undefined;
|
|
42
|
+
|
|
43
|
+
const opts = {
|
|
44
|
+
sourceType: 'module',
|
|
45
|
+
requireConfigFile: false,
|
|
46
|
+
babelOptions: {
|
|
47
|
+
configFile: false,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
scriptAST = jsParser.parse(jsData, opts);
|
|
53
|
+
delete scriptAST.tokens;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.log('出错了:', e);
|
|
56
|
+
}
|
|
57
|
+
return scriptAST;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function getDefaultExportComp(ast) {
|
|
62
|
+
if (!ast) return '';
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const namedDeclarationNodes = ast.body.filter(item => item.type === 'ExportNamedDeclaration');
|
|
66
|
+
|
|
67
|
+
const namedObj = {};
|
|
68
|
+
// console.log('namedDeclarationNodes',namedDeclarationNodes.length)
|
|
69
|
+
for (let i = 0;i < namedDeclarationNodes.length;i++) {
|
|
70
|
+
const node = namedDeclarationNodes[i];
|
|
71
|
+
// console.log('node',node)
|
|
72
|
+
if (!node.specifiers || !node.specifiers.length) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// console.log('i',node)
|
|
76
|
+
const { value } = node.source;
|
|
77
|
+
const { name } = node.specifiers[0].exported;
|
|
78
|
+
namedObj[name] = value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// console.log('namedObj', namedObj);
|
|
82
|
+
|
|
83
|
+
if (namedObj.default) {
|
|
84
|
+
return namedObj;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const nodes = ast.body.filter(item => item.type === 'ExportDefaultDeclaration') || [];
|
|
88
|
+
if (nodes[0] && nodes[0].declaration.type === 'Identifier') {
|
|
89
|
+
// 是一个变量,代表从上面导入的
|
|
90
|
+
const { name } = nodes[0].declaration;
|
|
91
|
+
const importAst = ast.body.filter(item => item.type === 'ImportDeclaration' && !!item.specifiers.find(it => it.local.name === name));
|
|
92
|
+
// console.log('importAst', importAst)
|
|
93
|
+
namedObj.default = importAst[0].source.value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return namedObj;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getRelativePath(originPath = '') {
|
|
100
|
+
return originPath.replace(`${path.resolve(ROOT_PATH)}/`, '');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getDefaultExportPathFromSouceFile(sourceFile) {
|
|
104
|
+
const scriptAST = getSourceAST(sourceFile);
|
|
105
|
+
// console.log('scriptAST', scriptAST)
|
|
106
|
+
|
|
107
|
+
const defaultExportComp = getDefaultExportComp(scriptAST);
|
|
108
|
+
// console.log('defaultExportComp',defaultExportComp)
|
|
109
|
+
if (!defaultExportComp) return;
|
|
110
|
+
|
|
111
|
+
const obj = {};
|
|
112
|
+
const keys = Object.keys(defaultExportComp);
|
|
113
|
+
for (let i = 0;i < keys.length;i++) {
|
|
114
|
+
const name = keys[i];
|
|
115
|
+
const value = defaultExportComp[name];
|
|
116
|
+
const defaultFilePath = findCompDir(value, path.dirname(sourceFile));
|
|
117
|
+
const relativePath = getRelativePath(defaultFilePath);
|
|
118
|
+
obj[name] = relativePath;
|
|
119
|
+
}
|
|
120
|
+
// console.log('defaultFilePath',defaultFilePath)
|
|
121
|
+
|
|
122
|
+
// console.log('relativePath',relativePath)
|
|
123
|
+
return obj;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
function handleError({
|
|
128
|
+
specifiers,
|
|
129
|
+
sourceFile,
|
|
130
|
+
context,
|
|
131
|
+
node: one,
|
|
132
|
+
}) {
|
|
133
|
+
if (!specifiers || !specifiers.length) return;
|
|
134
|
+
const componentList = [];
|
|
135
|
+
let statementString = '\n';
|
|
136
|
+
const relativePath = getDefaultExportPathFromSouceFile(sourceFile);
|
|
137
|
+
|
|
138
|
+
const isJSError = sourceFile.endsWith('.js');
|
|
139
|
+
|
|
140
|
+
for (let i = 0;i < specifiers.length;i++) {
|
|
141
|
+
const specifier = specifiers[i];
|
|
142
|
+
const componentName = specifier.local.name;
|
|
143
|
+
// console.log('componentName', componentName);
|
|
144
|
+
componentList.push(componentName);
|
|
145
|
+
if (relativePath[componentName]) {
|
|
146
|
+
statementString += `import ${componentName} from '${relativePath[componentName]}';\n`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// console.log('relativePath', relativePath);
|
|
151
|
+
context.report({
|
|
152
|
+
node: one,
|
|
153
|
+
messageId: isJSError ? 'jsError' : 'tsError',
|
|
154
|
+
fix(fixer) {
|
|
155
|
+
/**
|
|
156
|
+
* 默认导入,比如:
|
|
157
|
+
*
|
|
158
|
+
* import BottomTipBarComp from 'xxx';
|
|
159
|
+
*
|
|
160
|
+
*/
|
|
161
|
+
const defaultCompStr = relativePath.default;
|
|
162
|
+
if (defaultCompStr && specifiers.length === 1 && specifiers[0].type === 'ImportDefaultSpecifier') {
|
|
163
|
+
return fixer.replaceTextRange(one.source.range, `'${defaultCompStr}'`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 具名导入,比如:
|
|
168
|
+
* import { xx, yy } from 'xxx';
|
|
169
|
+
*/
|
|
170
|
+
return [
|
|
171
|
+
fixer.insertTextBeforeRange(one.range, statementString),
|
|
172
|
+
fixer.removeRange(one.range),
|
|
173
|
+
];
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = {
|
|
179
|
+
meta: {
|
|
180
|
+
type: 'problem',
|
|
181
|
+
schema: [],
|
|
182
|
+
docs: {
|
|
183
|
+
description: '不能从js/ts文件中引入组件',
|
|
184
|
+
},
|
|
185
|
+
fixable: 'code',
|
|
186
|
+
messages: {
|
|
187
|
+
jsError: 'Do not import component from JS file',
|
|
188
|
+
tsError: 'Do not import component from TS file',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
create(context) {
|
|
193
|
+
// const sourceCode = context.getSourceCode();
|
|
194
|
+
// const cwd = context.getCwd();
|
|
195
|
+
const fileName = context.getFilename();
|
|
196
|
+
|
|
197
|
+
// console.log('cwd', cwd)
|
|
198
|
+
// console.log('fileName', fileName)
|
|
199
|
+
const dirname = path.dirname(fileName);
|
|
200
|
+
// console.log('dirname', dirname);
|
|
201
|
+
if (!fileName.endsWith('.vue')) {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
Program: (node) => {
|
|
207
|
+
const exportAst = node.body.find(item => item.type === 'ExportDefaultDeclaration');
|
|
208
|
+
if (!exportAst || !exportAst.declaration) return;
|
|
209
|
+
|
|
210
|
+
const properties = exportAst.declaration.properties || [];
|
|
211
|
+
const componentsNode = properties.find(item => item.key && item.key.name === 'components');
|
|
212
|
+
|
|
213
|
+
// console.log('componentsNode',componentsNode)
|
|
214
|
+
if (!componentsNode || !componentsNode.value
|
|
215
|
+
|| !componentsNode.value.properties
|
|
216
|
+
|| !componentsNode.value.properties.length
|
|
217
|
+
) return;
|
|
218
|
+
const components = componentsNode.value.properties.map(item => ((item.value && item.value.name) || ''));
|
|
219
|
+
|
|
220
|
+
// console.log('components', components);
|
|
221
|
+
|
|
222
|
+
if (!components || !components.length) return;
|
|
223
|
+
|
|
224
|
+
const importAst = node.body.filter(item => item.type === 'ImportDeclaration');
|
|
225
|
+
const realImport = importAst.filter(item => !!item.specifiers.find((it) => {
|
|
226
|
+
const name = (it.imported && it.imported.name) || (it.local && it.local.name);
|
|
227
|
+
return components.includes(name);
|
|
228
|
+
}));
|
|
229
|
+
// console.log('realImport',realImport, realImport.length)
|
|
230
|
+
|
|
231
|
+
for (let i = 0;i < realImport.length;i++) {
|
|
232
|
+
const one = realImport[i];
|
|
233
|
+
const { specifiers } = one;
|
|
234
|
+
const source = one.source.value;
|
|
235
|
+
|
|
236
|
+
if (source.endsWith('.vue')) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (source.endsWith('.js') || source.endsWith('.ts')) {
|
|
241
|
+
const compFile = findCompDir(source, dirname);
|
|
242
|
+
|
|
243
|
+
handleError({
|
|
244
|
+
specifiers,
|
|
245
|
+
sourceFile: compFile,
|
|
246
|
+
node: one,
|
|
247
|
+
context,
|
|
248
|
+
});
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const compFile = findCompDir(source, dirname);
|
|
253
|
+
|
|
254
|
+
if (fs.existsSync(compFile)) {
|
|
255
|
+
const stat = fs.lstatSync(compFile);
|
|
256
|
+
if (stat.isDirectory()) {
|
|
257
|
+
const indexJs = path.resolve(compFile, 'index.js');
|
|
258
|
+
const indexTs = path.resolve(compFile, 'index.ts');
|
|
259
|
+
if (fs.existsSync(indexJs)) {
|
|
260
|
+
handleError({
|
|
261
|
+
specifiers,
|
|
262
|
+
sourceFile: indexJs,
|
|
263
|
+
node: one,
|
|
264
|
+
context,
|
|
265
|
+
});
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (fs.existsSync(indexTs)) {
|
|
269
|
+
handleError({
|
|
270
|
+
specifiers,
|
|
271
|
+
sourceFile: indexTs,
|
|
272
|
+
node: one,
|
|
273
|
+
context,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
};
|
package/package.json
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-light",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Simple Eslint Plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslint plugin",
|
|
8
8
|
"eslint-plugin",
|
|
9
9
|
"eslint-plugin-light"
|
|
10
10
|
],
|
|
11
|
+
"homepage": "https://novlan1.github.io/plugin-light/zh/eslint-plugin-light.html",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/novlan1/plugin-light"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "novlan1",
|
|
21
|
+
"main": "lib/index.js",
|
|
11
22
|
"files": [
|
|
12
23
|
"lib/",
|
|
13
24
|
"README.md",
|
|
14
25
|
"CHANGELOG.md"
|
|
15
26
|
],
|
|
16
|
-
"main": "lib/index.js",
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "https://github.com/novlan1/plugin-light"
|
|
20
|
-
},
|
|
21
|
-
"author": "guowangyang",
|
|
22
|
-
"homepage": "https://novlan1.github.io/plugin-light/",
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
25
|
-
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"requireindex": "^1.2.0"
|
|
28
29
|
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"eslint": ">=6",
|
|
31
|
-
"@babel/eslint-parser": ">=6"
|
|
32
|
-
},
|
|
33
30
|
"devDependencies": {
|
|
34
31
|
"@babel/core": "^7.18.9",
|
|
35
32
|
"@babel/eslint-parser": "^7.18.9",
|
|
@@ -41,13 +38,17 @@
|
|
|
41
38
|
"mocha": "^9.1.3",
|
|
42
39
|
"standard-version": "^9.5.0"
|
|
43
40
|
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@babel/eslint-parser": ">=6",
|
|
43
|
+
"eslint": ">=6"
|
|
44
|
+
},
|
|
44
45
|
"engines": {
|
|
45
46
|
"node": "12.x || 14.x || >= 16"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
|
-
"build": "
|
|
49
|
-
"changelog": "node ../../script/monorepo/changelog $PWD",
|
|
49
|
+
"build": "rm -rf lib && node script/build",
|
|
50
50
|
"bump": "node ../../script/monorepo/version-simple $PWD",
|
|
51
|
+
"changelog": "node ../../script/monorepo/changelog $PWD",
|
|
51
52
|
"release": "node ../../script/monorepo/release $PWD"
|
|
52
53
|
}
|
|
53
54
|
}
|