eslint-plugin-class-validator-type-match 2.1.0 → 3.0.0
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/dist/index.d.ts +25 -1
- package/dist/index.js +27 -0
- package/dist/rules/decorator-type-match.d.ts +39 -27
- package/dist/rules/decorator-type-match.js +54 -1084
- package/dist/rules/definite-assignment-match.d.ts +57 -0
- package/dist/rules/definite-assignment-match.js +143 -0
- package/dist/rules/type-decorator-match.d.ts +43 -0
- package/dist/rules/type-decorator-match.js +235 -0
- package/dist/rules/validate-nested-match.d.ts +50 -0
- package/dist/rules/validate-nested-match.js +259 -0
- package/dist/utils/type-helpers.util.d.ts +158 -0
- package/dist/utils/type-helpers.util.js +776 -0
- package/package.json +1 -1
- package/readme.md +108 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
rules: {
|
|
3
|
-
'decorator-type-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"mismatch" | "
|
|
3
|
+
'decorator-type-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"mismatch" | "enumMismatch" | "invalidEachOption", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
|
|
4
4
|
'optional-decorator-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingOptionalDecorator" | "missingOptionalSyntax" | "conflictingDefiniteAssignment" | "undefinedUnionWithoutDecorator" | "undefinedUnionWithoutOptional" | "nullUnionIncorrect" | "redundantUndefinedInType", [{
|
|
5
5
|
strictNullChecks?: boolean;
|
|
6
6
|
checkDefaultValues?: boolean;
|
|
7
7
|
customOptionalDecorators?: string[];
|
|
8
8
|
}], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
|
|
9
|
+
'validate-nested-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"nestedArrayMismatch" | "missingValidateNested" | "missingEachOption" | "unnecessaryValidateNested" | "tupleValidationWarning" | "multiTypeUnionWarning" | "mixedComplexityUnionWarning" | "pickOmitWarning", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
|
|
10
|
+
'type-decorator-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"typeMismatch" | "missingTypeDecorator", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
|
|
11
|
+
'definite-assignment-match': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDefiniteAssignment", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
|
|
9
12
|
};
|
|
10
13
|
configs: {
|
|
11
14
|
recommended: {
|
|
@@ -13,6 +16,27 @@ declare const _default: {
|
|
|
13
16
|
rules: {
|
|
14
17
|
'class-validator-type-match/decorator-type-match': string;
|
|
15
18
|
'class-validator-type-match/optional-decorator-match': string;
|
|
19
|
+
'class-validator-type-match/validate-nested-match': string;
|
|
20
|
+
'class-validator-type-match/type-decorator-match': string;
|
|
21
|
+
'class-validator-type-match/definite-assignment-match': string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
strict: {
|
|
25
|
+
plugins: string[];
|
|
26
|
+
rules: {
|
|
27
|
+
'class-validator-type-match/decorator-type-match': string;
|
|
28
|
+
'class-validator-type-match/optional-decorator-match': string;
|
|
29
|
+
'class-validator-type-match/validate-nested-match': string;
|
|
30
|
+
'class-validator-type-match/type-decorator-match': string;
|
|
31
|
+
'class-validator-type-match/definite-assignment-match': string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
basic: {
|
|
35
|
+
plugins: string[];
|
|
36
|
+
rules: {
|
|
37
|
+
'class-validator-type-match/decorator-type-match': string;
|
|
38
|
+
'class-validator-type-match/optional-decorator-match': string;
|
|
39
|
+
'class-validator-type-match/definite-assignment-match': string;
|
|
16
40
|
};
|
|
17
41
|
};
|
|
18
42
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const decorator_type_match_1 = __importDefault(require("./rules/decorator-type-match"));
|
|
6
6
|
const optional_decorator_match_1 = __importDefault(require("./rules/optional-decorator-match"));
|
|
7
|
+
const validate_nested_match_1 = __importDefault(require("./rules/validate-nested-match"));
|
|
8
|
+
const type_decorator_match_1 = __importDefault(require("./rules/type-decorator-match"));
|
|
9
|
+
const definite_assignment_match_1 = __importDefault(require("./rules/definite-assignment-match"));
|
|
7
10
|
module.exports = {
|
|
8
11
|
rules: {
|
|
9
12
|
'decorator-type-match': decorator_type_match_1.default,
|
|
10
13
|
'optional-decorator-match': optional_decorator_match_1.default,
|
|
14
|
+
'validate-nested-match': validate_nested_match_1.default,
|
|
15
|
+
'type-decorator-match': type_decorator_match_1.default,
|
|
16
|
+
'definite-assignment-match': definite_assignment_match_1.default,
|
|
11
17
|
},
|
|
12
18
|
configs: {
|
|
13
19
|
recommended: {
|
|
@@ -15,6 +21,27 @@ module.exports = {
|
|
|
15
21
|
rules: {
|
|
16
22
|
'class-validator-type-match/decorator-type-match': 'error',
|
|
17
23
|
'class-validator-type-match/optional-decorator-match': 'error',
|
|
24
|
+
'class-validator-type-match/validate-nested-match': 'error',
|
|
25
|
+
'class-validator-type-match/type-decorator-match': 'error',
|
|
26
|
+
'class-validator-type-match/definite-assignment-match': 'error',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
strict: {
|
|
30
|
+
plugins: ['class-validator-type-match'],
|
|
31
|
+
rules: {
|
|
32
|
+
'class-validator-type-match/decorator-type-match': 'error',
|
|
33
|
+
'class-validator-type-match/optional-decorator-match': 'error',
|
|
34
|
+
'class-validator-type-match/validate-nested-match': 'error',
|
|
35
|
+
'class-validator-type-match/type-decorator-match': 'error',
|
|
36
|
+
'class-validator-type-match/definite-assignment-match': 'error',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
basic: {
|
|
40
|
+
plugins: ['class-validator-type-match'],
|
|
41
|
+
rules: {
|
|
42
|
+
'class-validator-type-match/decorator-type-match': 'error',
|
|
43
|
+
'class-validator-type-match/optional-decorator-match': 'error',
|
|
44
|
+
'class-validator-type-match/definite-assignment-match': 'error',
|
|
18
45
|
},
|
|
19
46
|
},
|
|
20
47
|
},
|
|
@@ -1,38 +1,50 @@
|
|
|
1
1
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
type MessageIds = 'mismatch' | '
|
|
2
|
+
type MessageIds = 'mismatch' | 'enumMismatch' | 'invalidEachOption';
|
|
3
3
|
/**
|
|
4
4
|
* ESLint rule to ensure class-validator decorators match TypeScript type annotations.
|
|
5
5
|
*
|
|
6
6
|
* This rule prevents common mistakes where the decorator type (e.g., @IsString)
|
|
7
7
|
* doesn't match the actual TypeScript type annotation (e.g., number).
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
14
|
-
* - Type literals
|
|
15
|
-
* - class-transformer decorators
|
|
16
|
-
* - Enum types (both TypeScript enums and union types)
|
|
17
|
-
* - Literal types (e.g., "admin", 25)
|
|
18
|
-
* - Intersection types (e.g., Profile & Settings)
|
|
19
|
-
* - Branded types (string & { __brand: 'UserId' })
|
|
20
|
-
* - @Type(() => ClassName) decorator matching
|
|
21
|
-
* - Readonly arrays (readonly T[])
|
|
22
|
-
* - Tuple types ([T, U])
|
|
9
|
+
* Handles:
|
|
10
|
+
* - Basic type validation (string, number, boolean, array, Date, object, enum)
|
|
11
|
+
* - @IsEnum validation with enum references and union literals
|
|
12
|
+
* - { each: true } option for array element validation
|
|
13
|
+
* - Invalid { each: true } usage on non-array types
|
|
23
14
|
* - Nullable unions (T | null | undefined)
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
15
|
+
* - Utility types (Partial, Pick, Omit, etc.)
|
|
16
|
+
* - Template literal types, namespace references, branded types
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // ✅ Good - decorator matches type
|
|
20
|
+
* class User {
|
|
21
|
+
* @IsString()
|
|
22
|
+
* name!: string;
|
|
23
|
+
*
|
|
24
|
+
* @IsNumber()
|
|
25
|
+
* age!: number;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // ❌ Bad - decorator doesn't match type
|
|
30
|
+
* class User {
|
|
31
|
+
* @IsString()
|
|
32
|
+
* age!: number; // Error: @IsString does not match type number
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // ✅ Good - { each: true } for array elements
|
|
37
|
+
* class User {
|
|
38
|
+
* @IsString({ each: true })
|
|
39
|
+
* tags!: string[];
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // ❌ Bad - { each: true } on non-array
|
|
44
|
+
* class User {
|
|
45
|
+
* @IsString({ each: true })
|
|
46
|
+
* name!: string; // Error: { each: true } on non-array type
|
|
47
|
+
* }
|
|
36
48
|
*/
|
|
37
49
|
declare const _default: ESLintUtils.RuleModule<MessageIds, [], unknown, ESLintUtils.RuleListener>;
|
|
38
50
|
export default _default;
|