-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Migrate MultilineParametersBracketsRule from SourceKit to SwiftSyntax #6131
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 MultilineParametersBracketsRule from SourceKit to SwiftSyntax #6131
Conversation
Generated by 🚫 Danger |
An analysis of the OSS Check results from Claude:
|
64dcbac
to
4d6e508
Compare
## Summary Convert MultilineParametersBracketsRule to use SwiftSyntax instead of SourceKit for improved performance and better detection of multiline parameter formatting violations. ## Key Technical Improvements - **Enhanced multiline detection** distinguishing between structurally multiline parameters and parameters with multiline default values - **Accurate position reporting** using SwiftSyntax's precise token locations - **Better handling of default values** by focusing on parameter structure rather than content - **Improved performance** using visitor pattern over regex-based SourceKit analysis - **Reduced false positives** for single parameters with multiline default values ## Migration Details - Replaced `ASTRule` with `@SwiftSyntaxRule(optIn: true)` annotation - Implemented `ViolationsSyntaxVisitor` pattern for function and initializer parameter analysis - Added helper methods to extract significant tokens (name/type) excluding default values - Converted regex-based bracket detection to SwiftSyntax position comparisons - Maintained full compatibility with existing rule behavior and test cases
4d6e508
to
3a1a472
Compare
That cannot be entirely true. The numbers of fixed and new violations is not equal. So there must be a few that are only fixed and a few that are only new and thus have not just their message changed. The ones I found look valid though. I'm trying to improve the categorization further in #6139. |
return ellipsis | ||
} | ||
// Type is not optional, so directly use it | ||
return parameter.type.lastToken(viewMode: .sourceAccurate) // Gets the very last token of the type |
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.
Due to the .type
an example like
func foo(a: T,
b: String
= "")
would only trigger on a
but not at the closing parenthesis where it actually should. Not sure if that's relevant, though, as it's a quite strange way of formatting parameters. However, for pretty long names and types and short lines, the default value could have to be placed on a new line like in the example. Probably depends on what the previous behavior was ...
oss-check-summary.md is the report with improved categorization and this PR cherry-picked on top. There are indeed a few fixed and new violations that differ in more than the message. |
Summary
Convert MultilineParametersBracketsRule to use SwiftSyntax instead of
SourceKit for improved performance and better detection of multiline
parameter formatting violations.
Key Technical Improvements
multiline parameters and parameters with multiline default values
locations
structure rather than content
SourceKit analysis
default values
Migration Details
ASTRule
with@SwiftSyntaxRule(optIn: true)
annotationViolationsSyntaxVisitor
pattern for function andinitializer parameter analysis
excluding default values
comparisons
cases