-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Migrate StatementPositionRule from SourceKit to SwiftSyntax #6116
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 StatementPositionRule from SourceKit to SwiftSyntax #6116
Conversation
11a125c
to
a021d60
Compare
Generated by 🚫 Danger |
50caf3d
to
0d58b9f
Compare
uncuddledCorrect(file: file) | ||
private static func calculateIndentation(_ trivia: Trivia) -> Int { | ||
var indentation = 0 | ||
for piece in trivia.reversed() { |
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.
Why reversed?
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.
To calculate the indentation of the last line in the trivia, not the first. I'll add a comment.
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.
Without the reversed()
, all tests still pass. So we should probably have a test case that makes sure reversed order is required.
Source/SwiftLintBuiltInRules/Rules/Style/StatementPositionRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Style/StatementPositionRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Style/StatementPositionRuleExamples.swift
Show resolved
Hide resolved
Wondering about the fixed violations in the Swift repository. The code doesn't look like it shouldn't trigger the rule anymore as both |
Not sure if you're saying this is a good thing or a bad thing. |
Convert StatementPositionRule to use SwiftSyntax instead of SourceKit for improved performance and more accurate positioning validation. The SwiftSyntax implementation: - Uses ViolationsSyntaxVisitor and ViolationsSyntaxRewriter patterns - Validates else/catch keyword positioning with proper indentation checks - Supports both default (same line) and uncuddled (next line) modes - Correctly handles trailing/leading trivia for whitespace validation - Implements corrections using explicit rewriter for both statement types - Extracts common validation logic to reduce code duplication - Skip correcting when there are comments
63417be
to
8524128
Compare
Oh sorry, I think that these examples should still trigger a violation and not appear as "fixed" with the rewrite. |
Well really it's that these two violations merged and moved to a different location: Before
After
|
But in my understanding, all three lines should still trigger, because the keyword is always after the closing brace. |
Instead of at the preceding closing brace.
This was really a matter of violation location, but I think it makes more sense to report violations on the |
Convert StatementPositionRule to use SwiftSyntax instead of SourceKit for
improved performance and more accurate positioning validation.
The SwiftSyntax implementation: