mm_eslint 1.2.1 → 1.2.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/index.js +28 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -887,9 +887,22 @@ Detector.prototype._checkFuncProp = function (name, config, errors) {
|
|
|
887
887
|
* @private
|
|
888
888
|
*/
|
|
889
889
|
Detector.prototype._checkClassProp = function (name, config, errors) {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
890
|
+
// 对于类实例的属性名,允许使用小驼峰命名
|
|
891
|
+
// 只有类定义本身才要求使用PascalCase
|
|
892
|
+
const is_class_instance = true; // 这里可以根据上下文进一步优化
|
|
893
|
+
|
|
894
|
+
if (is_class_instance) {
|
|
895
|
+
// 类实例允许使用小驼峰命名
|
|
896
|
+
const func_res = this._checkName("function-name", name);
|
|
897
|
+
if (!func_res.valid) {
|
|
898
|
+
errors.push(`${config.name}(类实例)${func_res.errors.join(", ")}`);
|
|
899
|
+
}
|
|
900
|
+
} else {
|
|
901
|
+
// 类定义要求使用PascalCase
|
|
902
|
+
const cls_res = this._checkName("class-name", name);
|
|
903
|
+
if (!cls_res.valid) {
|
|
904
|
+
errors.push(`${config.name}(类)${cls_res.errors.join(", ")}`);
|
|
905
|
+
}
|
|
893
906
|
}
|
|
894
907
|
};
|
|
895
908
|
|
|
@@ -1039,6 +1052,18 @@ Detector.prototype._getPropType = function (val_node, prop_name, parent_node) {
|
|
|
1039
1052
|
return "method"; // 对象方法类型
|
|
1040
1053
|
}
|
|
1041
1054
|
|
|
1055
|
+
// 优先检查属性名是否符合类命名规范(PascalCase)
|
|
1056
|
+
// 当属性名符合PascalCase时,优先考虑类类型
|
|
1057
|
+
if (prop_name && /^[A-Z][a-zA-Z0-9]*$/.test(prop_name)) {
|
|
1058
|
+
const common_config_names = ['config', 'options', 'params', 'settings', 'props'];
|
|
1059
|
+
const is_common_config = common_config_names.includes(prop_name.toLowerCase());
|
|
1060
|
+
|
|
1061
|
+
// 如果属性名符合PascalCase且不是常见配置参数名,优先认为是类类型
|
|
1062
|
+
if (!is_common_config) {
|
|
1063
|
+
return "class";
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1042
1067
|
// 检查是否为函数
|
|
1043
1068
|
if (
|
|
1044
1069
|
val_node.type === "FunctionExpression" ||
|