Skip to content

Commit

Permalink
Preprocess syntax tree before running corrections (#5428)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Jan 18, 2024
1 parent 6bb9944 commit fc2a18e
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public extension SwiftSyntaxCorrectableRule {
}

func correct(file: SwiftLintFile) -> [Correction] {
guard let syntaxTree = preprocess(file: file) else {
return []
}
if let rewriter = makeRewriter(file: file) {
let syntaxTree = file.syntaxTree
let newTree = rewriter.visit(syntaxTree)
let positions = rewriter.correctionPositions
if positions.isEmpty {
Expand All @@ -40,7 +42,7 @@ public extension SwiftSyntaxCorrectableRule {
}

// There is no rewriter. Falling back to the correction ranges collected by the visitor (if any).
let violationCorrections = makeVisitor(file: file).walk(file: file, handler: \.violationCorrections)
let violationCorrections = makeVisitor(file: file).walk(tree: syntaxTree, handler: \.violationCorrections)
if violationCorrections.isEmpty {
return []
}
Expand Down

0 comments on commit fc2a18e

Please sign in to comment.