eslint-plugin-light 1.0.0 → 1.0.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/CHANGELOG.md +156 -3
- package/README.md +40 -13
- package/package.json +13 -23
- package/lib/configs/base.js +0 -16
- package/lib/configs/essential.js +0 -5
- package/lib/configs/recommended.js +0 -7
- package/lib/index.js +0 -15
- package/lib/rules/no-complex-key.js +0 -62
- package/lib/rules/no-import-vant.js +0 -70
- package/lib/rules/no-plus-turn-number.js +0 -47
- package/lib/rules/no-this-tip-uid.js +0 -33
- package/lib/rules/valid-vue-comp-import.js +0 -281
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,158 @@
|
|
|
1
|
-
|
|
1
|
+
## [1.0.0](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.16...v1.0.0) (2023-07-12)
|
|
2
2
|
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
### ✨ Features | 新功能
|
|
5
|
+
|
|
6
|
+
* 添加规则不能使用this.tip_uid,但是没有开启 ([d913d2b](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/d913d2be33aaa44dbb6615f2d4ac98d4a7acebb0))
|
|
7
|
+
* 新增no-import-vant ([c5b8722](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/c5b87222db44111338cd1d9d4356695efa20cb93))
|
|
8
|
+
* 优化插件 ([505f17f](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/505f17f2191fdd6a9f32c67d64420ae115909af2))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### ♻️ Code Refactoring | 代码重构
|
|
12
|
+
|
|
13
|
+
* 插件重命名为light ([21c1dd9](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/21c1dd93dcd5e31265767cf53121a718826abaad))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### ✏️ Documentation | 文档
|
|
17
|
+
|
|
18
|
+
* 文档更新 ([4f33c36](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/4f33c36f40bd8c872c586d05cd6ffbd0d21b5f62))
|
|
19
|
+
* 优化readme ([f0183d0](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/f0183d0b7cd66af9c47d3e389ccc11c572e1f54a))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### ✅ Tests | 测试
|
|
23
|
+
|
|
24
|
+
* 测试用例修正 ([70e9f36](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/70e9f36fdad34b72d94b85c2590bbb06489fd6aa))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### 🚀 Chore | 构建/工程依赖/工具
|
|
28
|
+
|
|
29
|
+
* 删除无效注释 ([96d5e9d](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/96d5e9d158c10df93c6f714805eaf8d670d39eeb))
|
|
30
|
+
|
|
31
|
+
### [0.0.16](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.15...v0.0.16) (2022-07-26)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### ✨ Features | 新功能
|
|
35
|
+
|
|
36
|
+
* 去掉打印信息 ([bde64c7](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/bde64c765562f5842aa988ee07d2caac27786a6c))
|
|
37
|
+
|
|
38
|
+
### [0.0.15](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.14...v0.0.15) (2022-07-26)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### ✨ Features | 新功能
|
|
42
|
+
|
|
43
|
+
* 优化包 ([906bcd7](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/906bcd7a2ff0291d331feef961b479135f11c526))
|
|
44
|
+
|
|
45
|
+
### [0.0.14](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.13...v0.0.14) (2022-07-26)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### ✨ Features | 新功能
|
|
49
|
+
|
|
50
|
+
* 脚本优化 ([d1e8172](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/d1e8172ac3777f1377864d3de76a50c55e4122dd))
|
|
51
|
+
* 脚本优化 ([9c6d844](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/9c6d844aad15475e1af7d97728dfcae84bd99693))
|
|
52
|
+
* **complex-key:** 不要使用复杂的key ([00e981b](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/00e981b8d81e097576163fa8078a09a315a22cba))
|
|
53
|
+
|
|
54
|
+
### [0.0.13](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.12...v0.0.13) (2022-07-26)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### ✨ Features | 新功能
|
|
58
|
+
|
|
59
|
+
* 优化脚本 ([ad9b142](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/ad9b142ee87aba73d45adcef3aa94ac3d5988b31))
|
|
60
|
+
|
|
61
|
+
### [0.0.12](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.11...v0.0.12) (2022-07-26)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### ✨ Features | 新功能
|
|
65
|
+
|
|
66
|
+
* 脚本优化 ([62f1181](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/62f11815bb458201991cca99716e773a3281c65b))
|
|
67
|
+
|
|
68
|
+
### [0.0.11](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.10...v0.0.11) (2022-07-26)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### ✨ Features | 新功能
|
|
72
|
+
|
|
73
|
+
* 脚本优化 ([3047f01](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/3047f01b89fdbdb8c72b0c5e511afb587d8ffc99))
|
|
74
|
+
* 优化发布脚本 ([a072ae8](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/a072ae8715352c9452072e8dfa9c85a343cf4f26))
|
|
75
|
+
|
|
76
|
+
### [0.0.10](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.9...v0.0.10) (2022-07-26)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### ✨ Features | 新功能
|
|
80
|
+
|
|
81
|
+
* 优化发布脚本 ([470a35f](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/470a35fc55153d41a362cf61492fde120a9ed3f7))
|
|
82
|
+
* 优化error信息 ([453430f](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/453430ff437d062cd1efa7bff96b87e975b2b414))
|
|
83
|
+
|
|
84
|
+
### [0.0.9](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.8...v0.0.9) (2022-07-22)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### ✨ Features | 新功能
|
|
88
|
+
|
|
89
|
+
* 优化插件 ([13a84d5](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/13a84d5ce25788f5d3b3b63b84a0731f179ff12d))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### ✏️ Documentation | 文档
|
|
93
|
+
|
|
94
|
+
* 用法更新 ([78e344d](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/78e344d61c026f7c38960d41d7038888664ecb85))
|
|
95
|
+
|
|
96
|
+
### [0.0.8](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.7...v0.0.8) (2022-07-22)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### ✏️ Documentation | 文档
|
|
100
|
+
|
|
101
|
+
* 更新文档 ([d6e3a23](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/d6e3a23205244f41ecb8b8fff3bb9d9a07a2c734))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### 🚀 Chore | 构建/工程依赖/工具
|
|
105
|
+
|
|
106
|
+
* eslint ([63e2398](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/63e2398387b466c4e188a7f12a2d08586583f527))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### ✨ Features | 新功能
|
|
110
|
+
|
|
111
|
+
* **number:** 优化插件 ([003f290](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/003f290563b15d4cc1e8a6585a629bbfba2fce1e))
|
|
112
|
+
|
|
113
|
+
### [0.0.7](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.6...v0.0.7) (2022-07-22)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### ✏️ Documentation | 文档
|
|
117
|
+
|
|
118
|
+
* 文档优化 ([e7f5bfb](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/e7f5bfb9e67ac3f7cb9ea182200886feb22c9798))
|
|
119
|
+
* 优化文档 ([44e7b1e](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/44e7b1e5f5e230363dcfd6923d325e96db9509f4))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
### ✨ Features | 新功能
|
|
123
|
+
|
|
124
|
+
* **no-plus-turn-number:** 转化+字符串 ([aa69796](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/aa69796620c554d745c2b5133b9699c9be363805))
|
|
125
|
+
|
|
126
|
+
### [0.0.6](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.5...v0.0.6) (2022-07-22)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### ✨ Features | 新功能
|
|
130
|
+
|
|
131
|
+
* 优化插件 ([c0e28fd](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/c0e28fda4d5ba7c6c90a0ad7fe799342b79e9b49))
|
|
132
|
+
|
|
133
|
+
### [0.0.5](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.4...v0.0.5) (2022-07-22)
|
|
134
|
+
|
|
135
|
+
### [0.0.4](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.3...v0.0.4) (2022-07-22)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
139
|
+
|
|
140
|
+
* 兼容性处理 ([ba123c2](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/ba123c26093d66008e459cdc3bfaf5fea74588e1))
|
|
141
|
+
|
|
142
|
+
### [0.0.3](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/compare/v0.0.2...v0.0.3) (2022-07-22)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### 🚀 Chore | 构建/工程依赖/工具
|
|
146
|
+
|
|
147
|
+
* 增加versionrc ([1a8b239](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/1a8b2393618cbb16003298a1ec5e8b9bf44fb779))
|
|
148
|
+
* version ([dda6406](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/dda640604dd0bd34bf8937692781edd95b99d6ed))
|
|
149
|
+
|
|
150
|
+
### 0.0.2 (2022-07-22)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Features
|
|
154
|
+
|
|
155
|
+
* 安装version ([a295b91](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/a295b91936a3eaeeda3bbc53d3221d0c0ee4c6f8))
|
|
156
|
+
* 优化插件 ([803d743](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/803d7434d653776dd70d0ec85b8eb0c20bdbc578))
|
|
157
|
+
* init ([44f3cb3](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/44f3cb326e7fca1b4b4b54ec8f361b491b84f996))
|
|
158
|
+
* vue组件规则 ([80b3690](https://git.woa.com/pmd-mobile/support/eslint-plugin-pmd/commit/80b36908061aab76995f6b7bf1d7f6930bb6f7eb))
|
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
## Eslint Plugin Light
|
|
2
2
|
|
|
3
|
-
Eslint plugin.
|
|
3
|
+
Simple Eslint plugin.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
### 1. Installation
|
|
7
7
|
|
|
8
|
-
You
|
|
8
|
+
You need to install [ESLint](https://eslint.org/) first.
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
npm i eslint
|
|
11
|
+
npm i eslint -D
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Next, install `eslint-plugin-light
|
|
14
|
+
Next, install `eslint-plugin-light`.
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
npm
|
|
17
|
+
npm i eslint-plugin-light -D
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### 2. Usage
|
|
21
21
|
|
|
22
22
|
Add `light` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
|
|
23
23
|
|
|
@@ -49,9 +49,9 @@ or use extends:
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
### 3. Supported Rules
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
#### 3.1. light/valid-vue-comp-import
|
|
55
55
|
|
|
56
56
|
禁止从`js`文件中加载`Vue`组件
|
|
57
57
|
|
|
@@ -67,7 +67,7 @@ import SomeComp from 'src/local-component/ui/pages/user/account-manage/index.js'
|
|
|
67
67
|
import SomeComp from 'src/local-component/ui/pages/user/account-manage/index';
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
如果加了 `--fix`,会被转换为:
|
|
71
71
|
|
|
72
72
|
```js
|
|
73
73
|
import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
|
|
@@ -109,7 +109,7 @@ import CComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
|
|
|
109
109
|
import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/d.vue';
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
#### 3.2. light/no-plus-turn-number
|
|
113
113
|
|
|
114
114
|
禁止在`vue`的`template`中用`+`号转换字符串为数字
|
|
115
115
|
|
|
@@ -129,7 +129,7 @@ import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
|
|
|
129
129
|
/>
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
#### 3.3 no-complex-key
|
|
133
133
|
|
|
134
134
|
不要在`vue`模板中使用复杂的`key`。包括:
|
|
135
135
|
|
|
@@ -167,3 +167,30 @@ getData() {
|
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
`uni-app`中,`key`重复的话,会造成挂载在组件上面的事件参数为`undefined`,从而不成功。
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
#### 3.4 json-parse-try-catch
|
|
173
|
+
|
|
174
|
+
`JSON.parse` 应该加 `try catch`。
|
|
175
|
+
|
|
176
|
+
默认配置会排除下面情况:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
JSON.parse(JSON.stringify(abc));
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
可以配置 `strict` 参数为 `true`,开启检查。
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
// .eslintrc.js
|
|
187
|
+
|
|
188
|
+
module.exports = {
|
|
189
|
+
plugins: [
|
|
190
|
+
'light',
|
|
191
|
+
],
|
|
192
|
+
rules: {
|
|
193
|
+
'light/json-parse-try-catch': [2, { strict: true }],
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-light",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Light Eslint Plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslint plugin",
|
|
@@ -13,30 +13,15 @@
|
|
|
13
13
|
"README.md",
|
|
14
14
|
"CHANGELOG.md"
|
|
15
15
|
],
|
|
16
|
-
"author": "GuoWangYang",
|
|
17
16
|
"main": "lib/index.js",
|
|
18
17
|
"repository": {
|
|
19
18
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/novlan1/
|
|
19
|
+
"url": "https://github.com/novlan1/plugin-light"
|
|
21
20
|
},
|
|
21
|
+
"author": "guowangyang",
|
|
22
|
+
"homepage": "https://novlan1.github.io/plugin-light/",
|
|
22
23
|
"bugs": {
|
|
23
|
-
"url": "https://github.com/novlan1/
|
|
24
|
-
},
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public",
|
|
27
|
-
"registry": "https://registry.npmjs.org/"
|
|
28
|
-
},
|
|
29
|
-
"homepage": "https://github.com/novlan1/eslint-plugin-light#readme",
|
|
30
|
-
"scripts": {
|
|
31
|
-
"lint": "eslint --ext .js,.vue .",
|
|
32
|
-
"lint:fix": "eslint --fix --ext .js,.vue .",
|
|
33
|
-
"test": "mocha tests --recursive",
|
|
34
|
-
"create:mr": "node ./script/create-mr.js",
|
|
35
|
-
"release": "npm run release-patch && npm publish",
|
|
36
|
-
"release:first": "standard-version --first-release",
|
|
37
|
-
"release-major": "standard-version --release-as major",
|
|
38
|
-
"release-minor": "standard-version --release-as minor",
|
|
39
|
-
"release-patch": "standard-version --release-as patch"
|
|
24
|
+
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
40
25
|
},
|
|
41
26
|
"dependencies": {
|
|
42
27
|
"requireindex": "^1.2.0"
|
|
@@ -59,5 +44,10 @@
|
|
|
59
44
|
"engines": {
|
|
60
45
|
"node": "12.x || 14.x || >= 16"
|
|
61
46
|
},
|
|
62
|
-
"
|
|
63
|
-
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "echo 0",
|
|
49
|
+
"changelog": "node ../../script/monorepo/changelog $PWD",
|
|
50
|
+
"bump": "node ../../script/monorepo/version-simple $PWD",
|
|
51
|
+
"release": "node ../../script/monorepo/release $PWD"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/lib/configs/base.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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/configs/essential.js
DELETED
package/lib/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const jsParser = require('@babel/eslint-parser');
|
|
4
|
-
|
|
5
|
-
const ROOT_PATH = process.cwd();
|
|
6
|
-
|
|
7
|
-
const VALID_FILES = ['js', 'ts', 'vue'];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 获取引入文件的真实位置,如果是目录,返回目录,如果是文件,返回带后缀的文件
|
|
11
|
-
*/
|
|
12
|
-
function findCompDir(source = '', dirname = '') {
|
|
13
|
-
let compFile;
|
|
14
|
-
if (source.startsWith('.')) {
|
|
15
|
-
compFile = path.resolve(dirname, source);
|
|
16
|
-
} else if (source.startsWith('src')) {
|
|
17
|
-
compFile = path.resolve(process.cwd(), source);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (fs.existsSync(compFile)) {
|
|
21
|
-
return compFile;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < VALID_FILES.length; i++) {
|
|
25
|
-
const postfix = VALID_FILES[i];
|
|
26
|
-
const wholeFileName = `${compFile}.${postfix}`;
|
|
27
|
-
if (fs.existsSync(wholeFileName)) {
|
|
28
|
-
return wholeFileName;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
console.log('\x1B[31m%s\x1B[0m', '未找到引入文件');
|
|
32
|
-
return compFile;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getSourceAST(sourceFile) {
|
|
36
|
-
const jsData = fs.readFileSync(sourceFile, {
|
|
37
|
-
encoding: 'utf-8',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
let scriptAST = undefined;
|
|
41
|
-
|
|
42
|
-
const opts = {
|
|
43
|
-
sourceType: 'module',
|
|
44
|
-
requireConfigFile: false,
|
|
45
|
-
babelOptions: {
|
|
46
|
-
configFile: false,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
scriptAST = jsParser.parse(jsData, opts);
|
|
52
|
-
delete scriptAST.tokens;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
console.log('出错了:', e);
|
|
55
|
-
}
|
|
56
|
-
return scriptAST;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function getDefaultExportComp(ast) {
|
|
61
|
-
if (!ast) return '';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const namedDeclarationNodes = ast.body.filter(item => item.type === 'ExportNamedDeclaration');
|
|
65
|
-
|
|
66
|
-
const namedObj = {};
|
|
67
|
-
// console.log('namedDeclarationNodes',namedDeclarationNodes.length)
|
|
68
|
-
for (let i = 0;i < namedDeclarationNodes.length;i++) {
|
|
69
|
-
const node = namedDeclarationNodes[i];
|
|
70
|
-
// console.log('node',node)
|
|
71
|
-
if (!node.specifiers || !node.specifiers.length) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
// console.log('i',node)
|
|
75
|
-
const { value } = node.source;
|
|
76
|
-
const { name } = node.specifiers[0].exported;
|
|
77
|
-
namedObj[name] = value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// console.log('namedObj', namedObj);
|
|
81
|
-
|
|
82
|
-
if (namedObj.default) {
|
|
83
|
-
return namedObj;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const nodes = ast.body.filter(item => item.type === 'ExportDefaultDeclaration') || [];
|
|
87
|
-
if (nodes[0] && nodes[0].declaration.type === 'Identifier') {
|
|
88
|
-
// 是一个变量,代表从上面导入的
|
|
89
|
-
const { name } = nodes[0].declaration;
|
|
90
|
-
const importAst = ast.body.filter(item => item.type === 'ImportDeclaration' && !!item.specifiers.find(it => it.local.name === name));
|
|
91
|
-
// console.log('importAst', importAst)
|
|
92
|
-
namedObj.default = importAst[0].source.value;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return namedObj;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getRelativePath(originPath = '') {
|
|
99
|
-
return originPath.replace(`${path.resolve(ROOT_PATH)}/`, '');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getDefaultExportPathFromSouceFile(sourceFile) {
|
|
103
|
-
const scriptAST = getSourceAST(sourceFile);
|
|
104
|
-
// console.log('scriptAST', scriptAST)
|
|
105
|
-
|
|
106
|
-
const defaultExportComp = getDefaultExportComp(scriptAST);
|
|
107
|
-
// console.log('defaultExportComp',defaultExportComp)
|
|
108
|
-
if (!defaultExportComp) return;
|
|
109
|
-
|
|
110
|
-
const obj = {};
|
|
111
|
-
const keys = Object.keys(defaultExportComp);
|
|
112
|
-
for (let i = 0;i < keys.length;i++) {
|
|
113
|
-
const name = keys[i];
|
|
114
|
-
const value = defaultExportComp[name];
|
|
115
|
-
const defaultFilePath = findCompDir(value, path.dirname(sourceFile));
|
|
116
|
-
const relativePath = getRelativePath(defaultFilePath);
|
|
117
|
-
obj[name] = relativePath;
|
|
118
|
-
}
|
|
119
|
-
// console.log('defaultFilePath',defaultFilePath)
|
|
120
|
-
|
|
121
|
-
// console.log('relativePath',relativePath)
|
|
122
|
-
return obj;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
function handleError({
|
|
127
|
-
specifiers,
|
|
128
|
-
sourceFile,
|
|
129
|
-
context,
|
|
130
|
-
node: one,
|
|
131
|
-
}) {
|
|
132
|
-
if (!specifiers || !specifiers.length) return;
|
|
133
|
-
const componentList = [];
|
|
134
|
-
let statementString = '\n';
|
|
135
|
-
const relativePath = getDefaultExportPathFromSouceFile(sourceFile);
|
|
136
|
-
|
|
137
|
-
const isJSError = sourceFile.endsWith('.js');
|
|
138
|
-
|
|
139
|
-
for (let i = 0;i < specifiers.length;i++) {
|
|
140
|
-
const specifier = specifiers[i];
|
|
141
|
-
const componentName = specifier.local.name;
|
|
142
|
-
// console.log('componentName', componentName);
|
|
143
|
-
componentList.push(componentName);
|
|
144
|
-
if (relativePath[componentName]) {
|
|
145
|
-
statementString += `import ${componentName} from '${relativePath[componentName]}';\n`;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// console.log('relativePath', relativePath);
|
|
150
|
-
context.report({
|
|
151
|
-
node: one,
|
|
152
|
-
messageId: isJSError ? 'jsError' : 'tsError',
|
|
153
|
-
fix(fixer) {
|
|
154
|
-
/**
|
|
155
|
-
* 默认导入,比如:
|
|
156
|
-
*
|
|
157
|
-
* import BottomTipBarComp from 'xxx';
|
|
158
|
-
*
|
|
159
|
-
*/
|
|
160
|
-
const defaultCompStr = relativePath.default;
|
|
161
|
-
if (defaultCompStr && specifiers.length === 1 && specifiers[0].type === 'ImportDefaultSpecifier') {
|
|
162
|
-
return fixer.replaceTextRange(one.source.range, `'${defaultCompStr}'`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 具名导入,比如:
|
|
167
|
-
* import { xx, yy } from 'xxx';
|
|
168
|
-
*/
|
|
169
|
-
return [
|
|
170
|
-
fixer.insertTextBeforeRange(one.range, statementString),
|
|
171
|
-
fixer.removeRange(one.range),
|
|
172
|
-
];
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
module.exports = {
|
|
178
|
-
meta: {
|
|
179
|
-
type: 'problem',
|
|
180
|
-
schema: [],
|
|
181
|
-
docs: {
|
|
182
|
-
description: '不能从js/ts文件中引入组件',
|
|
183
|
-
},
|
|
184
|
-
fixable: 'code',
|
|
185
|
-
messages: {
|
|
186
|
-
jsError: 'Do not import component from JS file',
|
|
187
|
-
tsError: 'Do not import component from TS file',
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
create(context) {
|
|
192
|
-
// const sourceCode = context.getSourceCode();
|
|
193
|
-
// const cwd = context.getCwd();
|
|
194
|
-
const fileName = context.getFilename();
|
|
195
|
-
|
|
196
|
-
// console.log('cwd', cwd)
|
|
197
|
-
// console.log('fileName', fileName)
|
|
198
|
-
const dirname = path.dirname(fileName);
|
|
199
|
-
// console.log('dirname', dirname);
|
|
200
|
-
if (!fileName.endsWith('.vue')) {
|
|
201
|
-
return {};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
Program: (node) => {
|
|
206
|
-
const exportAst = node.body.find(item => item.type === 'ExportDefaultDeclaration');
|
|
207
|
-
if (!exportAst || !exportAst.declaration) return;
|
|
208
|
-
|
|
209
|
-
const properties = exportAst.declaration.properties || [];
|
|
210
|
-
const componentsNode = properties.find(item => item.key && item.key.name === 'components');
|
|
211
|
-
|
|
212
|
-
// console.log('componentsNode',componentsNode)
|
|
213
|
-
if (!componentsNode || !componentsNode.value
|
|
214
|
-
|| !componentsNode.value.properties
|
|
215
|
-
|| !componentsNode.value.properties.length
|
|
216
|
-
) return;
|
|
217
|
-
const components = componentsNode.value.properties.map(item => ((item.value && item.value.name) || ''));
|
|
218
|
-
|
|
219
|
-
// console.log('components', components);
|
|
220
|
-
|
|
221
|
-
if (!components || !components.length) return;
|
|
222
|
-
|
|
223
|
-
const importAst = node.body.filter(item => item.type === 'ImportDeclaration');
|
|
224
|
-
const realImport = importAst.filter(item => !!item.specifiers.find((it) => {
|
|
225
|
-
const name = (it.imported && it.imported.name) || (it.local && it.local.name);
|
|
226
|
-
return components.includes(name);
|
|
227
|
-
}));
|
|
228
|
-
// console.log('realImport',realImport, realImport.length)
|
|
229
|
-
|
|
230
|
-
for (let i = 0;i < realImport.length;i++) {
|
|
231
|
-
const one = realImport[i];
|
|
232
|
-
const { specifiers } = one;
|
|
233
|
-
const source = one.source.value;
|
|
234
|
-
|
|
235
|
-
if (source.endsWith('.vue')) {
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (source.endsWith('.js') || source.endsWith('.ts')) {
|
|
240
|
-
const compFile = findCompDir(source, dirname);
|
|
241
|
-
|
|
242
|
-
handleError({
|
|
243
|
-
specifiers,
|
|
244
|
-
sourceFile: compFile,
|
|
245
|
-
node: one,
|
|
246
|
-
context,
|
|
247
|
-
});
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const compFile = findCompDir(source, dirname);
|
|
252
|
-
|
|
253
|
-
if (fs.existsSync(compFile)) {
|
|
254
|
-
const stat = fs.lstatSync(compFile);
|
|
255
|
-
if (stat.isDirectory()) {
|
|
256
|
-
const indexJs = path.resolve(compFile, 'index.js');
|
|
257
|
-
const indexTs = path.resolve(compFile, 'index.ts');
|
|
258
|
-
if (fs.existsSync(indexJs)) {
|
|
259
|
-
handleError({
|
|
260
|
-
specifiers,
|
|
261
|
-
sourceFile: indexJs,
|
|
262
|
-
node: one,
|
|
263
|
-
context,
|
|
264
|
-
});
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
if (fs.existsSync(indexTs)) {
|
|
268
|
-
handleError({
|
|
269
|
-
specifiers,
|
|
270
|
-
sourceFile: indexTs,
|
|
271
|
-
node: one,
|
|
272
|
-
context,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
},
|
|
281
|
-
};
|