Skip to content

Commit fd7cfdf

Browse files
authored
perf: prefer-reduce-type-parameter: only generate fixes when requested (#335)
1 parent 1ab207c commit fd7cfdf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

internal/rules/prefer_reduce_type_parameter/prefer_reduce_type_parameter.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ var PreferReduceTypeParameterRule = rule.Rule{
5959
return
6060
}
6161

62-
fixes := make([]rule.RuleFix, 0, 2)
63-
if secondArg.Kind == ast.KindAsExpression {
64-
fixes = append(fixes, rule.RuleFixRemoveRange(assertionType.Loc.WithPos(assertionExpr.End())))
65-
} else {
66-
fixes = append(fixes, rule.RuleFixRemoveRange(secondArg.Loc.WithEnd(assertionExpr.Pos())))
67-
}
68-
if expr.TypeArguments == nil {
69-
fixes = append(fixes, rule.RuleFixInsertAfter(callee, "<"+ctx.SourceFile.Text()[assertionType.Pos():assertionType.End()]+">"))
70-
}
71-
ctx.ReportNodeWithFixes(secondArg, buildPreferTypeParameterMessage(), func() []rule.RuleFix { return fixes })
62+
ctx.ReportNodeWithFixes(secondArg, buildPreferTypeParameterMessage(), func() []rule.RuleFix {
63+
fixes := make([]rule.RuleFix, 0, 2)
64+
if secondArg.Kind == ast.KindAsExpression {
65+
fixes = append(fixes, rule.RuleFixRemoveRange(assertionType.Loc.WithPos(assertionExpr.End())))
66+
} else {
67+
fixes = append(fixes, rule.RuleFixRemoveRange(secondArg.Loc.WithEnd(assertionExpr.Pos())))
68+
}
69+
if expr.TypeArguments == nil {
70+
fixes = append(fixes, rule.RuleFixInsertAfter(callee, "<"+ctx.SourceFile.Text()[assertionType.Pos():assertionType.End()]+">"))
71+
}
72+
return fixes
73+
})
7274
},
7375
}
7476
},

0 commit comments

Comments
 (0)