- Notifications
You must be signed in to change notification settings - Fork2.3k
fix: skip redundant_optional_initialization for @Parameter variables …#6296
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 ourterms of service andprivacy 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?
Conversation
…ealm#5884)This change updates ImplicitOptionalInitializationRule so that variables annotated with@parameter (from TipKit) are ignored when checking for redundant nil initializers. TipKit's@parameter macro requires explicitly initializing optional parameters to nil; otherwise the macro fails to expand. Without this change, the implicit_optional_initialization rule incorrectly flags these initializers, forcing developers to disable the rule.Resolvesrealm#5884.
SimplyDanny left 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.
Thank you for the contribution. Before this can be merged, it would need tests and a changelog entry.
Generally, I think that the attributes for which the rule shall be ignored, should be configurable instead of being hard-coded.
| @@ -1,4 +1,4 @@ | |||
| import SwiftSyntax | |||
| eimport SwiftSyntax | |||
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.
Unintentional?
| violations.append(ReasonedRuleViolation(position: violationPosition, reason: reason)) | ||
| // // violations.append(ReasonedRuleViolation(position: violationPosition, reason: reason)) | ||
| overridefunc visitPost(_ node:PatternBindingSyntax){ | ||
| iflet variableDecl= node.parent?.as(VariableDeclSyntax.self), |
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.
This looks a bit off.
SwiftLintBot commentedOct 27, 2025
Here's an example of your CHANGELOG entry: * fix: skip redundant_optional_initialization for@Parameter variables ….[chetan-kmr-0607](https://github.com/chetan-kmr-0607)[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number) note: There are two invisible spaces after the entry's text. Generated by 🚫Danger |
…(#5884)
This change updates ImplicitOptionalInitializationRule so that variables annotated with@parameter (from TipKit) are ignored when checking for redundant nil initializers. TipKit's@parameter macro requires explicitly initializing optional parameters to nil; otherwise the macro fails to expand. Without this change, the implicit_optional_initialization rule incorrectly flags these initializers, forcing developers to disable the rule.
Resolves#5884.