-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Migrate VerticalWhitespaceClosingBracesRule to SwiftSyntax #6118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Migrate VerticalWhitespaceClosingBracesRule to SwiftSyntax #6118
Conversation
3821d9b
to
a45aa1f
Compare
Generated by 🚫 Danger |
a45aa1f
to
5353d40
Compare
## Summary Convert VerticalWhitespaceClosingBracesRule to use SwiftSyntax instead of SourceKit for improved performance and better detection of empty lines before closing braces. ## Key Technical Improvements - **Enhanced trivia analysis** for accurate empty line detection before closing braces - **Proper position calculation** using positionAfterSkippingLeadingTrivia for line numbers - **Improved trivial line detection** supporting any combination of closing braces (`}`, `]`, `)`) - **SwiftSyntax visitor pattern** replacing regex-based detection for better accuracy - **Unified correction logic** handling all newline types (LF, CR, CRLF) consistently ## Migration Details - Replaced `CorrectableRule, OptInRule` with `@SwiftSyntaxRule(correctable: true, optIn: true)` - Implemented `ViolationsSyntaxVisitor` for detecting violations in token leading trivia - Implemented `ViolationsSyntaxRewriter` for correcting violations by modifying trivia - Added proper handling of `only_enforce_before_trivial_lines` configuration option - Maintained exact position reporting for violation locations - Preserved all existing test cases and rule behavior
5353d40
to
7dae4c2
Compare
Rebased to get the better summary. |
withTemplate: "$2" | ||
} | ||
|
||
final class Rewriter: ViolationsSyntaxRewriter<VerticalWhitespaceClosingBracesConfiguration> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rewriter is currently not used at all since the visitor does the replacement already and the rule doesn't specify explicitRewriter: true
.
} | ||
|
||
private extension VerticalWhitespaceClosingBracesRule { | ||
final class Visitor: ViolationsSyntaxVisitor<VerticalWhitespaceClosingBracesConfiguration> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final class Visitor: ViolationsSyntaxVisitor<VerticalWhitespaceClosingBracesConfiguration> { | |
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> { |
|
||
let patternRegex: NSRegularExpression = regex(pattern) | ||
private func isTokenLineTrivialHelper( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the "helper" suffix stand for?
With this rewrite, we see new violations on empty lines preceded by a comment, that is:
That's reasonable. So all OSS findings are fine. |
Summary
Convert VerticalWhitespaceClosingBracesRule to use SwiftSyntax instead
of SourceKit for improved performance and better detection of empty
lines before closing braces.
Key Technical Improvements
before closing braces
positionAfterSkippingLeadingTrivia for line numbers
closing braces (
}
,]
,)
)better accuracy
CRLF) consistently
Migration Details
CorrectableRule, OptInRule
with@SwiftSyntaxRule(correctable: true, optIn: true)
ViolationsSyntaxVisitor
for detecting violations intoken leading trivia
ViolationsSyntaxRewriter
for correcting violations bymodifying trivia
only_enforce_before_trivial_lines
configuration option