-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
RedundantTypeAnnotationRule: Rewrite with SwiftSyntax and allow ignoring certain attributes #5389
RedundantTypeAnnotationRule: Rewrite with SwiftSyntax and allow ignoring certain attributes #5389
Conversation
9c1904c
to
72e1850
Compare
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Show resolved
Hide resolved
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.
Thanks for taking up this rewrite! This is actually a bit more involved than adding the option for ignored attributes only. So I have a few comments ...
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
...ce/SwiftLintBuiltInRules/Rules/RuleConfigurations/RedundantTypeAnnotationConfiguration.swift
Outdated
Show resolved
Hide resolved
I'm really excited about this work! After this merges, perhaps we can also introduce another configuration element named |
@SimplyDanny Thanks for the review! After your comments I've rewrote the rule with a new approach that seems to be more flexible. Instead of visiting |
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
cd5eebf
to
ca246f5
Compare
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/RedundantTypeAnnotationRule.swift
Outdated
Show resolved
Hide resolved
Looking at the OSS findings, most of them look valid. However, there are cases where a sequence of Admittedly, these cases are debatable, but for the sake of a rewrite, the rule should behave as close to the previous version as it can. @tonell-m: Would you consider these cases in your PR? |
@SimplyDanny This case is now handled as well. Do you think we also need to handle cases where there is a mix of |
That depends on what the previous implementation did. I guess, it triggered, hence the rewritten rule should trigger too. |
…ributes - Add an `ignoreAttributes` configuration option that defaults to ["IBInspectable"] for retro compatibility - Check for each node's attributes to see if they are contained in the ignore list
…essions E.g. var a: Int = Int.random(0...1)
…edge cases manually
8771e14
to
fec3ea9
Compare
Rebased and addressed this point. |
Hi, first time contributing here so just let me know if something is wrong or missing in my PR 🙂
This PR resolves #5366 by adding a new
ignored_annotations
configuration to this rule that accepts a set of strings listing annotations that should disable this rule for properties that are marked with it. Currently this is already done arbitrarily for@IBInspectable
but now it is configurable. To solve the linked issue the configuration would be:This configuration still defaults to only
IBDesignable
for retrocompatibility.And, while I was at it and as @SimplyDanny suggested in the issue's comments, I took the opportunity to rewrite this rule using SwiftSyntax. Let me know what you think!