Swiftlint: Rule Request: Implicit initialization of optional bindings

Created on 9 Nov 2017  路  1Comment  路  Source: realm/SwiftLint

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.

rule-request

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings