Skip to content

Commit 6c8e5a3

Browse files
authored
perf: no-unnecessary-type-assertion: only do scanning when fixes are generated (#334)
1 parent bf425b6 commit 6c8e5a3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

internal/rules/no_unnecessary_type_assertion/no_unnecessary_type_assertion.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,18 @@ var NoUnnecessaryTypeAssertionRule = rule.Rule{
219219
msg := buildUnnecessaryAssertionMessage()
220220

221221
if node.Kind == ast.KindAsExpression {
222-
s := scanner.GetScannerForSourceFile(ctx.SourceFile, expression.End())
223-
asKeywordRange := s.TokenRange()
224-
225222
ctx.ReportNodeWithFixes(node, msg, func() []rule.RuleFix {
223+
s := scanner.GetScannerForSourceFile(ctx.SourceFile, expression.End())
224+
asKeywordRange := s.TokenRange()
226225
return []rule.RuleFix{rule.RuleFixRemoveRange(asKeywordRange), rule.RuleFixRemove(ctx.SourceFile, typeNode)}
227226
})
228227
} else {
229-
s := scanner.GetScannerForSourceFile(ctx.SourceFile, node.Pos())
230-
openingAngleBracket := s.TokenRange()
231-
s.ResetPos(typeNode.End())
232-
s.Scan()
233-
closingAngleBracket := s.TokenRange()
234-
235228
ctx.ReportNodeWithFixes(node, msg, func() []rule.RuleFix {
229+
s := scanner.GetScannerForSourceFile(ctx.SourceFile, node.Pos())
230+
openingAngleBracket := s.TokenRange()
231+
s.ResetPos(typeNode.End())
232+
s.Scan()
233+
closingAngleBracket := s.TokenRange()
236234
return []rule.RuleFix{rule.RuleFixRemoveRange(openingAngleBracket.WithEnd(closingAngleBracket.End()))}
237235
})
238236
}

0 commit comments

Comments
 (0)