Fix rewriter of `trailing_semicolon` rule wrongly removing trailing comments (#4818)

This commit is contained in:
Martin Redington 2023-03-13 22:23:35 +00:00 committed by GitHub
parent fb89ab2fb5
commit 6983c813c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -182,6 +182,11 @@
[Martin Redington](https://github.com/mildm8nnered)
[#4788](https://github.com/realm/SwiftLint/issues/4788)
* Fixed correction for `trailing_comma` rule wrongly removing trailing
comments.
[Martin Redington](https://github.com/mildm8nnered)
[#4814](https://github.com/realm/SwiftLint/issues/4814)
## 0.50.3: Bundle of Towels
#### Breaking

View File

@ -21,7 +21,8 @@ struct TrailingSemicolonRule: SwiftSyntaxCorrectableRule, ConfigurationProviderR
],
corrections: [
Example("let a = 0↓;\n"): Example("let a = 0\n"),
Example("let a = 0↓;\nlet b = 1\n"): Example("let a = 0\nlet b = 1\n")
Example("let a = 0↓;\nlet b = 1\n"): Example("let a = 0\nlet b = 1\n"),
Example("let foo = 12↓; // comment\n"): Example("let foo = 12 // comment\n")
]
)
@ -65,8 +66,7 @@ private extension TrailingSemicolonRule {
}
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
// Is there a better way to remove a node? Should we somehow keep trailing trivia?
return super.visit(TokenSyntax(.semicolon, presence: .missing))
return .unknown("").with(\.trailingTrivia, node.trailingTrivia ?? .zero)
}
}
}