Skip to content

Conversation

chetan-kmr-0607
Copy link

…(#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.

…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.

Resolves realm#5884.
Copy link
Collaborator

@SimplyDanny SimplyDanny left a 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
Copy link
Collaborator

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))
override func visitPost(_ node: PatternBindingSyntax) {
if let variableDecl = node.parent?.as(VariableDeclSyntax.self),
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional TipKit parameters trigger a redundant_optional_initialization violation

2 participants