mm_eslint 1.4.5 → 1.4.6

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 CHANGED
@@ -5,6 +5,8 @@
5
5
  [![npm version](https://img.shields.io/npm/v/mm_eslint.svg)](https://www.npmjs.com/package/mm_eslint)
6
6
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
7
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D12.0.0-brightgreen.svg)](https://nodejs.org/)
8
+ [![Downloads](https://img.shields.io/npm/dm/mm_eslint.svg)](https://www.npmjs.com/package/mm_eslint)
9
+ [![GitHub stars](https://img.shields.io/github/stars/qiuwenwu91/mm_eslint.svg)](https://gitee.com/qiuwenwu91/mm_eslint/stargazers)
8
10
 
9
11
  ## 功能特性
10
12
 
@@ -298,6 +300,30 @@ npm test
298
300
  npm run lint
299
301
  ```
300
302
 
303
+ ## 发布说明
304
+
305
+ ### npm发布
306
+
307
+ 插件已发布到npm,可以通过以下命令安装:
308
+
309
+ ```bash
310
+ npm install mm_eslint --save-dev
311
+ ```
312
+
313
+ ### 版本管理
314
+
315
+ 项目使用语义化版本控制(Semantic Versioning):
316
+ - **主版本号**:不兼容的API修改
317
+ - **次版本号**:向下兼容的功能性新增
318
+ - **修订号**:向下兼容的问题修正
319
+
320
+ ### 发布流程
321
+
322
+ 1. 更新版本号:`npm version patch|minor|major`
323
+ 2. 运行测试:`npm test`
324
+ 3. 代码检查:`npm run lint`
325
+ 4. 发布到npm:`npm publish`
326
+
301
327
  ## 许可证
302
328
 
303
329
  ISC License
package/README_EN.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # MM ESLint Plugin
2
2
 
3
- ESLint plugin for personal naming conventions - supports PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules.
3
+ ESLint plugin for personal naming conventions - supports PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules with intelligent recommendations.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/mm_eslint.svg)](https://www.npmjs.com/package/mm_eslint)
6
6
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
7
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D12.0.0-brightgreen.svg)](https://nodejs.org/)
8
+ [![Downloads](https://img.shields.io/npm/dm/mm_eslint.svg)](https://www.npmjs.com/package/mm_eslint)
9
+ [![GitHub stars](https://img.shields.io/github/stars/qiuwenwu91/mm_eslint.svg)](https://gitee.com/qiuwenwu91/mm_eslint/stargazers)
8
10
 
9
11
  ## Features
10
12
 
@@ -298,6 +300,30 @@ npm test
298
300
  npm run lint
299
301
  ```
300
302
 
303
+ ## Publishing Information
304
+
305
+ ### npm Publishing
306
+
307
+ The plugin is published to npm and can be installed via:
308
+
309
+ ```bash
310
+ npm install mm_eslint --save-dev
311
+ ```
312
+
313
+ ### Version Management
314
+
315
+ Project uses Semantic Versioning:
316
+ - **Major version**: Incompatible API changes
317
+ - **Minor version**: Backward-compatible functionality additions
318
+ - **Patch version**: Backward-compatible bug fixes
319
+
320
+ ### Publishing Process
321
+
322
+ 1. Update version: `npm version patch|minor|major`
323
+ 2. Run tests: `npm test`
324
+ 3. Code linting: `npm run lint`
325
+ 4. Publish to npm: `npm publish`
326
+
301
327
  ## License
302
328
 
303
329
  ISC License
package/index.js CHANGED
@@ -2,343 +2,199 @@
2
2
  * ESLint命名规范检测插件
3
3
  * 版本: 2.0.0 - 模块化重构版,职责分离
4
4
  */
5
- const { Handler } = require('./handler');
5
+ const { ClassName, ClassInstanceName, FunctionName, VariableName, ObjectName, ConstName, ParamName } = require('./lib/detector');
6
6
 
7
7
  /**
8
8
  * 规则定义类
9
9
  * 负责定义ESLint规则配置
10
10
  */
11
- class Rules {
12
- /**
13
- * 构造函数
14
- */
15
- constructor() {
16
- this.handler = new Handler();
17
- }
18
-
11
+ module.exports = {
19
12
  /**
20
13
  * 创建类名规则
21
14
  * @returns {object} 类名规则配置
22
15
  */
23
- createClassNameRule() {
24
- var handler = this.handler;
25
-
26
- return {
27
- meta: {
28
- type: 'suggestion',
29
- docs: {
30
- description: '检测类名是否符合命名规范',
31
- category: 'Stylistic Issues',
32
- recommended: true,
33
- },
34
- fixable: 'code',
35
- schema: [],
16
+ 'class-name': {
17
+ meta: {
18
+ type: 'suggestion',
19
+ docs: {
20
+ description: '检测类名是否符合命名规范',
21
+ category: 'Stylistic Issues',
22
+ recommended: true,
36
23
  },
37
- create: function (context) {
38
- return {
39
- ClassDeclaration: function (node) {
40
- handler.handleClassDeclaration(context, node, node, 'class');
41
- },
42
- VariableDeclaration: function (node) {
43
- handler.handleVariableDeclaration(context, node, node, 'class');
44
- },
45
- Property: function (node) {
46
- handler.handleProperty(context, node, node, 'class');
47
- },
48
- AssignmentExpression: function (node) {
49
- handler.handleAssignmentExpression(context, node, node, 'class');
50
- },
51
- ExportDefaultDeclaration: function (node) {
52
- handler.handleExportDefaultDeclaration(context, node, node, 'class');
53
- },
54
- ExportNamedDeclaration: function (node) {
55
- handler.handleExportNamedDeclaration(context, node, node, 'class');
56
- },
57
- ClassExpression: function (node) {
58
- handler.handleClassExpression(context, node, node, 'class');
59
- },
60
- ImportDeclaration: function (node) {
61
- handler.handleImportDeclaration(context, node, node, 'class');
62
- },
63
- Identifier: function (node) {
64
- handler.handleIdentifier(context, node, node, 'class');
65
- }
66
- };
67
- },
68
- };
69
- }
24
+ fixable: 'code',
25
+ schema: [],
26
+ },
27
+ create: function (context) {
28
+ var cs = new ClassName(context);
29
+ let obj = {};
30
+ for (let key in cs) {
31
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
32
+ obj[key] = cs[key].bind(cs);
33
+ }
34
+ }
35
+ return obj
36
+ }
37
+ },
70
38
 
71
39
  /**
72
40
  * 创建类实例名规则
73
41
  * @returns {object} 类实例名规则配置
74
42
  */
75
- createClassInstanceNameRule() {
76
- var handler = this.handler;
77
-
78
- return {
79
- meta: {
80
- type: 'suggestion',
81
- docs: {
82
- description: '检测类实例名是否符合命名规范',
83
- category: 'Stylistic Issues',
84
- recommended: true,
85
- },
86
- fixable: 'code',
87
- schema: [],
43
+ 'class-instance-name': {
44
+ meta: {
45
+ type: 'suggestion',
46
+ docs: {
47
+ description: '检测类实例名是否符合命名规范',
48
+ category: 'Stylistic Issues',
49
+ recommended: true,
88
50
  },
89
- create: function (context) {
90
- return {
91
- VariableDeclaration: function (node) {
92
- handler.handleVariableDeclaration(context, node, node, 'class-instance');
93
- },
94
- Property: function (node) {
95
- handler.handleProperty(context, node, node, 'class-instance');
96
- },
97
- AssignmentExpression: function (node) {
98
- handler.handleAssignmentExpression(context, node, node, 'class-instance');
99
- },
100
- PropertyDefinition: function (node) {
101
- handler.handlePropertyDefinition(context, node, node, 'class-instance');
102
- }
103
- };
51
+ fixable: 'code',
52
+ schema: [],
53
+ },
54
+ create: function (context) {
55
+ var cs = new ClassInstanceName(context);
56
+ let obj = {};
57
+ for (let key in cs) {
58
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
59
+ obj[key] = cs[key].bind(cs);
60
+ }
61
+ }
62
+ return obj
63
+ }
64
+ },
65
+
66
+ /**
67
+ * 创建对象名规则
68
+ * @returns {object} 对象名规则配置
69
+ */
70
+ 'object-name': {
71
+ meta: {
72
+ type: 'suggestion',
73
+ docs: {
74
+ description: '检测对象名是否符合命名规范',
75
+ category: 'Stylistic Issues',
76
+ recommended: true,
104
77
  },
105
- };
106
- }
78
+ fixable: 'code',
79
+ schema: [],
80
+ },
81
+ create: function (context) {
82
+ var cs = new ObjectName(context);
83
+ let obj = {};
84
+ for (let key in cs) {
85
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
86
+ obj[key] = cs[key].bind(cs);
87
+ }
88
+ }
89
+ return obj
90
+ }
91
+ },
107
92
 
108
93
  /**
109
94
  * 创建函数名规则
110
95
  * @returns {object} 函数名规则配置
111
96
  */
112
- createFunctionNameRule() {
113
- var handler = this.handler;
114
-
115
- return {
116
- meta: {
117
- type: 'suggestion',
118
- docs: {
119
- description: '检测函数名是否符合命名规范',
120
- category: 'Stylistic Issues',
121
- recommended: true,
122
- },
123
- fixable: 'code',
124
- schema: [],
97
+ 'function-name': {
98
+ meta: {
99
+ type: 'suggestion',
100
+ docs: {
101
+ description: '检测函数名是否符合命名规范',
102
+ category: 'Stylistic Issues',
103
+ recommended: true,
125
104
  },
126
- create: function (context) {
127
- return {
128
- FunctionDeclaration: function (node) {
129
- handler.handleFunctionDeclaration(context, node, node, 'function');
130
- },
131
- FunctionExpression: function (node) {
132
- handler.handleFunctionExpression(context, node, node, 'function');
133
- },
134
- ArrowFunctionExpression: function (node) {
135
- handler.handleArrowFunctionExpression(context, node, node, 'function');
136
- },
137
- CallExpression: function (node) {
138
- handler.handleCallExpression(context, node, node, 'function');
139
- },
140
- MethodDefinition: function (node) {
141
- handler.handleMethodDefinition(context, node, node, 'function');
142
- },
143
- Property: function (node) {
144
- handler.handleProperty(context, node, node, 'function');
145
- },
146
- PropertyDefinition: function (node) {
147
- handler.handlePropertyDefinition(context, node, node, 'function');
148
- },
149
- AssignmentExpression: function (node) {
150
- handler.handleAssignmentExpression(context, node, node, 'function');
151
- },
152
- VariableDeclaration: function (node) {
153
- handler.handleVariableDeclaration(context, node, node, 'function');
154
- },
155
- };
156
- },
157
- };
158
- }
105
+ fixable: 'code',
106
+ schema: [],
107
+ },
108
+ create: function (context) {
109
+ var cs = new FunctionName(context);
110
+ let obj = {};
111
+ for (let key in cs) {
112
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
113
+ obj[key] = cs[key].bind(cs);
114
+ }
115
+ }
116
+ return obj
117
+ }
118
+ },
159
119
 
160
120
  /**
161
121
  * 创建变量名规则
162
122
  * @returns {object} 变量名规则配置
163
123
  */
164
- createVariableNameRule() {
165
- var handler = this.handler;
166
-
167
- return {
168
- meta: {
169
- type: 'suggestion',
170
- docs: {
171
- description: '检测变量名是否符合命名规范',
172
- category: 'Stylistic Issues',
173
- recommended: true,
174
- },
175
- fixable: 'code',
176
- schema: [],
177
- },
178
- create: function (context) {
179
- return {
180
- VariableDeclaration: function (node) {
181
- handler.handleVariableDeclaration(context, node, node, 'variable');
182
- },
183
- ForStatement: function (node) {
184
- if (node.init && node.init.type === 'VariableDeclaration') {
185
- handler.handleVariableDeclaration(context, node, node.init, 'variable');
186
- }
187
- },
188
- ForInStatement: function (node) {
189
- if (node.left && node.left.type === 'VariableDeclaration') {
190
- handler.handleVariableDeclaration(context, node, node.left, 'variable');
191
- }
192
- },
193
- ForOfStatement: function (node) {
194
- if (node.left && node.left.type === 'VariableDeclaration') {
195
- handler.handleVariableDeclaration(context, node, node.left, 'variable');
196
- }
197
- },
198
- Property: function (node) {
199
- handler.handleProperty(context, node, node, 'variable');
200
- },
201
- PropertyDefinition: function (node) {
202
- handler.handlePropertyDefinition(context, node, node, 'variable');
203
- },
204
- AssignmentExpression: function (node) {
205
- handler.handleAssignmentExpression(context, node, node, 'variable');
206
- }
207
- };
124
+ 'variable-name': {
125
+ meta: {
126
+ type: 'suggestion',
127
+ docs: {
128
+ description: '检测变量名是否符合命名规范',
129
+ category: 'Stylistic Issues',
130
+ recommended: true,
208
131
  },
209
- };
210
- }
132
+ fixable: 'code',
133
+ schema: [],
134
+ },
135
+ create: function (context) {
136
+ var cs = new VariableName(context);
137
+ let obj = {};
138
+ for (let key in cs) {
139
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
140
+ obj[key] = cs[key].bind(cs);
141
+ }
142
+ }
143
+ return obj
144
+ }
145
+ },
211
146
 
212
147
  /**
213
148
  * 创建常量名规则
214
149
  * @returns {object} 常量名规则配置
215
150
  */
216
- createConstantNameRule() {
217
- var handler = this.handler;
218
-
219
- return {
220
- meta: {
221
- type: 'suggestion',
222
- docs: {
223
- description: '检测常量名是否符合命名规范',
224
- category: 'Stylistic Issues',
225
- recommended: true,
226
- },
227
- fixable: 'code',
228
- schema: [],
229
- },
230
- create: function (context) {
231
- return {
232
- VariableDeclaration: function (node) {
233
- handler.handleVariableDeclaration(context, node, node, 'constant');
234
- },
235
- Property: function (node) {
236
- handler.handleProperty(context, node, node, 'constant');
237
- },
238
- PropertyDefinition: function (node) {
239
- handler.handlePropertyDefinition(context, node, node, 'constant');
240
- },
241
- AssignmentExpression: function (node) {
242
- handler.handleAssignmentExpression(context, node, node, 'constant');
243
- }
244
- };
151
+ 'constant-name': {
152
+ meta: {
153
+ type: 'suggestion',
154
+ docs: {
155
+ description: '检测常量名是否符合命名规范',
156
+ category: 'Stylistic Issues',
157
+ recommended: true,
245
158
  },
246
- };
247
- }
159
+ fixable: 'code',
160
+ schema: [],
161
+ },
162
+ create: function (context) {
163
+ var cs = new ConstName(context);
164
+ let obj = {};
165
+ for (let key in cs) {
166
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
167
+ obj[key] = cs[key].bind(cs);
168
+ }
169
+ }
170
+ return obj
171
+ }
172
+ },
248
173
 
249
174
  /**
250
175
  * 创建参数名规则
251
176
  * @returns {object} 参数名规则配置
252
177
  */
253
- createParamNameRule() {
254
- var handler = this.handler;
255
-
256
- return {
257
- meta: {
258
- type: 'suggestion',
259
- docs: {
260
- description: '检测参数名是否符合命名规范',
261
- category: 'Stylistic Issues',
262
- recommended: true,
263
- },
264
- fixable: 'code',
265
- schema: [],
266
- },
267
- create: function (context) {
268
- return {
269
- FunctionDeclaration: function (node) {
270
- if (node.params && node.params.length > 0) {
271
- for (var i = 0; i < node.params.length; i++) {
272
- var param = node.params[i];
273
- if (param.type === 'Identifier') {
274
- var result = handler.detector.detect(param, param.name);
275
- if (result) {
276
- result.node = param;
277
- result.fix = handler.fix.createParamFixFunction(context, param, result);
278
- context.report(result);
279
- }
280
- }
281
- }
282
- }
283
- },
284
- FunctionExpression: function (node) {
285
- if (node.params && node.params.length > 0) {
286
- for (var i = 0; i < node.params.length; i++) {
287
- var param = node.params[i];
288
- if (param.type === 'Identifier') {
289
- var result = handler.detector.detect(param, param.name);
290
- if (result) {
291
- result.node = param;
292
- result.fix = handler.fix.createParamFixFunction(context, param, result);
293
- context.report(result);
294
- }
295
- }
296
- }
297
- }
298
- },
299
- ArrowFunctionExpression: function (node) {
300
- if (node.params && node.params.length > 0) {
301
- for (var i = 0; i < node.params.length; i++) {
302
- var param = node.params[i];
303
- if (param.type === 'Identifier') {
304
- var result = handler.detector.detect(param, param.name);
305
- if (result) {
306
- result.node = param;
307
- result.fix = handler.fix.createParamFixFunction(context, param, result);
308
- context.report(result);
309
- }
310
- }
311
- }
312
- }
313
- }
314
- };
178
+ 'param-name': {
179
+ meta: {
180
+ type: 'suggestion',
181
+ docs: {
182
+ description: '检测参数名是否符合命名规范',
183
+ category: 'Stylistic Issues',
184
+ recommended: true,
315
185
  },
316
- };
186
+ fixable: 'code',
187
+ schema: [],
188
+ },
189
+ create: function (context) {
190
+ var cs = new ParamName(context);
191
+ let obj = {};
192
+ for (let key in cs) {
193
+ if (typeof cs[key] === 'function' && !key.startsWith('_')) {
194
+ obj[key] = cs[key].bind(cs);
195
+ }
196
+ }
197
+ return obj
198
+ }
317
199
  }
318
-
319
- /**
320
- * 获取所有规则
321
- * @returns {object} 所有规则配置
322
- */
323
- getAllRules() {
324
- return {
325
- 'class-name': this.createClassNameRule(),
326
- 'class-instance-name': this.createClassInstanceNameRule(),
327
- 'function-name': this.createFunctionNameRule(),
328
- 'variable-name': this.createVariableNameRule(),
329
- 'constant-name': this.createConstantNameRule(),
330
- 'param-name': this.createParamNameRule()
331
- };
332
- }
333
- }
334
-
335
- /**
336
- * 创建ESLint规则配置
337
- * @returns {object} ESLint规则配置对象
338
- */
339
- function createNamingRules() {
340
- var rules = new Rules();
341
- return rules.getAllRules();
342
200
  }
343
-
344
- module.exports = createNamingRules();