eslint-plugin-light 1.0.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,174 @@
1
- # Changelog
1
+ ## <small>1.0.4 (2025-04-18)</small>
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.
3
+ * chore: update license ([5ba3e91](https://github.com/novlan1/plugin-light/commits/5ba3e91))
4
+ * chore: update license ([7f6a9d9](https://github.com/novlan1/plugin-light/commits/7f6a9d9))
5
+ * docs: update docs ([f055bcd](https://github.com/novlan1/plugin-light/commits/f055bcd))
6
+ * docs: update docs ([ddced10](https://github.com/novlan1/plugin-light/commits/ddced10))
7
+ * docs: update docs ([761f6c4](https://github.com/novlan1/plugin-light/commits/761f6c4))
8
+ * docs: update docs ([bba000b](https://github.com/novlan1/plugin-light/commits/bba000b))
9
+ * docs: update docs ([34dde24](https://github.com/novlan1/plugin-light/commits/34dde24))
10
+ * refactor: use eslint import/order rule ([41afa85](https://github.com/novlan1/plugin-light/commits/41afa85))
11
+ * feat(eslint): add eslint-config-light ([b7af1f7](https://github.com/novlan1/plugin-light/commits/b7af1f7))
12
+ * feat(eslint): use json-parse-try-catch rule ([eca21da](https://github.com/novlan1/plugin-light/commits/eca21da))
13
+ * ci: update build script ([b7ad1e3](https://github.com/novlan1/plugin-light/commits/b7ad1e3))
4
14
 
5
- ## 1.0.0 (2023-07-12)
15
+
16
+
17
+ ## [1.0.0](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.16...v1.0.0) (2023-07-12)
18
+
19
+
20
+ ### ✨ Features | 新功能
21
+
22
+ * 添加规则不能使用this.tip_uid,但是没有开启 ([d913d2b](https://github.com/novlan1/eslint-plugin-light/commit/d913d2be33aaa44dbb6615f2d4ac98d4a7acebb0))
23
+ * 新增no-import-vant ([c5b8722](https://github.com/novlan1/eslint-plugin-light/commit/c5b87222db44111338cd1d9d4356695efa20cb93))
24
+ * 优化插件 ([505f17f](https://github.com/novlan1/eslint-plugin-light/commit/505f17f2191fdd6a9f32c67d64420ae115909af2))
25
+
26
+
27
+ ### ♻️ Code Refactoring | 代码重构
28
+
29
+ * 插件重命名为light ([21c1dd9](https://github.com/novlan1/eslint-plugin-light/commit/21c1dd93dcd5e31265767cf53121a718826abaad))
30
+
31
+
32
+ ### ✏️ Documentation | 文档
33
+
34
+ * 文档更新 ([4f33c36](https://github.com/novlan1/eslint-plugin-light/commit/4f33c36f40bd8c872c586d05cd6ffbd0d21b5f62))
35
+ * 优化readme ([f0183d0](https://github.com/novlan1/eslint-plugin-light/commit/f0183d0b7cd66af9c47d3e389ccc11c572e1f54a))
36
+
37
+
38
+ ### ✅ Tests | 测试
39
+
40
+ * 测试用例修正 ([70e9f36](https://github.com/novlan1/eslint-plugin-light/commit/70e9f36fdad34b72d94b85c2590bbb06489fd6aa))
41
+
42
+
43
+ ### 🚀 Chore | 构建/工程依赖/工具
44
+
45
+ * 删除无效注释 ([96d5e9d](https://github.com/novlan1/eslint-plugin-light/commit/96d5e9d158c10df93c6f714805eaf8d670d39eeb))
46
+
47
+ ### [0.0.16](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.15...v0.0.16) (2022-07-26)
48
+
49
+
50
+ ### ✨ Features | 新功能
51
+
52
+ * 去掉打印信息 ([bde64c7](https://github.com/novlan1/eslint-plugin-light/commit/bde64c765562f5842aa988ee07d2caac27786a6c))
53
+
54
+ ### [0.0.15](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.14...v0.0.15) (2022-07-26)
55
+
56
+
57
+ ### ✨ Features | 新功能
58
+
59
+ * 优化包 ([906bcd7](https://github.com/novlan1/eslint-plugin-light/commit/906bcd7a2ff0291d331feef961b479135f11c526))
60
+
61
+ ### [0.0.14](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.13...v0.0.14) (2022-07-26)
62
+
63
+
64
+ ### ✨ Features | 新功能
65
+
66
+ * 脚本优化 ([d1e8172](https://github.com/novlan1/eslint-plugin-light/commit/d1e8172ac3777f1377864d3de76a50c55e4122dd))
67
+ * 脚本优化 ([9c6d844](https://github.com/novlan1/eslint-plugin-light/commit/9c6d844aad15475e1af7d97728dfcae84bd99693))
68
+ * **complex-key:** 不要使用复杂的key ([00e981b](https://github.com/novlan1/eslint-plugin-light/commit/00e981b8d81e097576163fa8078a09a315a22cba))
69
+
70
+ ### [0.0.13](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.12...v0.0.13) (2022-07-26)
71
+
72
+
73
+ ### ✨ Features | 新功能
74
+
75
+ * 优化脚本 ([ad9b142](https://github.com/novlan1/eslint-plugin-light/commit/ad9b142ee87aba73d45adcef3aa94ac3d5988b31))
76
+
77
+ ### [0.0.12](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.11...v0.0.12) (2022-07-26)
78
+
79
+
80
+ ### ✨ Features | 新功能
81
+
82
+ * 脚本优化 ([62f1181](https://github.com/novlan1/eslint-plugin-light/commit/62f11815bb458201991cca99716e773a3281c65b))
83
+
84
+ ### [0.0.11](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.10...v0.0.11) (2022-07-26)
85
+
86
+
87
+ ### ✨ Features | 新功能
88
+
89
+ * 脚本优化 ([3047f01](https://github.com/novlan1/eslint-plugin-light/commit/3047f01b89fdbdb8c72b0c5e511afb587d8ffc99))
90
+ * 优化发布脚本 ([a072ae8](https://github.com/novlan1/eslint-plugin-light/commit/a072ae8715352c9452072e8dfa9c85a343cf4f26))
91
+
92
+ ### [0.0.10](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.9...v0.0.10) (2022-07-26)
93
+
94
+
95
+ ### ✨ Features | 新功能
96
+
97
+ * 优化发布脚本 ([470a35f](https://github.com/novlan1/eslint-plugin-light/commit/470a35fc55153d41a362cf61492fde120a9ed3f7))
98
+ * 优化error信息 ([453430f](https://github.com/novlan1/eslint-plugin-light/commit/453430ff437d062cd1efa7bff96b87e975b2b414))
99
+
100
+ ### [0.0.9](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.8...v0.0.9) (2022-07-22)
101
+
102
+
103
+ ### ✨ Features | 新功能
104
+
105
+ * 优化插件 ([13a84d5](https://github.com/novlan1/eslint-plugin-light/commit/13a84d5ce25788f5d3b3b63b84a0731f179ff12d))
106
+
107
+
108
+ ### ✏️ Documentation | 文档
109
+
110
+ * 用法更新 ([78e344d](https://github.com/novlan1/eslint-plugin-light/commit/78e344d61c026f7c38960d41d7038888664ecb85))
111
+
112
+ ### [0.0.8](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.7...v0.0.8) (2022-07-22)
113
+
114
+
115
+ ### ✏️ Documentation | 文档
116
+
117
+ * 更新文档 ([d6e3a23](https://github.com/novlan1/eslint-plugin-light/commit/d6e3a23205244f41ecb8b8fff3bb9d9a07a2c734))
118
+
119
+
120
+ ### 🚀 Chore | 构建/工程依赖/工具
121
+
122
+ * eslint ([63e2398](https://github.com/novlan1/eslint-plugin-light/commit/63e2398387b466c4e188a7f12a2d08586583f527))
123
+
124
+
125
+ ### ✨ Features | 新功能
126
+
127
+ * **number:** 优化插件 ([003f290](https://github.com/novlan1/eslint-plugin-light/commit/003f290563b15d4cc1e8a6585a629bbfba2fce1e))
128
+
129
+ ### [0.0.7](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.6...v0.0.7) (2022-07-22)
130
+
131
+
132
+ ### ✏️ Documentation | 文档
133
+
134
+ * 文档优化 ([e7f5bfb](https://github.com/novlan1/eslint-plugin-light/commit/e7f5bfb9e67ac3f7cb9ea182200886feb22c9798))
135
+ * 优化文档 ([44e7b1e](https://github.com/novlan1/eslint-plugin-light/commit/44e7b1e5f5e230363dcfd6923d325e96db9509f4))
136
+
137
+
138
+ ### ✨ Features | 新功能
139
+
140
+ * **no-plus-turn-number:** 转化+字符串 ([aa69796](https://github.com/novlan1/eslint-plugin-light/commit/aa69796620c554d745c2b5133b9699c9be363805))
141
+
142
+ ### [0.0.6](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.5...v0.0.6) (2022-07-22)
143
+
144
+
145
+ ### ✨ Features | 新功能
146
+
147
+ * 优化插件 ([c0e28fd](https://github.com/novlan1/eslint-plugin-light/commit/c0e28fda4d5ba7c6c90a0ad7fe799342b79e9b49))
148
+
149
+ ### [0.0.5](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.4...v0.0.5) (2022-07-22)
150
+
151
+ ### [0.0.4](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.3...v0.0.4) (2022-07-22)
152
+
153
+
154
+ ### 🐛 Bug Fixes | Bug 修复
155
+
156
+ * 兼容性处理 ([ba123c2](https://github.com/novlan1/eslint-plugin-light/commit/ba123c26093d66008e459cdc3bfaf5fea74588e1))
157
+
158
+ ### [0.0.3](https://github.com/novlan1/eslint-plugin-light/compare/v0.0.2...v0.0.3) (2022-07-22)
159
+
160
+
161
+ ### 🚀 Chore | 构建/工程依赖/工具
162
+
163
+ * 增加versionrc ([1a8b239](https://github.com/novlan1/eslint-plugin-light/commit/1a8b2393618cbb16003298a1ec5e8b9bf44fb779))
164
+ * version ([dda6406](https://github.com/novlan1/eslint-plugin-light/commit/dda640604dd0bd34bf8937692781edd95b99d6ed))
165
+
166
+ ### 0.0.2 (2022-07-22)
167
+
168
+
169
+ ### Features
170
+
171
+ * 安装version ([a295b91](https://github.com/novlan1/eslint-plugin-light/commit/a295b91936a3eaeeda3bbc53d3221d0c0ee4c6f8))
172
+ * 优化插件 ([803d743](https://github.com/novlan1/eslint-plugin-light/commit/803d7434d653776dd70d0ec85b8eb0c20bdbc578))
173
+ * init ([44f3cb3](https://github.com/novlan1/eslint-plugin-light/commit/44f3cb326e7fca1b4b4b54ec8f361b491b84f996))
174
+ * 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,23 +1,32 @@
1
- # eslint-plugin-light
1
+ ## ESLint Plugin Light
2
2
 
3
- Eslint plugin.
4
3
 
4
+ <p align="center">
5
+ <img src="https://img.shields.io/npm/dw/eslint-plugin-light">
6
+ <img src="https://img.shields.io/npm/unpacked-size/eslint-plugin-light">
7
+ <img src="https://img.shields.io/npm/v/eslint-plugin-light">
8
+ <img src="https://img.shields.io/npm/l/eslint-plugin-light">
9
+ <img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
10
+ <img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
11
+ </p>
5
12
 
6
- ## 1. Installation
13
+ Simple Eslint plugin.
7
14
 
8
- You'll first need to install [ESLint](https://eslint.org/):
15
+ ### 1. Installation
16
+
17
+ You need to install [ESLint](https://eslint.org/) first.
9
18
 
10
19
  ```sh
11
- npm i eslint --save-dev
20
+ npm i eslint -D
12
21
  ```
13
22
 
14
- Next, install `eslint-plugin-light`:
23
+ Next, install `eslint-plugin-light`.
15
24
 
16
25
  ```sh
17
- npm install eslint-plugin-light --save-dev
26
+ npm i eslint-plugin-light -D
18
27
  ```
19
28
 
20
- ## 2. Usage
29
+ ### 2. Usage
21
30
 
22
31
  Add `light` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
23
32
 
@@ -49,9 +58,9 @@ or use extends:
49
58
  ```
50
59
 
51
60
 
52
- ## 3. Supported Rules
61
+ ### 3. Supported Rules
53
62
 
54
- ### 3.1. light/valid-vue-comp-import
63
+ #### 3.1. light/valid-vue-comp-import
55
64
 
56
65
  禁止从`js`文件中加载`Vue`组件
57
66
 
@@ -67,7 +76,7 @@ import SomeComp from 'src/local-component/ui/pages/user/account-manage/index.js'
67
76
  import SomeComp from 'src/local-component/ui/pages/user/account-manage/index';
68
77
  ```
69
78
 
70
- 如果加了`--fix`,会被转换为:
79
+ 如果加了 `--fix`,会被转换为:
71
80
 
72
81
  ```js
73
82
  import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
@@ -109,7 +118,7 @@ import CComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
109
118
  import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/d.vue';
110
119
  ```
111
120
 
112
- ### 3.2. light/no-plus-turn-number
121
+ #### 3.2. light/no-plus-turn-number
113
122
 
114
123
  禁止在`vue`的`template`中用`+`号转换字符串为数字
115
124
 
@@ -129,7 +138,7 @@ import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-
129
138
  />
130
139
  ```
131
140
 
132
- ### 3.3 no-complex-key
141
+ #### 3.3 no-complex-key
133
142
 
134
143
  不要在`vue`模板中使用复杂的`key`。包括:
135
144
 
@@ -167,3 +176,30 @@ getData() {
167
176
  ```
168
177
 
169
178
  `uni-app`中,`key`重复的话,会造成挂载在组件上面的事件参数为`undefined`,从而不成功。
179
+
180
+
181
+ #### 3.4 json-parse-try-catch
182
+
183
+ `JSON.parse` 应该加 `try catch`。
184
+
185
+ 默认配置会排除下面情况:
186
+
187
+ ```ts
188
+ JSON.parse(JSON.stringify(abc));
189
+ ```
190
+
191
+ 可以配置 `strict` 参数为 `true`,开启检查。
192
+
193
+
194
+ ```js
195
+ // .eslintrc.js
196
+
197
+ module.exports = {
198
+ plugins: [
199
+ 'light',
200
+ ],
201
+ rules: {
202
+ 'light/json-parse-try-catch': [2, { strict: true }],
203
+ },
204
+ }
205
+ ```
@@ -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
+
@@ -1,5 +1,6 @@
1
- const path = require('path');
2
1
  const fs = require('fs');
2
+ const path = require('path');
3
+
3
4
  const jsParser = require('@babel/eslint-parser');
4
5
 
5
6
  const ROOT_PATH = process.cwd();
package/package.json CHANGED
@@ -1,50 +1,32 @@
1
1
  {
2
2
  "name": "eslint-plugin-light",
3
- "version": "1.0.0",
4
- "description": "eslint插件",
3
+ "version": "1.0.4",
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
- "author": "GuoWangYang",
17
- "main": "lib/index.js",
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/novlan1/eslint-plugin-light"
21
- },
22
- "bugs": {
23
- "url": "https://github.com/novlan1/eslint-plugin-light/issues"
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"
40
- },
41
27
  "dependencies": {
42
28
  "requireindex": "^1.2.0"
43
29
  },
44
- "peerDependencies": {
45
- "eslint": ">=6",
46
- "@babel/eslint-parser": ">=6"
47
- },
48
30
  "devDependencies": {
49
31
  "@babel/core": "^7.18.9",
50
32
  "@babel/eslint-parser": "^7.18.9",
@@ -56,8 +38,17 @@
56
38
  "mocha": "^9.1.3",
57
39
  "standard-version": "^9.5.0"
58
40
  },
41
+ "peerDependencies": {
42
+ "@babel/eslint-parser": ">=6",
43
+ "eslint": ">=6"
44
+ },
59
45
  "engines": {
60
46
  "node": "12.x || 14.x || >= 16"
61
47
  },
62
- "license": "ISC"
63
- }
48
+ "scripts": {
49
+ "build": "rm -rf lib && node script/build",
50
+ "bump": "node ../../script/monorepo/version-simple $PWD",
51
+ "changelog": "node ../../script/monorepo/changelog $PWD",
52
+ "release": "node ../../script/monorepo/release $PWD"
53
+ }
54
+ }