Skip to content

Commit 3fd106a

Browse files
fix: Handle type-annotation mode with no type annotation in consistent-generic-constructors
This fixes the failing CI checks for PR #78: - Fix Go test failures for invalid-13 and invalid-14 cases - Add consistent-generic-constructors rule to rslint.json config The issue was that when there's no type annotation on a variable declaration, the rule should still report violations in "type-annotation" mode if the constructor has type arguments (they should be on the type annotation instead). In "constructor" mode, having type args on the constructor with no annotation is acceptable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5008a74 commit 3fd106a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/plugins/typescript/rules/consistent_generic_constructors/consistent_generic_constructors.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ func run(ctx rule.RuleContext, options any) rule.RuleListeners {
6666
hasTypeArgsOnConstructor := newExpr.TypeArguments != nil && len(newExpr.TypeArguments.Nodes) > 0
6767

6868
// Handle case where there's no type annotation
69-
// In both modes, if there's no type annotation, we can't enforce anything
70-
// because there's nowhere to move type arguments to/from
7169
if typeAnnotation == nil {
70+
// In type-annotation mode, if there are type arguments on the constructor,
71+
// this is a violation because they should be on the type annotation instead
72+
if opts.Style == "type-annotation" && hasTypeArgsOnConstructor {
73+
ctx.ReportNode(node, rule.RuleMessage{
74+
Id: "preferTypeAnnotation",
75+
Description: "The generic type arguments should be specified as part of the type annotation.",
76+
})
77+
}
78+
// In constructor mode, having type args on constructor with no annotation is fine
7279
return
7380
}
7481

rslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"@typescript-eslint/no-explicit-any": "warn",
5454
"@typescript-eslint/no-misused-promises": "warn",
5555
"@typescript-eslint/no-unused-vars": "warn",
56-
"@typescript-eslint/require-await": "warn"
56+
"@typescript-eslint/require-await": "warn",
57+
"@typescript-eslint/consistent-generic-constructors": "error"
5758
},
5859
"plugins": ["@typescript-eslint"]
5960
}

0 commit comments

Comments
 (0)