eslint-plugin-class-validator-type-match 4.1.7 → 4.1.8

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.
@@ -163,6 +163,13 @@ export declare function hasEachOption(decorator: TSESTree.Decorator): boolean;
163
163
  * Returns false for decorators without parentheses or without the each option.
164
164
  */
165
165
  export declare function hasValidateNestedEachOption(decorator: TSESTree.Decorator): boolean;
166
+ /**
167
+ * Checks if a type is an object-producing utility type or Record.
168
+ * These types always produce object types and should be valid with @IsObject.
169
+ *
170
+ * Includes: Record, Partial, Required, Pick, Omit, Readonly
171
+ */
172
+ export declare function isObjectUtilityType(typeNode: TSESTree.TypeNode): boolean;
166
173
  /**
167
174
  * Validates if a decorator matches the TypeScript type annotation.
168
175
  * Handles special cases like @IsEnum validation, nullable unions, and utility types.
@@ -22,6 +22,7 @@ exports.isEnumArgumentArraySubset = isEnumArgumentArraySubset;
22
22
  exports.getTypeDecoratorClassName = getTypeDecoratorClassName;
23
23
  exports.hasEachOption = hasEachOption;
24
24
  exports.hasValidateNestedEachOption = hasValidateNestedEachOption;
25
+ exports.isObjectUtilityType = isObjectUtilityType;
25
26
  exports.checkTypeMatch = checkTypeMatch;
26
27
  /**
27
28
  * Decorators that don't enforce specific types and can work with any type.
@@ -780,6 +781,21 @@ function hasEachOption(decorator) {
780
781
  function hasValidateNestedEachOption(decorator) {
781
782
  return hasEachOption(decorator);
782
783
  }
784
+ /**
785
+ * Checks if a type is an object-producing utility type or Record.
786
+ * These types always produce object types and should be valid with @IsObject.
787
+ *
788
+ * Includes: Record, Partial, Required, Pick, Omit, Readonly
789
+ */
790
+ function isObjectUtilityType(typeNode) {
791
+ const unwrapped = unwrapReadonlyOperator(typeNode);
792
+ if (unwrapped.type !== 'TSTypeReference') {
793
+ return false;
794
+ }
795
+ const typeName = getTypeReferenceName(unwrapped.typeName);
796
+ const objectUtilityTypes = ['Record', 'Partial', 'Required', 'Pick', 'Omit', 'Readonly'];
797
+ return objectUtilityTypes.includes(typeName);
798
+ }
783
799
  /**
784
800
  * Validates if a decorator matches the TypeScript type annotation.
785
801
  * Handles special cases like @IsEnum validation, nullable unions, and utility types.
@@ -790,6 +806,10 @@ function checkTypeMatch(decorator, typeAnnotation, actualType, checker, esTreeNo
790
806
  if (!expectedTypes || expectedTypes.length === 0) {
791
807
  return true;
792
808
  }
809
+ // Special handling for @IsObject and @IsNotEmptyObject - utility types that produce objects
810
+ if ((decorator === 'IsObject' || decorator === 'IsNotEmptyObject') && isObjectUtilityType(typeAnnotation)) {
811
+ return true;
812
+ }
793
813
  // Special handling for @IsEnum
794
814
  if (decorator === 'IsEnum') {
795
815
  // @IsEnum should work with:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-class-validator-type-match",
3
- "version": "4.1.7",
3
+ "version": "4.1.8",
4
4
  "description": "ESLint plugin to ensure class-validator decorators match TypeScript type annotations",
5
5
  "keywords": [
6
6
  "eslint",