mm_eslint 1.0.1 → 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/README.md +149 -32
- package/README_EN.md +146 -29
- package/index.js +1899 -608
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -10,16 +10,20 @@
|
|
|
10
10
|
- ✅ **变量名检测** - 小写蛇形命名法(snake_case)
|
|
11
11
|
- ✅ **常量名检测** - 大写蛇形命名法(UPPER_SNAKE_CASE)
|
|
12
12
|
- ✅ **私有成员检测** - 下划线开头的小写蛇形命名
|
|
13
|
+
- ✅ **入参名检测** - 小写蛇形命名法(snake_case)
|
|
14
|
+
- ✅ **属性名检测** - 基于值类型的多风格命名
|
|
13
15
|
- ✅ **长度限制** - 所有命名长度限制在1-20字符
|
|
14
16
|
- ✅ **单个单词优先** - 鼓励使用单个单词命名
|
|
17
|
+
- ✅ **单词长度限制** - 每个单词限制在最大8字符
|
|
15
18
|
- ✅ **禁止废话词** - 避免使用Manager、Handler等冗余词汇
|
|
19
|
+
- ✅ **JSDoc支持** - 集成JSDoc文档要求
|
|
16
20
|
|
|
17
21
|
## 安装
|
|
18
22
|
|
|
19
23
|
### npm安装
|
|
20
24
|
|
|
21
25
|
```bash
|
|
22
|
-
npm install
|
|
26
|
+
npm install mm_eslint --save-dev
|
|
23
27
|
```
|
|
24
28
|
|
|
25
29
|
### 本地安装
|
|
@@ -28,34 +32,102 @@ npm install mm-eslint-plugin --save-dev
|
|
|
28
32
|
|
|
29
33
|
```bash
|
|
30
34
|
# 复制插件文件到您的项目
|
|
31
|
-
cp
|
|
35
|
+
cp mm_eslint/index.js your-project/eslint-plugins/
|
|
32
36
|
```
|
|
33
37
|
|
|
34
38
|
## 快速开始
|
|
35
39
|
|
|
36
|
-
### 1.
|
|
40
|
+
### 1. 完整配置
|
|
37
41
|
|
|
38
42
|
在您的ESLint配置文件中引入插件:
|
|
39
43
|
|
|
40
44
|
```javascript
|
|
41
45
|
// eslint.config.js
|
|
42
|
-
const namingConventionPlugin = require(
|
|
46
|
+
const namingConventionPlugin = require("mm_eslint");
|
|
43
47
|
|
|
44
48
|
module.exports = [
|
|
45
49
|
{
|
|
46
|
-
files: [
|
|
50
|
+
files: ["**/*.js"],
|
|
47
51
|
plugins: {
|
|
48
|
-
|
|
52
|
+
"naming-convention": namingConventionPlugin,
|
|
53
|
+
jsdoc: require("eslint-plugin-jsdoc"),
|
|
49
54
|
},
|
|
50
55
|
rules: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
// 自定义命名规范插件规则(优先使用)
|
|
57
|
+
"naming-convention/class-name": "error",
|
|
58
|
+
"naming-convention/function-name": "error",
|
|
59
|
+
"naming-convention/method-name": "error",
|
|
60
|
+
"naming-convention/variable-name": "warn",
|
|
61
|
+
"naming-convention/constant-name": "error",
|
|
62
|
+
"naming-convention/private-naming": "warn",
|
|
63
|
+
"naming-convention/param-name": "warn",
|
|
64
|
+
"naming-convention/property-name": "warn",
|
|
65
|
+
|
|
66
|
+
// 禁用与命名规范插件冲突的默认规则
|
|
67
|
+
camelcase: "off",
|
|
68
|
+
"id-match": "off",
|
|
69
|
+
"new-cap": "off",
|
|
70
|
+
"id-length": "off",
|
|
71
|
+
"id-denylist": "off",
|
|
72
|
+
"id-blacklist": "off",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
// 代码风格规则
|
|
78
|
+
rules: {
|
|
79
|
+
"max-len": ["error", { code: 100 }],
|
|
80
|
+
indent: ["error", 2],
|
|
81
|
+
quotes: ["error", "single"],
|
|
82
|
+
"no-tabs": "error",
|
|
83
|
+
semi: ["error", "always"],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
// 错误处理规则
|
|
89
|
+
rules: {
|
|
90
|
+
"no-unused-vars": ["error", { args: "all" }],
|
|
91
|
+
"no-unsafe-finally": "warn",
|
|
92
|
+
"no-throw-literal": "error",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
{
|
|
97
|
+
// 最佳实践规则
|
|
98
|
+
rules: {
|
|
99
|
+
"prefer-promise-reject-errors": "error",
|
|
100
|
+
"no-param-reassign": "error",
|
|
101
|
+
"prefer-object-spread": "error",
|
|
102
|
+
"prefer-arrow-callback": "error",
|
|
103
|
+
"max-lines-per-function": ["warn", { max: 40 }],
|
|
104
|
+
complexity: ["warn", 10],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
// JSDoc规则
|
|
110
|
+
rules: {
|
|
111
|
+
"jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
|
|
112
|
+
"jsdoc/check-alignment": "warn",
|
|
113
|
+
"jsdoc/check-indentation": "warn",
|
|
114
|
+
"jsdoc/check-param-names": "warn",
|
|
115
|
+
"jsdoc/check-syntax": "warn",
|
|
116
|
+
"jsdoc/check-tag-names": "warn",
|
|
117
|
+
"jsdoc/check-types": "warn",
|
|
118
|
+
"jsdoc/no-undefined-types": "warn",
|
|
119
|
+
"jsdoc/require-description": "warn",
|
|
120
|
+
"jsdoc/require-param": "warn",
|
|
121
|
+
"jsdoc/require-param-description": "warn",
|
|
122
|
+
"jsdoc/require-param-name": "warn",
|
|
123
|
+
"jsdoc/require-param-type": "warn",
|
|
124
|
+
"jsdoc/require-returns": "warn",
|
|
125
|
+
"jsdoc/require-returns-check": "warn",
|
|
126
|
+
"jsdoc/require-returns-description": "warn",
|
|
127
|
+
"jsdoc/require-returns-type": "warn",
|
|
128
|
+
"jsdoc/valid-types": "warn",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
59
131
|
];
|
|
60
132
|
```
|
|
61
133
|
|
|
@@ -75,37 +147,44 @@ npx eslint --fix your-file.js
|
|
|
75
147
|
## 命名规范规则
|
|
76
148
|
|
|
77
149
|
### 类名规则(class-name)
|
|
150
|
+
|
|
78
151
|
- **级别**: error
|
|
79
152
|
- **要求**: 大驼峰命名法(PascalCase)
|
|
80
153
|
- **长度**: 1-20字符
|
|
81
|
-
-
|
|
82
|
-
-
|
|
154
|
+
- **单词长度**: 每个单词≤8字符
|
|
155
|
+
- **示例**: `User`, `Product`
|
|
156
|
+
- **错误示例**: `UserConfiguration`, `ProductManagement`
|
|
83
157
|
|
|
84
158
|
### 函数名规则(function-name)
|
|
159
|
+
|
|
85
160
|
- **级别**: error
|
|
86
161
|
- **要求**: 小驼峰命名法(camelCase)
|
|
87
162
|
- **长度**: 1-20字符
|
|
163
|
+
- **单词长度**: 每个单词≤8字符
|
|
88
164
|
- **优先**: 单个单词
|
|
89
|
-
- **示例**: `
|
|
90
|
-
- **错误示例**: `
|
|
165
|
+
- **示例**: `get`, `getName`, `process`
|
|
166
|
+
- **错误示例**: `getConfiguration`, `processInformation`
|
|
91
167
|
|
|
92
168
|
### 方法名规则(method-name)
|
|
169
|
+
|
|
93
170
|
- **级别**: error
|
|
94
171
|
- **要求**: 小驼峰命名法(camelCase)
|
|
95
172
|
- **长度**: 1-20字符
|
|
173
|
+
- **单词长度**: 每个单词≤8字符
|
|
96
174
|
- **优先**: 单个单词
|
|
97
|
-
- **示例**: `
|
|
98
|
-
- **错误示例**: `
|
|
175
|
+
- **示例**: `add`, `setName`, `isValid`
|
|
176
|
+
- **错误示例**: `addConfiguration`, `validateAuthentication`
|
|
99
177
|
|
|
100
178
|
### 变量名规则(variable-name)
|
|
179
|
+
|
|
101
180
|
- **级别**: warn
|
|
102
181
|
- **要求**: 小写蛇形命名法(snake_case)
|
|
103
182
|
- **长度**: 1-20字符
|
|
104
|
-
- **优先**: 单个单词
|
|
105
183
|
- **示例**: `user_count`, `max_retry`
|
|
106
184
|
- **错误示例**: `userCount`, `MAX_RETRY`
|
|
107
185
|
|
|
108
186
|
### 常量名规则(constant-name)
|
|
187
|
+
|
|
109
188
|
- **级别**: error
|
|
110
189
|
- **要求**: 大写蛇形命名法(UPPER_SNAKE_CASE)
|
|
111
190
|
- **长度**: 1-20字符
|
|
@@ -113,28 +192,48 @@ npx eslint --fix your-file.js
|
|
|
113
192
|
- **错误示例**: `maxRetry`, `defaultTimeout`
|
|
114
193
|
|
|
115
194
|
### 私有成员规则(private-naming)
|
|
195
|
+
|
|
116
196
|
- **级别**: warn
|
|
117
197
|
- **要求**: 下划线开头的小写蛇形命名
|
|
118
198
|
- **长度**: 2-20字符
|
|
119
199
|
- **示例**: `_user_count`, `_internal_data`
|
|
120
200
|
- **错误示例**: `userCount`, `_UserCount`
|
|
121
201
|
|
|
202
|
+
### 入参名规则(param-name)
|
|
203
|
+
|
|
204
|
+
- **级别**: warn
|
|
205
|
+
- **要求**: 小写蛇形命名法(snake_case)
|
|
206
|
+
- **长度**: 1-20字符
|
|
207
|
+
- **示例**: `user_name`, `max_count`
|
|
208
|
+
- **错误示例**: `userName`, `maxCount`
|
|
209
|
+
|
|
210
|
+
### 属性名规则(property-name)
|
|
211
|
+
|
|
212
|
+
- **级别**: warn
|
|
213
|
+
- **要求**: 基于值类型的多风格命名
|
|
214
|
+
- **长度**: 1-20字符
|
|
215
|
+
- **示例**: `user_name`(字符串), `getUser`(函数), `User`(类)
|
|
216
|
+
|
|
122
217
|
## 错误示例
|
|
123
218
|
|
|
124
219
|
```javascript
|
|
125
220
|
// ❌ 错误的命名示例
|
|
126
|
-
class
|
|
127
|
-
const
|
|
221
|
+
class UserConfiguration { // "Configuration"超过8字符
|
|
222
|
+
const getConfiguration = function() {}; // "Configuration"超过8字符
|
|
128
223
|
let maxRetryCount = 5; // 变量名应该小写蛇形
|
|
129
224
|
const userCount = 10; // 常量名应该大写蛇形
|
|
130
225
|
|
|
131
226
|
// ✅ 正确的命名示例
|
|
132
|
-
class
|
|
227
|
+
class User {
|
|
133
228
|
constructor() {
|
|
134
229
|
this._user_count = 0; // 私有属性正确
|
|
135
230
|
}
|
|
136
|
-
|
|
137
|
-
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 获取用户数量
|
|
234
|
+
* @returns {number} 用户数量
|
|
235
|
+
*/
|
|
236
|
+
get() { // 方法名正确(单个单词≤8字符)
|
|
138
237
|
return this._user_count;
|
|
139
238
|
}
|
|
140
239
|
}
|
|
@@ -143,6 +242,15 @@ const MAX_RETRY = 5; // 常量名正确
|
|
|
143
242
|
let user_count = 10; // 变量名正确
|
|
144
243
|
```
|
|
145
244
|
|
|
245
|
+
## 单词长度验证
|
|
246
|
+
|
|
247
|
+
插件验证复合名称中的每个单词不超过8个字符:
|
|
248
|
+
|
|
249
|
+
- **有效**: `UserService`("User"=4, "Service"=7)
|
|
250
|
+
- **无效**: `UserConfiguration`("Configuration"=13 > 8)
|
|
251
|
+
- **有效**: `getUser`("get"=3, "User"=4)
|
|
252
|
+
- **无效**: `getConfiguration`("Configuration"=13 > 8)
|
|
253
|
+
|
|
146
254
|
## 配置选项
|
|
147
255
|
|
|
148
256
|
您可以通过配置自定义规则参数:
|
|
@@ -150,12 +258,13 @@ let user_count = 10; // 变量名正确
|
|
|
150
258
|
```javascript
|
|
151
259
|
// 自定义配置示例
|
|
152
260
|
const customConfig = {
|
|
153
|
-
|
|
261
|
+
"class-name": {
|
|
154
262
|
regex: /^[A-Z][a-zA-Z]*$/,
|
|
155
263
|
min: 1,
|
|
156
|
-
max: 25,
|
|
157
|
-
|
|
158
|
-
|
|
264
|
+
max: 25, // 扩展最大长度
|
|
265
|
+
single_word_len: 10, // 扩展单词长度限制
|
|
266
|
+
message: "类名{name}必须使用大驼峰命名法",
|
|
267
|
+
},
|
|
159
268
|
};
|
|
160
269
|
|
|
161
270
|
const detector = new NamingDetector(customConfig);
|
|
@@ -166,7 +275,7 @@ const detector = new NamingDetector(customConfig);
|
|
|
166
275
|
### 项目结构
|
|
167
276
|
|
|
168
277
|
```
|
|
169
|
-
|
|
278
|
+
mm_eslint/
|
|
170
279
|
├── index.js # 主插件文件
|
|
171
280
|
├── package.json # npm配置
|
|
172
281
|
├── eslint.config.js # ESLint配置
|
|
@@ -195,8 +304,16 @@ ISC License
|
|
|
195
304
|
|
|
196
305
|
## 更新日志
|
|
197
306
|
|
|
307
|
+
### v1.1.0
|
|
308
|
+
|
|
309
|
+
- 添加单词长度验证(每个单词最大8字符)
|
|
310
|
+
- 添加入参名和属性名检测
|
|
311
|
+
- 集成JSDoc文档要求
|
|
312
|
+
- 增强配置,包含完整的ESLint规则
|
|
313
|
+
|
|
198
314
|
### v1.0.0
|
|
315
|
+
|
|
199
316
|
- 初始版本发布
|
|
200
317
|
- 支持类名、函数名、方法名、变量名、常量名、私有成员命名规范检测
|
|
201
318
|
- 支持长度限制和单个单词优先规则
|
|
202
|
-
- 支持禁止废话词检测
|
|
319
|
+
- 支持禁止废话词检测
|
package/README_EN.md
CHANGED
|
@@ -10,9 +10,13 @@ An ESLint plugin based on personal naming conventions, supporting naming convent
|
|
|
10
10
|
- ✅ **Variable Name Detection** - snake_case naming convention
|
|
11
11
|
- ✅ **Constant Name Detection** - UPPER_SNAKE_CASE naming convention
|
|
12
12
|
- ✅ **Private Member Detection** - underscore-prefixed snake_case naming
|
|
13
|
+
- ✅ **Parameter Name Detection** - snake_case naming convention
|
|
14
|
+
- ✅ **Property Name Detection** - Multi-style naming based on value type
|
|
13
15
|
- ✅ **Length Restrictions** - All names limited to 1-20 characters
|
|
14
16
|
- ✅ **Single Word Preferred** - Encourages single word naming
|
|
17
|
+
- ✅ **Word Length Limit** - Each word limited to maximum 8 characters
|
|
15
18
|
- ✅ **Forbidden Words** - Avoids redundant words like Manager, Handler, etc.
|
|
19
|
+
- ✅ **JSDoc Support** - Integrated JSDoc documentation requirements
|
|
16
20
|
|
|
17
21
|
## Installation
|
|
18
22
|
|
|
@@ -33,29 +37,97 @@ cp mm-eslint-plugin/index.js your-project/eslint-plugins/
|
|
|
33
37
|
|
|
34
38
|
## Quick Start
|
|
35
39
|
|
|
36
|
-
### 1.
|
|
40
|
+
### 1. Complete Configuration
|
|
37
41
|
|
|
38
42
|
Import the plugin in your ESLint configuration file:
|
|
39
43
|
|
|
40
44
|
```javascript
|
|
41
45
|
// eslint.config.js
|
|
42
|
-
const namingConventionPlugin = require(
|
|
46
|
+
const namingConventionPlugin = require("mm-eslint-plugin");
|
|
43
47
|
|
|
44
48
|
module.exports = [
|
|
45
49
|
{
|
|
46
|
-
files: [
|
|
50
|
+
files: ["**/*.js"],
|
|
47
51
|
plugins: {
|
|
48
|
-
|
|
52
|
+
"naming-convention": namingConventionPlugin,
|
|
53
|
+
jsdoc: require("eslint-plugin-jsdoc"),
|
|
49
54
|
},
|
|
50
55
|
rules: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
// Custom naming convention rules (priority)
|
|
57
|
+
"naming-convention/class-name": "error",
|
|
58
|
+
"naming-convention/function-name": "error",
|
|
59
|
+
"naming-convention/method-name": "error",
|
|
60
|
+
"naming-convention/variable-name": "warn",
|
|
61
|
+
"naming-convention/constant-name": "error",
|
|
62
|
+
"naming-convention/private-naming": "warn",
|
|
63
|
+
"naming-convention/param-name": "warn",
|
|
64
|
+
"naming-convention/property-name": "warn",
|
|
65
|
+
|
|
66
|
+
// Disable conflicting default rules
|
|
67
|
+
camelcase: "off",
|
|
68
|
+
"id-match": "off",
|
|
69
|
+
"new-cap": "off",
|
|
70
|
+
"id-length": "off",
|
|
71
|
+
"id-denylist": "off",
|
|
72
|
+
"id-blacklist": "off",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
// Code style rules
|
|
78
|
+
rules: {
|
|
79
|
+
"max-len": ["error", { code: 100 }],
|
|
80
|
+
indent: ["error", 2],
|
|
81
|
+
quotes: ["error", "single"],
|
|
82
|
+
"no-tabs": "error",
|
|
83
|
+
semi: ["error", "always"],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
// Error handling rules
|
|
89
|
+
rules: {
|
|
90
|
+
"no-unused-vars": ["error", { args: "all" }],
|
|
91
|
+
"no-unsafe-finally": "warn",
|
|
92
|
+
"no-throw-literal": "error",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
{
|
|
97
|
+
// Best practices
|
|
98
|
+
rules: {
|
|
99
|
+
"prefer-promise-reject-errors": "error",
|
|
100
|
+
"no-param-reassign": "error",
|
|
101
|
+
"prefer-object-spread": "error",
|
|
102
|
+
"prefer-arrow-callback": "error",
|
|
103
|
+
"max-lines-per-function": ["warn", { max: 40 }],
|
|
104
|
+
complexity: ["warn", 10],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
// JSDoc rules
|
|
110
|
+
rules: {
|
|
111
|
+
"jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
|
|
112
|
+
"jsdoc/check-alignment": "warn",
|
|
113
|
+
"jsdoc/check-indentation": "warn",
|
|
114
|
+
"jsdoc/check-param-names": "warn",
|
|
115
|
+
"jsdoc/check-syntax": "warn",
|
|
116
|
+
"jsdoc/check-tag-names": "warn",
|
|
117
|
+
"jsdoc/check-types": "warn",
|
|
118
|
+
"jsdoc/no-undefined-types": "warn",
|
|
119
|
+
"jsdoc/require-description": "warn",
|
|
120
|
+
"jsdoc/require-param": "warn",
|
|
121
|
+
"jsdoc/require-param-description": "warn",
|
|
122
|
+
"jsdoc/require-param-name": "warn",
|
|
123
|
+
"jsdoc/require-param-type": "warn",
|
|
124
|
+
"jsdoc/require-returns": "warn",
|
|
125
|
+
"jsdoc/require-returns-check": "warn",
|
|
126
|
+
"jsdoc/require-returns-description": "warn",
|
|
127
|
+
"jsdoc/require-returns-type": "warn",
|
|
128
|
+
"jsdoc/valid-types": "warn",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
59
131
|
];
|
|
60
132
|
```
|
|
61
133
|
|
|
@@ -75,37 +147,44 @@ npx eslint --fix your-file.js
|
|
|
75
147
|
## Naming Convention Rules
|
|
76
148
|
|
|
77
149
|
### Class Name Rule (class-name)
|
|
150
|
+
|
|
78
151
|
- **Level**: error
|
|
79
152
|
- **Requirement**: PascalCase naming convention
|
|
80
153
|
- **Length**: 1-20 characters
|
|
81
|
-
- **
|
|
82
|
-
- **
|
|
154
|
+
- **Word Length**: Each word ≤8 characters
|
|
155
|
+
- **Examples**: `User`, `Product`
|
|
156
|
+
- **Invalid Examples**: `UserConfiguration`, `ProductManagement`
|
|
83
157
|
|
|
84
158
|
### Function Name Rule (function-name)
|
|
159
|
+
|
|
85
160
|
- **Level**: error
|
|
86
161
|
- **Requirement**: camelCase naming convention
|
|
87
162
|
- **Length**: 1-20 characters
|
|
163
|
+
- **Word Length**: Each word ≤8 characters
|
|
88
164
|
- **Preference**: Single word
|
|
89
|
-
- **Examples**: `
|
|
90
|
-
- **Invalid Examples**: `
|
|
165
|
+
- **Examples**: `get`, `getName`, `process`
|
|
166
|
+
- **Invalid Examples**: `getConfiguration`, `processInformation`
|
|
91
167
|
|
|
92
168
|
### Method Name Rule (method-name)
|
|
169
|
+
|
|
93
170
|
- **Level**: error
|
|
94
171
|
- **Requirement**: camelCase naming convention
|
|
95
172
|
- **Length**: 1-20 characters
|
|
173
|
+
- **Word Length**: Each word ≤8 characters
|
|
96
174
|
- **Preference**: Single word
|
|
97
|
-
- **Examples**: `
|
|
98
|
-
- **Invalid Examples**: `
|
|
175
|
+
- **Examples**: `add`, `setName`, `isValid`
|
|
176
|
+
- **Invalid Examples**: `addConfiguration`, `validateAuthentication`
|
|
99
177
|
|
|
100
178
|
### Variable Name Rule (variable-name)
|
|
179
|
+
|
|
101
180
|
- **Level**: warn
|
|
102
181
|
- **Requirement**: snake_case naming convention
|
|
103
182
|
- **Length**: 1-20 characters
|
|
104
|
-
- **Preference**: Single word
|
|
105
183
|
- **Examples**: `user_count`, `max_retry`
|
|
106
184
|
- **Invalid Examples**: `userCount`, `MAX_RETRY`
|
|
107
185
|
|
|
108
186
|
### Constant Name Rule (constant-name)
|
|
187
|
+
|
|
109
188
|
- **Level**: error
|
|
110
189
|
- **Requirement**: UPPER_SNAKE_CASE naming convention
|
|
111
190
|
- **Length**: 1-20 characters
|
|
@@ -113,28 +192,48 @@ npx eslint --fix your-file.js
|
|
|
113
192
|
- **Invalid Examples**: `maxRetry`, `defaultTimeout`
|
|
114
193
|
|
|
115
194
|
### Private Member Rule (private-naming)
|
|
195
|
+
|
|
116
196
|
- **Level**: warn
|
|
117
197
|
- **Requirement**: underscore-prefixed snake_case naming
|
|
118
198
|
- **Length**: 2-20 characters
|
|
119
199
|
- **Examples**: `_user_count`, `_internal_data`
|
|
120
200
|
- **Invalid Examples**: `userCount`, `_UserCount`
|
|
121
201
|
|
|
202
|
+
### Parameter Name Rule (param-name)
|
|
203
|
+
|
|
204
|
+
- **Level**: warn
|
|
205
|
+
- **Requirement**: snake_case naming convention
|
|
206
|
+
- **Length**: 1-20 characters
|
|
207
|
+
- **Examples**: `user_name`, `max_count`
|
|
208
|
+
- **Invalid Examples**: `userName`, `maxCount`
|
|
209
|
+
|
|
210
|
+
### Property Name Rule (property-name)
|
|
211
|
+
|
|
212
|
+
- **Level**: warn
|
|
213
|
+
- **Requirement**: Multi-style naming based on value type
|
|
214
|
+
- **Length**: 1-20 characters
|
|
215
|
+
- **Examples**: `user_name` (string), `getUser` (function), `User` (class)
|
|
216
|
+
|
|
122
217
|
## Error Examples
|
|
123
218
|
|
|
124
219
|
```javascript
|
|
125
220
|
// ❌ Invalid naming examples
|
|
126
|
-
class
|
|
127
|
-
const
|
|
221
|
+
class UserConfiguration { // "Configuration" exceeds 8 characters
|
|
222
|
+
const getConfiguration = function() {}; // "Configuration" exceeds 8 characters
|
|
128
223
|
let maxRetryCount = 5; // Variable name should be snake_case
|
|
129
224
|
const userCount = 10; // Constant name should be UPPER_SNAKE_CASE
|
|
130
225
|
|
|
131
226
|
// ✅ Correct naming examples
|
|
132
|
-
class
|
|
227
|
+
class User {
|
|
133
228
|
constructor() {
|
|
134
229
|
this._user_count = 0; // Private property correct
|
|
135
230
|
}
|
|
136
|
-
|
|
137
|
-
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get user count
|
|
234
|
+
* @returns {number} User count
|
|
235
|
+
*/
|
|
236
|
+
get() { // Method name correct (single word ≤8 chars)
|
|
138
237
|
return this._user_count;
|
|
139
238
|
}
|
|
140
239
|
}
|
|
@@ -143,6 +242,15 @@ const MAX_RETRY = 5; // Constant name correct
|
|
|
143
242
|
let user_count = 10; // Variable name correct
|
|
144
243
|
```
|
|
145
244
|
|
|
245
|
+
## Word Length Validation
|
|
246
|
+
|
|
247
|
+
The plugin validates that each word in compound names does not exceed 8 characters:
|
|
248
|
+
|
|
249
|
+
- **Valid**: `UserService` ("User"=4, "Service"=7)
|
|
250
|
+
- **Invalid**: `UserConfiguration` ("Configuration"=13 > 8)
|
|
251
|
+
- **Valid**: `getUser` ("get"=3, "User"=4)
|
|
252
|
+
- **Invalid**: `getConfiguration` ("Configuration"=13 > 8)
|
|
253
|
+
|
|
146
254
|
## Configuration Options
|
|
147
255
|
|
|
148
256
|
You can customize rule parameters through configuration:
|
|
@@ -150,12 +258,13 @@ You can customize rule parameters through configuration:
|
|
|
150
258
|
```javascript
|
|
151
259
|
// Custom configuration example
|
|
152
260
|
const customConfig = {
|
|
153
|
-
|
|
261
|
+
"class-name": {
|
|
154
262
|
regex: /^[A-Z][a-zA-Z]*$/,
|
|
155
263
|
min: 1,
|
|
156
|
-
max: 25,
|
|
157
|
-
|
|
158
|
-
|
|
264
|
+
max: 25, // Extend maximum length
|
|
265
|
+
single_word_len: 10, // Extend word length limit
|
|
266
|
+
message: "Class name {name} must use PascalCase naming convention",
|
|
267
|
+
},
|
|
159
268
|
};
|
|
160
269
|
|
|
161
270
|
const detector = new NamingDetector(customConfig);
|
|
@@ -195,8 +304,16 @@ Welcome to submit Issues and Pull Requests to improve this plugin.
|
|
|
195
304
|
|
|
196
305
|
## Changelog
|
|
197
306
|
|
|
307
|
+
### v1.1.0
|
|
308
|
+
|
|
309
|
+
- Added word length validation (max 8 characters per word)
|
|
310
|
+
- Added parameter name and property name detection
|
|
311
|
+
- Integrated JSDoc documentation requirements
|
|
312
|
+
- Enhanced configuration with complete ESLint rules
|
|
313
|
+
|
|
198
314
|
### v1.0.0
|
|
315
|
+
|
|
199
316
|
- Initial version release
|
|
200
317
|
- Support for class name, function name, method name, variable name, constant name, and private member naming convention detection
|
|
201
318
|
- Support for length restrictions and single word preference rules
|
|
202
|
-
- Support for forbidden words detection
|
|
319
|
+
- Support for forbidden words detection
|