SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Rule Request: Implicit initialization of optional bindings

Open sindresorhus opened this issue 8 years ago • 1 comments

New Issue Checklist

Rule Request

  1. 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
}
  1. 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.

  1. 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?
}
  1. 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.

sindresorhus avatar Nov 09 '17 05:11 sindresorhus

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.

jpsim avatar Nov 09 '17 23:11 jpsim