mm_eslint 1.2.5 → 1.2.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.
Files changed (2) hide show
  1. package/index.js +13 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -897,23 +897,26 @@ Detector.prototype._checkFuncProp = function (name, config, errors) {
897
897
  * @private
898
898
  */
899
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";
900
+ // 根据值节点类型和属性名模式判断是类定义还是类实例
901
+ // 1. 如果值节点是require调用,则是类定义
902
+ // 2. 如果属性名符合PascalCase命名规范,优先认为是类定义
903
+ const is_class_definition = (val_node && val_node.type === "CallExpression" &&
904
+ val_node.callee && val_node.callee.name === "require") ||
905
+ (name && /^[A-Z][a-zA-Z0-9]*$/.test(name));
903
906
  const is_class_instance = !is_class_definition;
904
907
 
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 {
908
+ if (is_class_definition) {
912
909
  // 类定义要求使用PascalCase
913
910
  const cls_res = this._checkName("class-name", name);
914
911
  if (!cls_res.valid) {
915
912
  errors.push(`${config.name}(类)${cls_res.errors.join(", ")}`);
916
913
  }
914
+ } else {
915
+ // 类实例允许使用小驼峰命名
916
+ const func_res = this._checkName("function-name", name);
917
+ if (!func_res.valid) {
918
+ errors.push(`${config.name}(类实例)${func_res.errors.join(", ")}`);
919
+ }
917
920
  }
918
921
  };
919
922
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
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": [