mm_eslint 1.4.4 → 1.4.5

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
@@ -22,12 +22,12 @@
22
22
  ## 实际支持的规则
23
23
 
24
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` - 常量名检测
25
+ - `mm_eslint/class-name` - 类名检测
26
+ - `mm_eslint/class-instance-name` - 类实例名检测
27
+ - `mm_eslint/function-name` - 函数名检测
28
+ - `mm_eslint/param-name` - 参数名检测
29
+ - `mm_eslint/variable-name` - 变量名检测
30
+ - `mm_eslint/constant-name` - 常量名检测
31
31
 
32
32
  ## 安装
33
33
 
@@ -54,28 +54,30 @@ cp mm_eslint/index.js your-project/eslint-plugins/
54
54
 
55
55
  ```javascript
56
56
  // eslint.config.js
57
- const namingConventionPlugin = require("mm_eslint");
57
+ const mmEslint = require('mm_eslint');
58
58
 
59
59
  module.exports = [
60
60
  {
61
- files: ["**/*.js"],
61
+ files: ['**/*.js'],
62
62
  plugins: {
63
- "naming-convention": namingConventionPlugin,
63
+ mm_eslint: {
64
+ rules: mmEslint
65
+ }
64
66
  },
65
67
  rules: {
66
68
  // 命名规范插件规则
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",
69
+ 'mm_eslint/class-name': 'error',
70
+ 'mm_eslint/class-instance-name': 'error',
71
+ 'mm_eslint/function-name': 'error',
72
+ 'mm_eslint/param-name': 'warn',
73
+ 'mm_eslint/variable-name': 'warn',
74
+ 'mm_eslint/constant-name': 'error',
73
75
 
74
76
  // 禁用与命名规范插件冲突的默认规则
75
- camelcase: "off",
76
- "id-match": "off",
77
- "new-cap": "off",
78
- "id-length": "off",
77
+ camelcase: 'off',
78
+ 'id-match': 'off',
79
+ 'new-cap': 'off',
80
+ 'id-length': 'off',
79
81
  },
80
82
  },
81
83
  ];
@@ -273,7 +275,10 @@ mm_eslint/
273
275
  ├── corrector.js # 命名修正器
274
276
  ├── tip.js # 提示信息
275
277
  ├── util.js # 工具函数
278
+ ├── handler.js # 规则处理器
279
+ ├── fix.js # 自动修复功能
276
280
  ├── package.json # npm配置
281
+ ├── eslint.config.js # ESLint配置示例
277
282
  ├── README.md # 中文说明文档
278
283
  ├── README_EN.md # 英文说明文档
279
284
  ├── LICENSE # 许可证
@@ -303,6 +308,12 @@ ISC License
303
308
 
304
309
  ## 更新日志
305
310
 
311
+ ### v1.4.4
312
+ - 更新插件名称和规则前缀为 `mm_eslint`
313
+ - 优化模块结构和文件组织
314
+ - 增强测试覆盖率和错误处理
315
+ - 改进文档和示例
316
+
306
317
  ### v1.4.3
307
318
  - 优化模块结构和文件组织
308
319
  - 增强测试覆盖率和错误处理
package/README_EN.md CHANGED
@@ -22,12 +22,12 @@ ESLint plugin for personal naming conventions - supports PascalCase, camelCase,
22
22
  ## Actual Supported Rules
23
23
 
24
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
25
+ - `mm_eslint/class-name` - Class name detection
26
+ - `mm_eslint/class-instance-name` - Class instance name detection
27
+ - `mm_eslint/function-name` - Function name detection
28
+ - `mm_eslint/param-name` - Parameter name detection
29
+ - `mm_eslint/variable-name` - Variable name detection
30
+ - `mm_eslint/constant-name` - Constant name detection
31
31
 
32
32
  ## Installation
33
33
 
@@ -54,28 +54,30 @@ Import the plugin in your ESLint configuration file:
54
54
 
