Skip to content

Rule Request: Implicit initialization of optional bindings #1940

@sindresorhus

Description

@sindresorhus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIdeas for improvements of existing features and rules.good first issueIssue to be taken up by new contributors yet unfamiliar with the project.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions