SwiftLint
SwiftLint copied to clipboard
Rule Request: Implicit initialization of optional bindings
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Rule Request
- Why should this rule be added? Share links to existing discussion about what the community thinks about this.
Swift supports both default implicit initialization of optional bindings and explicit.
These are equivalent:
struct A {
var x: Int?
}
struct A {
var x: Int? = nil
}
- Should the rule be configurable, if so what parameters should be configurable?
I think you should be able to enforce it either way, so either "always" or "never" implicit init of optional bindings.
- Provide several examples of what would and wouldn't trigger violations.
For "always", this would trigger a violation:
struct A {
var x: Int? = nil
}
For "never", this would trigger a violation:
struct A {
var x: Int?
}
- Should the rule be opt-in or enabled by default? Why? See README.md for guidelines on when to mark a rule as opt-in.
Opt-in as it's opinionated.
Note that the "never" case already exists as the Redundant Optional Initialization Rule.
I'm ok if we want to rename this rule and make it configurable to both cases.