55
55
  ```javascript
56
56
  // eslint.config.js
57
- const namingConventionPlugin = require("mm_eslint");
57
+ const mmEslint = require('mm_eslint');
58
58
 
59
59
  module.exports = [
60
60
  {
61
- files: ["**/*.js"],
61
+ files: ['**/*.js'],
62
62
  plugins: {
63
- "naming-convention": namingConventionPlugin,
63
+ mm_eslint: {
64
+ rules: mmEslint
65
+ }
64
66
  },
65
67
  rules: {
66
68
  // 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",
69
+ 'mm_eslint/class-name': 'error',
70
+ 'mm_eslint/class-instance-name': 'error',
71
+ 'mm_eslint/function-name': 'error',
72
+ 'mm_eslint/param-name': 'warn',
73
+ 'mm_eslint/variable-name': 'warn',
74
+ 'mm_eslint/constant-name': 'error',
73
75
 
74
76
  // Disable default rules conflicting with naming convention plugin
75
- camelcase: "off",
76
- "id-match": "off",
77
- "new-cap": "off",
78
- "id-length": "off",
77
+ camelcase: 'off',
78
+ 'id-match': 'off',
79
+ 'new-cap': 'off',
80
+ 'id-length': 'off',
79
81
  },
80
82
  },
81
83
  ];
@@ -273,7 +275,10 @@ mm_eslint/
273
275
  ├── corrector.js # Name corrector
274
276
  ├── tip.js # Tip messages
275
277
  ├── util.js # Utility functions
278
+ ├── handler.js # Rule handler
279
+ ├── fix.js # Auto-fix functionality
276
280
  ├── package.json # npm configuration
281
+ ├── eslint.config.js # ESLint configuration example
277
282
  ├── README.md # Chinese documentation
278
283
  ├── README_EN.md # English documentation
279
284
  ├── LICENSE # License
@@ -303,6 +308,12 @@ Issues and Pull Requests are welcome to improve this plugin.
303
308
 
304
309
  ## Changelog
305
310
 
311
+ ### v1.4.4
312
+ - Updated plugin name and rule prefix to `mm_eslint`
313
+ - Optimized module structure and file organization
314
+ - Enhanced test coverage and error handling
315
+ - Improved documentation and examples
316
+
306
317
  ### v1.4.3
307
318
  - Optimized module structure and file organization
308
319
  - Enhanced test coverage and error handling
package/config.js CHANGED
@@ -47,8 +47,8 @@ class Config {
47
47
  */
48
48
  Config.prototype.getRegex = function (style) {
49
49
  var regex = {
50
- "PascalCase": /^[A-Z][a-z]*([A-Z][a-z]*)*$/,
51
- "camelCase": /^[a-z][a-z]*([A-Z][a-z]*)*$/,
50
+ "PascalCase": /^[A-Z][a-z]+[A-Za-z]*$/,
51
+ "camelCase": /^[a-z][a-z]*([A-Z][a-z]*)*[a-z0-9]*$/,
52
52
  "snake_case": /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,
53
53
  "UPPER_SNAKE_CASE": /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/,
54
54
  "lowercase": /^[a-z]+([a-z0-9]+)*$/,
@@ -65,7 +65,7 @@ Config.prototype.getRegex = function (style) {
65
65
  * @returns {Array} 禁止拼接词列表
66
66
  */
67
67
  Config.prototype.getForbiddenWords = function (name_type) {
68
- let type = name_type.replace('property-', '').replace('instance-', '');
68
+ let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
69
69
  var forbidden = {
70
70
  'class': [
71
71
  'manager',
@@ -103,6 +103,7 @@ Config.prototype.getForbiddenWords = function (name_type) {
103
103
  'field',
104
104
  'property',
105
105
  'entity',
106
+ 'data'
106
107
  ],
107
108
  'function': [
108
109
  'data',
@@ -149,10 +150,10 @@ Config.prototype.getForbiddenWords = function (name_type) {
149
150
  'array',
150
151
  'map',
151
152
  'set',
152
- 'collection',
153
153
  'container',
154
154
  'instance',
155
155
  'data',
156
+ 'collection',
156
157
  'item',
157
158
  'items',
158
159
  'element',
@@ -300,6 +301,38 @@ Config.prototype.getBaseRule = function (name_type) {
300
301
  single_word: true,
301
302
  single_word_len: 8
302
303
  },
304
+ 'param-function': {
305
+ name: '函数类型参数',
306
+ min: 1,
307
+ max: 20,
308
+ styles: ['camelCase'],
309
+ single_word: true,
310
+ single_word_len: 8
311
+ },
312
+ 'param-class': {
313
+ name: '类类型参数',
314
+ min: 1,
315
+ max: 20,
316
+ styles: ['PascalCase'],
317
+ single_word: true,
318
+ single_word_len: 8
319
+ },
320
+ 'param-object': {
321
+ name: '对象类型参数',
322
+ min: 1,
323
+ max: 20,
324
+ styles: ['snake_case'],
325
+ single_word: true,
326
+ single_word_len: 8
327
+ },
328
+ 'param-variable': {
329
+ name: '变量类型参数',
330
+ min: 1,
331
+ max: 20,
332
+ styles: ['snake_case'],
333
+ single_word: true,
334
+ single_word_len: 8
335
+ },
303
336
  'variable': {
304
337
  name: '变量名',
305
338
  min: 1,
@@ -341,13 +374,7 @@ Config.prototype.getRule = function (name_type) {
341
374
  * @returns {object} 推荐词映射
342
375
  */
343
376
  Config.prototype.getRecommendWords = function (name_type) {
344
- let type = name_type.replace('property-', '').replace('instance-', '');
345
- if (type == 'function') {
346
- type = 'function';
347
- }
348
- else if (type == 'value') {
349
- type = 'variable';
350
- }
377
+ let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
351
378
  var recommend = {
352
379
  'class': {
353
380
  'App': ['Application'],
@@ -466,7 +493,7 @@ Config.prototype.getRecommendWords = function (name_type) {
466
493
  * @returns {Array} 忽略词列表
467
494
  */
468
495
  Config.prototype.getIgnoreWords = function (name_type) {
469
- let type = name_type.replace('property-', '').replace('instance-', '');
496
+ let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
470
497
  var ignore = {
471
498
  'class': [
472
499
  'exports', 'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transformer', 'Template'
@@ -535,23 +562,34 @@ Config.prototype.getTypeNameMap = function () {
535
562
  'class-instance': '类实例',
536
563
  'class': '类',
537
564
  'constant': '常量',
538
- 'property-function': '属性函数',
539
- 'property-variable': '属性变量',
540
- 'property-class-instance': '属性类实例',
541
- 'property-class': '属性类',
542
- 'property-constant': '属性常量',
543
- 'static-function': '静态函数',
544
- 'static-variable': '静态变量',
545
- 'static-class-instance': '静态类实例',
546
- 'static-class': '静态类',
547
- 'static-constant': '静态常量',
565
+ 'property-function': '属性—函数',
566
+ 'property-variable': '属性—变量',
567
+ 'property-class-instance': '属性—类实例',
568
+ 'property-class': '属性—类',
569
+ 'property-constant': '属性—常量',
570
+ 'static-function': '静态属性—函数',
571
+ 'static-variable': '静态属性—变量',
572
+ 'static-class-instance': '静态属性—类实例',
573
+ 'static-class': '静态属性—类',
574
+ 'static-constant': '静态属性—常量',
548
575
  'prototype-function': '原型函数',
549
576
  'prototype-variable': '原型变量',
550
577
  'prototype-class-instance': '原型类实例',
551
- 'prototype-class': '原型类',
552
- 'prototype-constant': '原型常量',
553
- 'private-function': '私有函数',
554
- 'private-variable': '私有变量'
578
+ 'private-function': '私有属性—函数',
579
+ 'private-variable': '私有属性—变量',
580
+ 'private-class-instance': '私有属性—类实例',
581
+ 'internal-function': '内部属性—函数',
582
+ 'internal-variable': '内部属性—变量',
583
+ 'internal-class-instance': '内部属性—类实例',
584
+ 'use-variable': '引用-变量',
585
+ 'use-function': '引用-函数',
586
+ 'use-class': '引用-类',
587
+ 'use-constant': '引用-常量',
588
+ 'use-class-instance': '引用-类实例',
589
+ 'param-class': '参数—类',
590
+ 'param-class-instance': '参数—类实例',
591
+ 'param-variable': '参数—变量',
592
+ 'param-function': '参数—函数'
555
593
  };
556
594
  return type_name_map;
557
595
  }
package/corrector.js CHANGED
@@ -43,7 +43,15 @@ Corrector.prototype.getSuggestion = function (error) {
43
43
  } catch {
44
44
  return error.name;
45
45
  }
46
- return error.prefix + word;
46
+
47
+ var suggestion = error.prefix + word;
48
+
49
+ // 检查建议名称是否与原名称相同,如果相同则不显示建议
50
+ if (suggestion === error.name || word === error.name) {
51
+ return null;
52
+ }
53
+
54
+ return suggestion;
47
55
  };
48
56
 
49
57
  /**
@@ -273,9 +281,54 @@ Corrector.prototype._filterForbiddenWord = function (words, forbidden_words) {
273
281
  new_word.push(word);
274
282
  }
275
283
  }
284
+ if (new_word.length === 0) {
285
+ new_word.push(words[words.length - 1]);
286
+ }
276
287
  return new_word;
277
288
  }
278
289
 
290
+ /**
291
+ * 替换禁止词汇为推荐词汇
292
+ * @param {string[]} words 单词数组
293
+ * @param {Array} forbidden_words 禁止词列表
294
+ * @param {object} recommend_words 推荐词配置
295
+ * @returns {string[]} 替换后的单词数组
296
+ */
297
+ Corrector.prototype._replaceForbiddenWords = function (words, forbidden_words, recommend_words) {
298
+ var new_words = [];
299
+ for (let i = 0; i < words.length; i++) {
300
+ let word = words[i];
301
+ if (this._isForbiddenWord(word, forbidden_words)) {
302
+ // 尝试为禁用词找到替代建议
303
+ var replacement = this._getForbiddenWordReplacement(word, recommend_words);
304
+ if (replacement) {
305
+ new_words.push(replacement);
306
+ }
307
+ } else {
308
+ new_words.push(word);
309
+ }
310
+ }
311
+ return new_words;
312
+ }
313
+
314
+ /**
315
+ * 获取禁用词的替代建议
316
+ * @param {string} forbidden_word 禁用词
317
+ * @param {object} recommend_words 推荐词配置
318
+ * @returns {string} 替代建议词
319
+ */
320
+ Corrector.prototype._getForbiddenWordReplacement = function (forbidden_word, recommend_words) {
321
+ for (var replacement in recommend_words) {
322
+ var forbidden_list = recommend_words[replacement];
323
+ for (let i = 0; i < forbidden_list.length; i++) {
324
+ if (forbidden_word.toLowerCase() === forbidden_list[i].toLowerCase()) {
325
+ return replacement;
326
+ }
327
+ }
328
+ }
329
+ return null;
330
+ }
331
+
279
332
  /**
280
333
  * 获取推荐的单词
281
334
  * @param {string[]} words 单词数组
@@ -284,7 +337,6 @@ Corrector.prototype._filterForbiddenWord = function (words, forbidden_words) {
284
337
  * @returns {string[]} 推荐的单词数组
285
338
  */
286
339
  Corrector.prototype._toRecommendWords = function (words, recommend, single_word_len) {
287
- // console.log('推荐单词', words, recommend, single_word_len);
288
340
  let recommend_words = [];
289
341
  for (let i = 0; i < words.length; i++) {
290
342
  let word = words[i];