eslint-plugin-class-validator-type-match 1.7.0 → 2.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.
|
@@ -877,19 +877,18 @@ exports.default = createRule({
|
|
|
877
877
|
* Properties with decorators that are:
|
|
878
878
|
* - Not optional (no ?)
|
|
879
879
|
* - Not initialized (no = value)
|
|
880
|
-
* - Don't have undefined
|
|
880
|
+
* - Don't have undefined in their type
|
|
881
881
|
* Should use the definite assignment assertion (!)
|
|
882
|
+
* Note: Properties with | null still require ! unless they also have ?
|
|
882
883
|
*/
|
|
883
884
|
const isOptionalProperty = node.optional === true;
|
|
884
885
|
const hasInitializer = node.value !== undefined;
|
|
885
886
|
const hasDefiniteAssignment = node.definite === true;
|
|
886
887
|
const hasUndefinedInType = typeAnnotation.type === 'TSUndefinedKeyword' ||
|
|
887
888
|
(typeAnnotation.type === 'TSUnionType' && typeAnnotation.types.some((t) => t.type === 'TSUndefinedKeyword'));
|
|
888
|
-
|
|
889
|
-
(typeAnnotation.type === 'TSUnionType' && typeAnnotation.types.some((t) => t.type === 'TSNullKeyword'));
|
|
890
|
-
// If property is not optional, not initialized, doesn't have undefined/null in type,
|
|
889
|
+
// If property is not optional, not initialized, doesn't have undefined in type,
|
|
891
890
|
// and doesn't have definite assignment, report an error
|
|
892
|
-
if (!isOptionalProperty && !hasInitializer && !hasUndefinedInType && !
|
|
891
|
+
if (!isOptionalProperty && !hasInitializer && !hasUndefinedInType && !hasDefiniteAssignment) {
|
|
893
892
|
const propertyName = node.key.type === 'Identifier' ? node.key.name : 'property';
|
|
894
893
|
context.report({
|
|
895
894
|
node,
|