-
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
RedundantTypeAnnotation: add 'ignore_type_interfaces' option #5839
base: main
Are you sure you want to change the base?
Conversation
The `redundant_type_annotation` and `explicit_type_interface` rules conflict. For users that want to have an explicit type interface, but still be able to write simple code inside the bodies of functions, I want to add an option to `redundant_type_annotation` that has it ignore "type interfaces". For example, this allows: ``` struct Foo { var bar: Bar = Bar() // OK: ignore this! I want explicit types on interfaces. func baz() { let bar: Bar = Bar() // WARN: redundant_type_annotation kicks in here though. } } ```
Generated by 🚫 Danger |
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.
The new option makes sense to me. Thanks for adding it!
@@ -8,6 +8,8 @@ struct RedundantTypeAnnotationConfiguration: SeverityBasedRuleConfiguration { | |||
var severityConfiguration = SeverityConfiguration<Parent>(.warning) | |||
@ConfigurationElement(key: "ignore_attributes") | |||
var ignoreAttributes = Set<String>(["IBInspectable"]) | |||
@ConfigurationElement(key: "ignore_type_interfaces") |
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.
Which other elements apart from properties does this include?
If it's only about properties, we could be more specific with the name by calling it ignore_properties
.
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.
Yes, I think it is limited only to that. I was trying to echo the other rule (explicit_type_interfaces
) by the name, but your suggestion is probably more accurate. I can change it!
if ignoreTypeInterfaces, | ||
let parentNode = varDecl.parent, | ||
parentNode.as(CodeBlockItemSyntax.self) == nil { | ||
return true | ||
} | ||
return false |
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.
if ignoreTypeInterfaces, | |
let parentNode = varDecl.parent, | |
parentNode.as(CodeBlockItemSyntax.self) == nil { | |
return true | |
} | |
return false | |
return ignoreTypeInterfaces && varDecl.parent?.is(MemberBlockItemSyntax.self) == true |
The
redundant_type_annotation
andexplicit_type_interface
rules conflict. For users that want to have an explicit type interface, but still be able to write simple code inside the bodies of functions, I want to add an option toredundant_type_annotation
that has it ignore "type interfaces".For example, this allows:
I suggest that this addresses the complaint made in Issue #3750.