mm_eslint 1.2.2 → 1.2.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/index.js +33 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -790,7 +790,7 @@ Detector.prototype._checkPropName = function (name, val_node, parent_node) {
|
|
|
790
790
|
const val_type = this._getPropType(val_node, name, parent_node);
|
|
791
791
|
|
|
792
792
|
if (use_strong_val) {
|
|
793
|
-
this._checkPropStrong(name, val_type, config, errors);
|
|
793
|
+
this._checkPropStrong(name, val_type, config, errors, val_node);
|
|
794
794
|
} else {
|
|
795
795
|
this._checkPropWeak(name, val_type, config, errors);
|
|
796
796
|
}
|
|
@@ -820,6 +820,11 @@ Detector.prototype._checkPropLength = function (name, config, errors) {
|
|
|
820
820
|
|
|
821
821
|
/**
|
|
822
822
|
* 强验证模式检查
|
|
823
|
+
* @param {string} name - 属性名
|
|
824
|
+
* @param {string} val_type - 值类型
|
|
825
|
+
* @param {Object} config - 配置对象
|
|
826
|
+
* @param {Array} errors - 错误数组
|
|
827
|
+
* @param {Object} val_node - 属性值AST节点(可选)
|
|
823
828
|
* @private
|
|
824
829
|
*/
|
|
825
830
|
Detector.prototype._checkPropStrong = function (
|
|
@@ -827,6 +832,7 @@ Detector.prototype._checkPropStrong = function (
|
|
|
827
832
|
val_type,
|
|
828
833
|
config,
|
|
829
834
|
errors,
|
|
835
|
+
val_node,
|
|
830
836
|
) {
|
|
831
837
|
switch (val_type) {
|
|
832
838
|
case "function":
|
|
@@ -836,7 +842,7 @@ Detector.prototype._checkPropStrong = function (
|
|
|
836
842
|
this._checkMethodProp(name, config, errors);
|
|
837
843
|
break;
|
|
838
844
|
case "class":
|
|
839
|
-
this._checkClassProp(name, config, errors);
|
|
845
|
+
this._checkClassProp(name, config, errors, val_node);
|
|
840
846
|
break;
|
|
841
847
|
case "constant":
|
|
842
848
|
this._checkConstProp(name, config, errors);
|
|
@@ -884,12 +890,30 @@ Detector.prototype._checkFuncProp = function (name, config, errors) {
|
|
|
884
890
|
|
|
885
891
|
/**
|
|
886
892
|
* 检查类属性
|
|
893
|
+
* @param {string} name - 属性名
|
|
894
|
+
* @param {Object} config - 配置对象
|
|
895
|
+
* @param {Array} errors - 错误数组
|
|
896
|
+
* @param {Object} val_node - 属性值AST节点(可选)
|
|
887
897
|
* @private
|
|
888
898
|
*/
|
|
889
|
-
Detector.prototype._checkClassProp = function (name, config, errors) {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
899
|
+
Detector.prototype._checkClassProp = function (name, config, errors, val_node) {
|
|
900
|
+
// 根据值节点类型判断是类定义还是类实例
|
|
901
|
+
const is_class_definition = val_node && val_node.type === "CallExpression" &&
|
|
902
|
+
val_node.callee && val_node.callee.name === "require";
|
|
903
|
+
const is_class_instance = !is_class_definition;
|
|
904
|
+
|
|
905
|
+
if (is_class_instance) {
|
|
906
|
+
// 类实例允许使用小驼峰命名
|
|
907
|
+
const func_res = this._checkName("function-name", name);
|
|
908
|
+
if (!func_res.valid) {
|
|
909
|
+
errors.push(`${config.name}(类实例)${func_res.errors.join(", ")}`);
|
|
910
|
+
}
|
|
911
|
+
} else {
|
|
912
|
+
// 类定义要求使用PascalCase
|
|
913
|
+
const cls_res = this._checkName("class-name", name);
|
|
914
|
+
if (!cls_res.valid) {
|
|
915
|
+
errors.push(`${config.name}(类)${cls_res.errors.join(", ")}`);
|
|
916
|
+
}
|
|
893
917
|
}
|
|
894
918
|
};
|
|
895
919
|
|
|
@@ -2176,10 +2200,10 @@ const variable_name_rule = {
|
|
|
2176
2200
|
node.init.callee &&
|
|
2177
2201
|
node.init.callee.type === "Identifier" &&
|
|
2178
2202
|
/^[A-Z][a-zA-Z]*$/.test(node.init.callee.name)) {
|
|
2179
|
-
//
|
|
2203
|
+
// 这是类实例,应该使用函数名规则(camelCase)
|
|
2180
2204
|
const class_instance_name = node.id.name;
|
|
2181
|
-
const detector = new Detector({ "
|
|
2182
|
-
const result = detector.checkName(class_instance_name, "
|
|
2205
|
+
const detector = new Detector({ "function-name": options });
|
|
2206
|
+
const result = detector.checkName(class_instance_name, "function-name");
|
|
2183
2207
|
|
|
2184
2208
|
if (!result.valid) {
|
|
2185
2209
|
result.errors.forEach((error) => {
|