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 +30 -19
- package/README_EN.md +30 -19
- package/config.js +64 -26
- package/corrector.js +54 -2
- package/detector.js +1290 -1238
- package/eslint.config.js +5 -2
- package/fix.js +441 -0
- package/handler.js +993 -0
- package/index.js +344 -1045
- package/package.json +7 -2
- package/tip.js +84 -70
- package/validator.js +10 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_eslint",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "ESLint plugin for naming conventions - PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -36,11 +36,13 @@
|
|
|
36
36
|
"lint": "npx eslint . --config eslint.config.js"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
|
-
"index.js",
|
|
40
39
|
"config.js",
|
|
41
40
|
"corrector.js",
|
|
42
41
|
"detector.js",
|
|
43
42
|
"eslint.config.js",
|
|
43
|
+
"fix.js",
|
|
44
|
+
"handler.js",
|
|
45
|
+
"index.js",
|
|
44
46
|
"tip.js",
|
|
45
47
|
"util.js",
|
|
46
48
|
"validator.js",
|
|
@@ -50,5 +52,8 @@
|
|
|
50
52
|
],
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"eslint-plugin-jsdoc": "^61.5.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@babel/parser": "^7.28.6"
|
|
53
58
|
}
|
|
54
59
|
}
|
package/tip.js
CHANGED
|
@@ -1,71 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 提示管理类
|
|
7
|
-
* 统一管理所有错误提示和建议使用词的生成
|
|
8
|
-
*/
|
|
9
|
-
class Tip {
|
|
10
|
-
/**
|
|
11
|
-
* 构造函数
|
|
12
|
-
* @param {object} config 配置对象
|
|
13
|
-
*/
|
|
14
|
-
constructor(config) {
|
|
15
|
-
this.config = config || new Config();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
var { Config } = require('./config');
|
|
2
|
+
var { Corrector } = require('./corrector');
|
|
3
|
+
var corrector = new Corrector();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 提示管理类
|
|
7
|
+
* 统一管理所有错误提示和建议使用词的生成
|
|
8
|
+
*/
|
|
9
|
+
class Tip {
|
|
10
|
+
/**
|
|
11
|
+
* 构造函数
|
|
12
|
+
* @param {object} config 配置对象
|
|
13
|
+
*/
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config || new Config();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 生成完整的错误提示
|
|
21
|
+
* @param {object} error 错误信息
|
|
22
|
+
* @param {string} fix_suggestion 修正建议
|
|
23
|
+
* @returns {string} 完整的错误提示
|
|
24
|
+
*/
|
|
25
|
+
Tip.prototype.getFullMessage = function(error, fix_suggestion) {
|
|
26
|
+
var base_message = this._getBaseMessage(error);
|
|
27
|
+
var suggestion = fix_suggestion || corrector.getSuggestion(error);
|
|
28
|
+
if (suggestion) {
|
|
29
|
+
return base_message + ',建议使用:' + suggestion;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return base_message;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取声明方式问题的错误消息
|
|
37
|
+
* @param {string} issue_type 问题类型
|
|
38
|
+
* @param {string} name 名称
|
|
39
|
+
* @returns {string} 错误消息
|
|
40
|
+
*/
|
|
41
|
+
Tip.prototype.getDeclarationIssueMessage = function(issue_type, name) {
|
|
42
|
+
switch (issue_type) {
|
|
43
|
+
case 'const-should-be-let':
|
|
44
|
+
return `变量'${name}'应该用let声明而不是const`;
|
|
45
|
+
default:
|
|
46
|
+
return `变量'${name}'声明方式不符合规范`;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 获取基础错误消息
|
|
52
|
+
* @param {object} error 错误信息对象
|
|
53
|
+
* @returns {string} 基础错误消息
|
|
54
|
+
*/
|
|
55
|
+
Tip.prototype._getBaseMessage = function(error) {
|
|
56
|
+
var type_name_map = this.config.getTypeNameMap();
|
|
57
|
+
var name = error.name;
|
|
58
|
+
var original_type = error.original_type || 'variable';
|
|
59
|
+
var type_name = type_name_map[original_type] || '名称';
|
|
60
|
+
|
|
61
|
+
switch (error.type) {
|
|
62
|
+
case 'style':
|
|
63
|
+
var styles = error.rule.styles.join('、');
|
|
64
|
+
return `${type_name}'${name}'命名不符合${styles}风格`;
|
|
65
|
+
|
|
66
|
+
case 'length':
|
|
67
|
+
if (error.min_length) {
|
|
68
|
+
return `${type_name}'${name}'小于最小长度${error.min_length}字符`;
|
|
69
|
+
} else {
|
|
70
|
+
return `${type_name}'${name}'超过最大长度${error.max_length}字符`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case 'word_length':
|
|
74
|
+
var word = error.word || name;
|
|
75
|
+
return `${type_name}'${name}'拼接单词"${word}"超过最大长度${error.max_word_length}字符`;
|
|
76
|
+
|
|
77
|
+
case 'forbidden_word':
|
|
78
|
+
return `${type_name}'${name}'拼接了禁用词"${error.forbidden_word}"`;
|
|
79
|
+
|
|
80
|
+
default:
|
|
81
|
+
return `${type_name}'${name}'不符合命名规范`;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
71
85
|
module.exports = { Tip };
|
package/validator.js
CHANGED
|
@@ -152,7 +152,7 @@ Validator.prototype._validateLength = function (name, min = 1, max = 32) {
|
|
|
152
152
|
* @returns {string} 验证类型
|
|
153
153
|
*/
|
|
154
154
|
Validator.prototype._getValidationType = function (original_type) {
|
|
155
|
-
return original_type.replace('property-', '').replace('static-', '').replace('prototype-', '').replace('private-', '');
|
|
155
|
+
return original_type.replace('property-', '').replace('static-', '').replace('prototype-', '').replace('private-', '').replace('internal-', '').replace('use-', '').replace('param-', '');
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
/**
|
|
@@ -218,9 +218,9 @@ Validator.prototype._validateForbiddenWords = function (words, forbidden_words)
|
|
|
218
218
|
if (!forbidden_words || forbidden_words.length === 0) {
|
|
219
219
|
return null;
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
let word = this.getForbiddenWord(
|
|
221
|
+
|
|
222
|
+
for (var i = 0; i < words.length; i++) {
|
|
223
|
+
let word = this.getForbiddenWord(forbidden_words, words[i]);
|
|
224
224
|
if (word) {
|
|
225
225
|
return {
|
|
226
226
|
type: 'forbidden_word',
|
|
@@ -229,24 +229,20 @@ Validator.prototype._validateForbiddenWords = function (words, forbidden_words)
|
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
|
|
233
232
|
return null;
|
|
234
233
|
};
|
|
235
234
|
|
|
236
235
|
/**
|
|
237
236
|
* 检查单词数组是否包含禁止拼接词
|
|
238
|
-
* @param {array}
|
|
239
|
-
* @param {string}
|
|
237
|
+
* @param {array} forbidden_words 禁止拼接词组
|
|
238
|
+
* @param {string} word 单词
|
|
240
239
|
* @returns {boolean} 是否包含禁止拼接词
|
|
241
240
|
*/
|
|
242
|
-
Validator.prototype.getForbiddenWord = function (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
for (var i = 0; i < words.length; i++) {
|
|
247
|
-
var word = words[i];
|
|
241
|
+
Validator.prototype.getForbiddenWord = function (forbidden_words, word) {
|
|
242
|
+
let word_lower = word.toLowerCase();
|
|
243
|
+
for (var i = 0; i < forbidden_words.length; i++) {
|
|
248
244
|
// 忽略大小写进行比较
|
|
249
|
-
if (
|
|
245
|
+
if (forbidden_words[i].toLowerCase() === word_lower) {
|
|
250
246
|
return word;
|
|
251
247
|
}
|
|
252
248
|
}
|