mm_eslint 1.4.3 → 1.4.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/README.md +325 -0
- package/README_EN.md +325 -0
- package/config.js +588 -573
- package/corrector.js +323 -0
- package/detector.js +1239 -3664
- package/eslint.config.js +22 -0
- package/index.js +1045 -1297
- package/package.json +54 -49
- package/tip.js +71 -0
- package/util.js +241 -0
- package/validator.js +270 -0
package/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# MM ESLint Plugin
|
|
2
|
+
|
|
3
|
+
基于个人命名规范的ESLint插件,支持类名、类实例名、函数名、参数名、变量名、常量名等命名规范检测。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mm_eslint)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
## 功能特性
|
|
10
|
+
|
|
11
|
+
- ✅ **类名检测** - 大驼峰命名法(PascalCase)
|
|
12
|
+
- ✅ **类实例名检测** - 小驼峰命名法(camelCase)
|
|
13
|
+
- ✅ **函数名检测** - 小驼峰命名法(camelCase)
|
|
14
|
+
- ✅ **参数名检测** - 小写蛇形命名法(snake_case)
|
|
15
|
+
- ✅ **变量名检测** - 小写蛇形命名法(snake_case)
|
|
16
|
+
- ✅ **常量名检测** - 大写蛇形命名法(UPPER_SNAKE_CASE)
|
|
17
|
+
- ✅ **长度限制** - 所有命名长度限制在1-20字符
|
|
18
|
+
- ✅ **单词长度限制** - 每个单词限制在最大8字符
|
|
19
|
+
- ✅ **禁止废话词** - 避免使用Manager、Handler等冗余词汇
|
|
20
|
+
- ✅ **命名推荐功能** - 推荐更短的替代名称,同时保持语义不变
|
|
21
|
+
|
|
22
|
+
## 实际支持的规则
|
|
23
|
+
|
|
24
|
+
插件实际支持以下ESLint规则:
|
|
25
|
+
- `naming-convention/class-name` - 类名检测
|
|
26
|
+
- `naming-convention/class-instance-name` - 类实例名检测
|
|
27
|
+
- `naming-convention/function-name` - 函数名检测
|
|
28
|
+
- `naming-convention/param-name` - 参数名检测
|
|
29
|
+
- `naming-convention/variable-name` - 变量名检测
|
|
30
|
+
- `naming-convention/constant-name` - 常量名检测
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
### npm安装
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install mm_eslint --save-dev
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 本地安装
|
|
41
|
+
|
|
42
|
+
如果您想使用本地版本,可以将插件文件复制到项目中:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 复制插件文件到您的项目
|
|
46
|
+
cp mm_eslint/index.js your-project/eslint-plugins/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 快速开始
|
|
50
|
+
|
|
51
|
+
### 1. 基本配置
|
|
52
|
+
|
|
53
|
+
在您的ESLint配置文件中引入插件:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// eslint.config.js
|
|
57
|
+
const namingConventionPlugin = require("mm_eslint");
|
|
58
|
+
|
|
59
|
+
module.exports = [
|
|
60
|
+
{
|
|
61
|
+
files: ["**/*.js"],
|
|
62
|
+
plugins: {
|
|
63
|
+
"naming-convention": namingConventionPlugin,
|
|
64
|
+
},
|
|
65
|
+
rules: {
|
|
66
|
+
// 命名规范插件规则
|
|
67
|
+
"naming-convention/class-name": "error",
|
|
68
|
+
"naming-convention/class-instance-name": "error",
|
|
69
|
+
"naming-convention/function-name": "error",
|
|
70
|
+
"naming-convention/param-name": "warn",
|
|
71
|
+
"naming-convention/variable-name": "warn",
|
|
72
|
+
"naming-convention/constant-name": "error",
|
|
73
|
+
|
|
74
|
+
// 禁用与命名规范插件冲突的默认规则
|
|
75
|
+
camelcase: "off",
|
|
76
|
+
"id-match": "off",
|
|
77
|
+
"new-cap": "off",
|
|
78
|
+
"id-length": "off",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. 命令行使用
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 验证单个文件
|
|
88
|
+
npx eslint your-file.js
|
|
89
|
+
|
|
90
|
+
# 验证所有JS文件
|
|
91
|
+
npx eslint "**/*.js"
|
|
92
|
+
|
|
93
|
+
# 验证并自动修复
|
|
94
|
+
npx eslint --fix your-file.js
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 命名规范规则
|
|
98
|
+
|
|
99
|
+
### 类名规则(class-name)
|
|
100
|
+
|
|
101
|
+
- **级别**: error
|
|
102
|
+
- **要求**: 大驼峰命名法(PascalCase)
|
|
103
|
+
- **长度**: 1-20字符
|
|
104
|
+
- **单词长度**: 每个单词≤8字符
|
|
105
|
+
- **示例**: `User`, `DbConn`
|
|
106
|
+
- **错误示例**: `user`, `user_manager`, `UserManager`
|
|
107
|
+
|
|
108
|
+
### 类实例名规则(class-instance-name)
|
|
109
|
+
|
|
110
|
+
- **级别**: error
|
|
111
|
+
- **要求**: 小驼峰命名法(camelCase)
|
|
112
|
+
- **长度**: 1-20字符
|
|
113
|
+
- **单词长度**: 每个单词≤8字符
|
|
114
|
+
- **示例**: `userInstance`, `dbConn`
|
|
115
|
+
- **错误示例**: `UserInstance`, `db_conn`, `DB_CONN`
|
|
116
|
+
|
|
117
|
+
### 函数名规则(function-name)
|
|
118
|
+
|
|
119
|
+
- **级别**: error
|
|
120
|
+
- **要求**: 小驼峰命名法(camelCase)
|
|
121
|
+
- **长度**: 1-20字符
|
|
122
|
+
- **单词长度**: 每个单词≤8字符
|
|
123
|
+
- **示例**: `get`, `getName`, `process`
|
|
124
|
+
- **错误示例**: `Get`, `get_name`, `PROCESS`
|
|
125
|
+
|
|
126
|
+
### 参数名规则(param-name)
|
|
127
|
+
|
|
128
|
+
- **级别**: warn
|
|
129
|
+
- **要求**: 小写蛇形命名法(snake_case)
|
|
130
|
+
- **长度**: 1-20字符
|
|
131
|
+
- **示例**: `user_name`, `max_count`
|
|
132
|
+
- **错误示例**: `userName`, `maxCount`, `MAX_COUNT`
|
|
133
|
+
|
|
134
|
+
### 变量名规则(variable-name)
|
|
135
|
+
|
|
136
|
+
- **级别**: warn
|
|
137
|
+
- **要求**: 小写蛇形命名法(snake_case)
|
|
138
|
+
- **长度**: 1-20字符
|
|
139
|
+
- **示例**: `user_count`, `max_retry`
|
|
140
|
+
- **错误示例**: `userCount`, `maxRetry`, `MAX_RETRY`
|
|
141
|
+
|
|
142
|
+
### 常量名规则(constant-name)
|
|
143
|
+
|
|
144
|
+
- **级别**: error
|
|
145
|
+
- **要求**: 大写蛇形命名法(UPPER_SNAKE_CASE)
|
|
146
|
+
- **长度**: 1-20字符
|
|
147
|
+
- **示例**: `MAX_RETRY`, `DEFAULT_TIMEOUT`
|
|
148
|
+
- **错误示例**: `maxRetry`, `defaultTimeout`, `DefaultTimeout`
|
|
149
|
+
|
|
150
|
+
## 错误示例
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
// ❌ 错误的命名示例
|
|
154
|
+
class user {} // 类名应该使用 PascalCase
|
|
155
|
+
class user_manager {} // 类名应该使用 PascalCase
|
|
156
|
+
class UserManager {} // 类名应该使用 PascalCase
|
|
157
|
+
|
|
158
|
+
const userInstance = new User(); // 类实例名应该使用 camelCase
|
|
159
|
+
const UserInstance = new User(); // 类实例名应该使用 camelCase
|
|
160
|
+
|
|
161
|
+
function GetUser() {} // 函数名应该使用 camelCase
|
|
162
|
+
function get_user() {} // 函数名应该使用 camelCase
|
|
163
|
+
|
|
164
|
+
function process(userName) {} // 参数名应该使用 snake_case
|
|
165
|
+
const maxRetry = 5; // 变量名应该使用 snake_case
|
|
166
|
+
const defaultTimeout = 1000; // 常量名应该使用 UPPER_SNAKE_CASE
|
|
167
|
+
|
|
168
|
+
// ✅ 正确的命名示例
|
|
169
|
+
class User {}
|
|
170
|
+
class DbConn {}
|
|
171
|
+
|
|
172
|
+
const userInstance = new User();
|
|
173
|
+
const dbConn = new DbConn();
|
|
174
|
+
|
|
175
|
+
function getUser() {}
|
|
176
|
+
function process() {}
|
|
177
|
+
|
|
178
|
+
function process(user_name) {}
|
|
179
|
+
const max_retry = 5;
|
|
180
|
+
const DEFAULT_TIMEOUT = 1000;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 单词长度验证
|
|
184
|
+
|
|
185
|
+
插件验证复合名称中的每个单词不超过8个字符:
|
|
186
|
+
|
|
187
|
+
- **有效**: `UserService`("User"=4, "Service"=7)
|
|
188
|
+
- **无效**: `UserConfiguration`("Configuration"=13 > 8)
|
|
189
|
+
- **有效**: `getUser`("get"=3, "User"=4)
|
|
190
|
+
- **无效**: `getConfiguration`("Configuration"=13 > 8)
|
|
191
|
+
|
|
192
|
+
## 禁止的冗余词汇
|
|
193
|
+
|
|
194
|
+
插件会自动检测并禁止使用以下冗余词汇:
|
|
195
|
+
|
|
196
|
+
**类名禁止词**: manager, handler, processor, controller, service, provider, factory, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, model, view, route, router, component, widget, panel, dialog, window, form, field, property, entity
|
|
197
|
+
|
|
198
|
+
**函数名禁止词**: data, result, output, input, param, params, parameter, parameters, value, values, item, items, process, processor, provider, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, temp, tmp, temporary, cached, buffered, idx, counter, with
|
|
199
|
+
|
|
200
|
+
**变量名禁止词**: object, array, map, set, collection, container, instance, data, item, items, element, elements, entry, entries, temp, tmp, temporary, cached, buffer, buffered, input, output, result, destination, index, idx, counter, length, total, sum, pointer, reference, ref, handle, handler, entity, column, property, attribute, manager, processor, controller, service, middleware, component, provider
|
|
201
|
+
|
|
202
|
+
## 命名推荐功能
|
|
203
|
+
|
|
204
|
+
插件包含智能命名推荐系统,建议使用更短的替代名称,同时保持语义不变。
|
|
205
|
+
|
|
206
|
+
### 核心原则
|
|
207
|
+
|
|
208
|
+
核心原则是**"缩短命名而不改变语义"**。推荐系统:
|
|
209
|
+
- 推荐更短的单词,同时保持相同含义
|
|
210
|
+
- 避免会改变功能的概念性变化
|
|
211
|
+
- 确保推荐词始终比原词短
|
|
212
|
+
- 保留编程特定术语和概念差异
|
|
213
|
+
|
|
214
|
+
### 可用推荐
|
|
215
|
+
|
|
216
|
+
插件为常见编程操作提供推荐:
|
|
217
|
+
|
|
218
|
+
| 原词 | 推荐词 | 描述 |
|
|
219
|
+
| ------------ | -------- | ---------- |
|
|
220
|
+
| `calculate` | `calc` | 数学运算 |
|
|
221
|
+
| `generate` | `gen` | 数据生成 |
|
|
222
|
+
| `initialize` | `init` | 初始化操作 |
|
|
223
|
+
| `execute` | `exec` | 命令执行 |
|
|
224
|
+
| `process` | `run` | 数据处理 |
|
|
225
|
+
| `retrieve` | `load` | 数据加载 |
|
|
226
|
+
| `persist` | `save` | 数据存储 |
|
|
227
|
+
| `compare` | `cmp` | 比较操作 |
|
|
228
|
+
| `duplicate` | `copy` | 数据复制 |
|
|
229
|
+
| `transfer` | `move` | 数据移动 |
|
|
230
|
+
| `convert` | `to` | 类型转换 |
|
|
231
|
+
| `verify` | `check` | 验证检查 |
|
|
232
|
+
| `construct` | `create` | 对象创建 |
|
|
233
|
+
| `handle` | `run` | 事件处理 |
|
|
234
|
+
|
|
235
|
+
### 示例
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
// ❌ 原词(较长名称)
|
|
239
|
+
function calculateTotal() {}
|
|
240
|
+
function generateUserData() {}
|
|
241
|
+
function initializeSystem() {}
|
|
242
|
+
function executeCommand() {}
|
|
243
|
+
function processData() {}
|
|
244
|
+
|
|
245
|
+
// ✅ 推荐词(较短名称)
|
|
246
|
+
function calcTotal() {}
|
|
247
|
+
function genUserData() {}
|
|
248
|
+
function initSystem() {}
|
|
249
|
+
function execCommand() {}
|
|
250
|
+
function runData() {}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 带推荐的错误消息
|
|
254
|
+
|
|
255
|
+
启用推荐功能后,ESLint将建议替代名称:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# ESLint输出示例
|
|
259
|
+
function calculateTotal() {}
|
|
260
|
+
# ^ 建议使用'calc'替代'calculate'以获得更短的命名
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## 开发
|
|
264
|
+
|
|
265
|
+
### 项目结构
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
mm_eslint/
|
|
269
|
+
├── index.js # 主插件文件
|
|
270
|
+
├── config.js # 配置管理
|
|
271
|
+
├── detector.js # 命名检测器
|
|
272
|
+
├── validator.js # 验证器
|
|
273
|
+
├── corrector.js # 命名修正器
|
|
274
|
+
├── tip.js # 提示信息
|
|
275
|
+
├── util.js # 工具函数
|
|
276
|
+
├── package.json # npm配置
|
|
277
|
+
├── README.md # 中文说明文档
|
|
278
|
+
├── README_EN.md # 英文说明文档
|
|
279
|
+
├── LICENSE # 许可证
|
|
280
|
+
└── tests/ # 测试文件
|
|
281
|
+
├── success/ # 正确示例
|
|
282
|
+
├── error/ # 错误示例
|
|
283
|
+
└── scence/ # 场景测试
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### 运行测试
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# 运行单元测试
|
|
290
|
+
npm test
|
|
291
|
+
|
|
292
|
+
# 运行ESLint检查
|
|
293
|
+
npm run lint
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## 许可证
|
|
297
|
+
|
|
298
|
+
ISC License
|
|
299
|
+
|
|
300
|
+
## 贡献
|
|
301
|
+
|
|
302
|
+
欢迎提交Issue和Pull Request来改进这个插件。
|
|
303
|
+
|
|
304
|
+
## 更新日志
|
|
305
|
+
|
|
306
|
+
### v1.4.3
|
|
307
|
+
- 优化模块结构和文件组织
|
|
308
|
+
- 增强测试覆盖率和错误处理
|
|
309
|
+
- 改进文档和示例
|
|
310
|
+
|
|
311
|
+
### v1.2.0
|
|
312
|
+
- 模块化重构版,职责分离
|
|
313
|
+
- 增强配置管理
|
|
314
|
+
- 改进命名检测算法
|
|
315
|
+
|
|
316
|
+
### v1.1.0
|
|
317
|
+
- 添加单词长度验证(每个单词最大8字符)
|
|
318
|
+
- 添加入参名和属性名检测
|
|
319
|
+
- 增强配置,包含完整的ESLint规则
|
|
320
|
+
|
|
321
|
+
### v1.0.0
|
|
322
|
+
- 初始版本发布
|
|
323
|
+
- 支持类名、函数名、变量名、常量名、私有成员命名规范检测
|
|
324
|
+
- 支持长度限制和单个单词优先规则
|
|
325
|
+
- 支持禁止废话词检测
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# MM ESLint Plugin
|
|
2
|
+
|
|
3
|
+
ESLint plugin for personal naming conventions - supports PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mm_eslint)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ✅ **Class Name Detection** - PascalCase naming convention
|
|
12
|
+
- ✅ **Class Instance Name Detection** - camelCase naming convention
|
|
13
|
+
- ✅ **Function Name Detection** - camelCase naming convention
|
|
14
|
+
- ✅ **Parameter Name Detection** - snake_case naming convention
|
|
15
|
+
- ✅ **Variable Name Detection** - snake_case naming convention
|
|
16
|
+
- ✅ **Constant Name Detection** - UPPER_SNAKE_CASE naming convention
|
|
17
|
+
- ✅ **Length Limitation** - All names limited to 1-20 characters
|
|
18
|
+
- ✅ **Word Length Limitation** - Each word limited to maximum 8 characters
|
|
19
|
+
- ✅ **Redundant Word Prevention** - Avoids redundant words like Manager, Handler
|
|
20
|
+
- ✅ **Name Recommendation** - Recommends shorter alternative names while preserving semantics
|
|
21
|
+
|
|
22
|
+
## Actual Supported Rules
|
|
23
|
+
|
|
24
|
+
The plugin actually supports the following ESLint rules:
|
|
25
|
+
- `naming-convention/class-name` - Class name detection
|
|
26
|
+
- `naming-convention/class-instance-name` - Class instance name detection
|
|
27
|
+
- `naming-convention/function-name` - Function name detection
|
|
28
|
+
- `naming-convention/param-name` - Parameter name detection
|
|
29
|
+
- `naming-convention/variable-name` - Variable name detection
|
|
30
|
+
- `naming-convention/constant-name` - Constant name detection
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### npm Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install mm_eslint --save-dev
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Local Installation
|
|
41
|
+
|
|
42
|
+
If you want to use a local version, you can copy the plugin files to your project:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Copy plugin files to your project
|
|
46
|
+
cp mm_eslint/index.js your-project/eslint-plugins/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### 1. Basic Configuration
|
|
52
|
+
|
|
53
|
+
Import the plugin in your ESLint configuration file:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// eslint.config.js
|
|
57
|
+
const namingConventionPlugin = require("mm_eslint");
|
|
58
|
+
|
|
59
|
+
module.exports = [
|
|
60
|
+
{
|
|
61
|
+
files: ["**/*.js"],
|
|
62
|
+
plugins: {
|
|
63
|
+
"naming-convention": namingConventionPlugin,
|
|
64
|
+
},
|
|
65
|
+
rules: {
|
|
66
|
+
// Naming convention plugin rules
|
|
67
|
+
"naming-convention/class-name": "error",
|
|
68
|
+
"naming-convention/class-instance-name": "error",
|
|
69
|
+
"naming-convention/function-name": "error",
|
|
70
|
+
"naming-convention/param-name": "warn",
|
|
71
|
+
"naming-convention/variable-name": "warn",
|
|
72
|
+
"naming-convention/constant-name": "error",
|
|
73
|
+
|
|
74
|
+
// Disable default rules conflicting with naming convention plugin
|
|
75
|
+
camelcase: "off",
|
|
76
|
+
"id-match": "off",
|
|
77
|
+
"new-cap": "off",
|
|
78
|
+
"id-length": "off",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Command Line Usage
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Validate single file
|
|
88
|
+
npx eslint your-file.js
|
|
89
|
+
|
|
90
|
+
# Validate all JS files
|
|
91
|
+
npx eslint "**/*.js"
|
|
92
|
+
|
|
93
|
+
# Validate and auto-fix
|
|
94
|
+
npx eslint --fix your-file.js
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Naming Convention Rules
|
|
98
|
+
|
|
99
|
+
### Class Name Rule (class-name)
|
|
100
|
+
|
|
101
|
+
- **Level**: error
|
|
102
|
+
- **Requirement**: PascalCase naming convention
|
|
103
|
+
- **Length**: 1-20 characters
|
|
104
|
+
- **Word Length**: Each word ≤8 characters
|
|
105
|
+
- **Example**: `User`, `DbConn`
|
|
106
|
+
- **Error Example**: `user`, `user_manager`, `UserManager`
|
|
107
|
+
|
|
108
|
+
### Class Instance Name Rule (class-instance-name)
|
|
109
|
+
|
|
110
|
+
- **Level**: error
|
|
111
|
+
- **Requirement**: camelCase naming convention
|
|
112
|
+
- **Length**: 1-20 characters
|
|
113
|
+
- **Word Length**: Each word ≤8 characters
|
|
114
|
+
- **Example**: `userInstance`, `dbConn`
|
|
115
|
+
- **Error Example**: `UserInstance`, `db_conn`, `DB_CONN`
|
|
116
|
+
|
|
117
|
+
### Function Name Rule (function-name)
|
|
118
|
+
|
|
119
|
+
- **Level**: error
|
|
120
|
+
- **Requirement**: camelCase naming convention
|
|
121
|
+
- **Length**: 1-20 characters
|
|
122
|
+
- **Word Length**: Each word ≤8 characters
|
|
123
|
+
- **Example**: `get`, `getName`, `process`
|
|
124
|
+
- **Error Example**: `Get`, `get_name`, `PROCESS`
|
|
125
|
+
|
|
126
|
+
### Parameter Name Rule (param-name)
|
|
127
|
+
|
|
128
|
+
- **Level**: warn
|
|
129
|
+
- **Requirement**: snake_case naming convention
|
|
130
|
+
- **Length**: 1-20 characters
|
|
131
|
+
- **Example**: `user_name`, `max_count`
|
|
132
|
+
- **Error Example**: `userName`, `maxCount`, `MAX_COUNT`
|
|
133
|
+
|
|
134
|
+
### Variable Name Rule (variable-name)
|
|
135
|
+
|
|
136
|
+
- **Level**: warn
|
|
137
|
+
- **Requirement**: snake_case naming convention
|
|
138
|
+
- **Length**: 1-20 characters
|
|
139
|
+
- **Example**: `user_count`, `max_retry`
|
|
140
|
+
- **Error Example**: `userCount`, `maxRetry`, `MAX_RETRY`
|
|
141
|
+
|
|
142
|
+
### Constant Name Rule (constant-name)
|
|
143
|
+
|
|
144
|
+
- **Level**: error
|
|
145
|
+
- **Requirement**: UPPER_SNAKE_CASE naming convention
|
|
146
|
+
- **Length**: 1-20 characters
|
|
147
|
+
- **Example**: `MAX_RETRY`, `DEFAULT_TIMEOUT`
|
|
148
|
+
- **Error Example**: `maxRetry`, `defaultTimeout`, `DefaultTimeout`
|
|
149
|
+
|
|
150
|
+
## Error Examples
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
// ❌ Incorrect naming examples
|
|
154
|
+
class user {} // Class name should use PascalCase
|
|
155
|
+
class user_manager {} // Class name should use PascalCase
|
|
156
|
+
class UserManager {} // Class name should use PascalCase
|
|
157
|
+
|
|
158
|
+
const userInstance = new User(); // Class instance name should use camelCase
|
|
159
|
+
const UserInstance = new User(); // Class instance name should use camelCase
|
|
160
|
+
|
|
161
|
+
function GetUser() {} // Function name should use camelCase
|
|
162
|
+
function get_user() {} // Function name should use camelCase
|
|
163
|
+
|
|
164
|
+
function process(userName) {} // Parameter name should use snake_case
|
|
165
|
+
const maxRetry = 5; // Variable name should use snake_case
|
|
166
|
+
const defaultTimeout = 1000; // Constant name should use UPPER_SNAKE_CASE
|
|
167
|
+
|
|
168
|
+
// ✅ Correct naming examples
|
|
169
|
+
class User {}
|
|
170
|
+
class DbConn {}
|
|
171
|
+
|
|
172
|
+
const userInstance = new User();
|
|
173
|
+
const dbConn = new DbConn();
|
|
174
|
+
|
|
175
|
+
function getUser() {}
|
|
176
|
+
function process() {}
|
|
177
|
+
|
|
178
|
+
function process(user_name) {}
|
|
179
|
+
const max_retry = 5;
|
|
180
|
+
const DEFAULT_TIMEOUT = 1000;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Word Length Validation
|
|
184
|
+
|
|
185
|
+
The plugin validates that each word in compound names does not exceed 8 characters:
|
|
186
|
+
|
|
187
|
+
- **Valid**: `UserService` ("User"=4, "Service"=7)
|
|
188
|
+
- **Invalid**: `UserConfiguration` ("Configuration"=13 > 8)
|
|
189
|
+
- **Valid**: `getUser` ("get"=3, "User"=4)
|
|
190
|
+
- **Invalid**: `getConfiguration` ("Configuration"=13 > 8)
|
|
191
|
+
|
|
192
|
+
## Prohibited Redundant Words
|
|
193
|
+
|
|
194
|
+
The plugin automatically detects and prohibits the use of the following redundant words:
|
|
195
|
+
|
|
196
|
+
**Class Name Prohibited Words**: manager, handler, processor, controller, service, provider, factory, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, model, view, route, router, component, widget, panel, dialog, window, form, field, property, entity
|
|
197
|
+
|
|
198
|
+
**Function Name Prohibited Words**: data, result, output, input, param, params, parameter, parameters, value, values, item, items, process, processor, provider, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, temp, tmp, temporary, cached, buffered, idx, counter, with
|
|
199
|
+
|
|
200
|
+
**Variable Name Prohibited Words**: object, array, map, set, collection, container, instance, data, item, items, element, elements, entry, entries, temp, tmp, temporary, cached, buffer, buffered, input, output, result, destination, index, idx, counter, length, total, sum, pointer, reference, ref, handle, handler, entity, column, property, attribute, manager, processor, controller, service, middleware, component, provider
|
|
201
|
+
|
|
202
|
+
## Name Recommendation Feature
|
|
203
|
+
|
|
204
|
+
The plugin includes an intelligent name recommendation system that suggests shorter alternative names while preserving semantics.
|
|
205
|
+
|
|
206
|
+
### Core Principle
|
|
207
|
+
|
|
208
|
+
The core principle is **"shorten names without changing semantics"**. The recommendation system:
|
|
209
|
+
- Recommends shorter words while maintaining the same meaning
|
|
210
|
+
- Avoids conceptual changes that would alter functionality
|
|
211
|
+
- Ensures recommended words are always shorter than the original
|
|
212
|
+
- Preserves programming-specific terminology and conceptual differences
|
|
213
|
+
|
|
214
|
+
### Available Recommendations
|
|
215
|
+
|
|
216
|
+
The plugin provides recommendations for common programming operations:
|
|
217
|
+
|
|
218
|
+
| Original Word | Recommended | Description |
|
|
219
|
+
| ------------- | ----------- | ----------- |
|
|
220
|
+
| `calculate` | `calc` | Math operations |
|
|
221
|
+
| `generate` | `gen` | Data generation |
|
|
222
|
+
| `initialize` | `init` | Initialization operations |
|
|
223
|
+
| `execute` | `exec` | Command execution |
|
|
224
|
+
| `process` | `run` | Data processing |
|
|
225
|
+
| `retrieve` | `load` | Data loading |
|
|
226
|
+
| `persist` | `save` | Data storage |
|
|
227
|
+
| `compare` | `cmp` | Comparison operations |
|
|
228
|
+
| `duplicate` | `copy` | Data duplication |
|
|
229
|
+
| `transfer` | `move` | Data transfer |
|
|
230
|
+
| `convert` | `to` | Type conversion |
|
|
231
|
+
| `verify` | `check` | Verification checks |
|
|
232
|
+
| `construct` | `create` | Object creation |
|
|
233
|
+
| `handle` | `run` | Event handling |
|
|
234
|
+
|
|
235
|
+
### Examples
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
// ❌ Original words (longer names)
|
|
239
|
+
function calculateTotal() {}
|
|
240
|
+
function generateUserData() {}
|
|
241
|
+
function initializeSystem() {}
|
|
242
|
+
function executeCommand() {}
|
|
243
|
+
function processData() {}
|
|
244
|
+
|
|
245
|
+
// ✅ Recommended words (shorter names)
|
|
246
|
+
function calcTotal() {}
|
|
247
|
+
function genUserData() {}
|
|
248
|
+
function initSystem() {}
|
|
249
|
+
function execCommand() {}
|
|
250
|
+
function runData() {}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Error Messages with Recommendations
|
|
254
|
+
|
|
255
|
+
When the recommendation feature is enabled, ESLint will suggest alternative names:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# ESLint output example
|
|
259
|
+
function calculateTotal() {}
|
|
260
|
+
# ^ Suggestion: Use 'calc' instead of 'calculate' for shorter naming
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Development
|
|
264
|
+
|
|
265
|
+
### Project Structure
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
mm_eslint/
|
|
269
|
+
├── index.js # Main plugin file
|
|
270
|
+
├── config.js # Configuration management
|
|
271
|
+
├── detector.js # Naming detector
|
|
272
|
+
├── validator.js # Validator
|
|
273
|
+
├── corrector.js # Name corrector
|
|
274
|
+
├── tip.js # Tip messages
|
|
275
|
+
├── util.js # Utility functions
|
|
276
|
+
├── package.json # npm configuration
|
|
277
|
+
├── README.md # Chinese documentation
|
|
278
|
+
├── README_EN.md # English documentation
|
|
279
|
+
├── LICENSE # License
|
|
280
|
+
└── tests/ # Test files
|
|
281
|
+
├── success/ # Correct examples
|
|
282
|
+
├── error/ # Error examples
|
|
283
|
+
└── scence/ # Scenario tests
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Running Tests
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# Run unit tests
|
|
290
|
+
npm test
|
|
291
|
+
|
|
292
|
+
# Run ESLint checks
|
|
293
|
+
npm run lint
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
ISC License
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
Issues and Pull Requests are welcome to improve this plugin.
|
|
303
|
+
|
|
304
|
+
## Changelog
|
|
305
|
+
|
|
306
|
+
### v1.4.3
|
|
307
|
+
- Optimized module structure and file organization
|
|
308
|
+
- Enhanced test coverage and error handling
|
|
309
|
+
- Improved documentation and examples
|
|
310
|
+
|
|
311
|
+
### v1.2.0
|
|
312
|
+
- Modular refactoring version, separation of responsibilities
|
|
313
|
+
- Enhanced configuration management
|
|
314
|
+
- Improved naming detection algorithm
|
|
315
|
+
|
|
316
|
+
### v1.1.0
|
|
317
|
+
- Added word length validation (max 8 characters per word)
|
|
318
|
+
- Added parameter name and property name detection
|
|
319
|
+
- Enhanced configuration with complete ESLint rules
|
|
320
|
+
|
|
321
|
+
### v1.0.0
|
|
322
|
+
- Initial version release
|
|
323
|
+
- Support for class, function, variable, constant, and private member naming conventions
|
|
324
|
+
- Support for length limitations and single word priority rules
|
|
325
|
+
- Support for redundant word prevention
|