Skip to content

Rule suggestion: guard let instead of huge if let #596

@dbmrq

Description

@dbmrq

Instead of something like:

if let aVariable = something, 
    anotherVariable = somethingElse {
        // A
        // huge
        // indented
        // body
        // of
        // code
}

I think it's generally better to do something like:

guard let aVariable = something, 
    anotherVariable = somethingElse else { return }

// A
// huge
// unindented
// body
// of
// code

There could be a limit to the number of lines inside the if let to trigger the rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions