mm_eslint 1.2.3 → 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.
Files changed (2) hide show
  1. package/index.js +20 -9
  2. 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,17 @@ 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
- // 只有类定义本身才要求使用PascalCase
892
- const is_class_instance = true; // 这里可以根据上下文进一步优化
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;
893
904
 
894
905
  if (is_class_instance) {
895
906
  // 类实例允许使用小驼峰命名
@@ -2189,10 +2200,10 @@ const variable_name_rule = {
2189
2200
  node.init.callee &&
2190
2201
  node.init.callee.type === "Identifier" &&
2191
2202
  /^[A-Z][a-zA-Z]*$/.test(node.init.callee.name)) {
2192
- // 这是类实例,应该由变量名规则处理(类实例是变量,不是类)
2203
+ // 这是类实例,应该使用函数名规则(camelCase)
2193
2204
  const class_instance_name = node.id.name;
2194
- const detector = new Detector({ "variable-name": options });
2195
- const result = detector.checkName(class_instance_name, "variable-name");
2205
+ const detector = new Detector({ "function-name": options });
2206
+ const result = detector.checkName(class_instance_name, "function-name");
2196
2207
 
2197
2208
  if (!result.valid) {
2198
2209
  result.errors.forEach((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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": [