Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.
This repository was archived by the owner on May 9, 2021. It is now read-only.

Consider relaxing redundant assignment if it is part of a sequence #363

Closed
@ijc

Description

@ijc

After #319 (motivated by #312) a function of the form:

if err := doSomething(); err != nil {
    return err
}

if err := doSomethingElse(); err != nil {
    return err
}

if err := doAThirdThing(); err != nil {
    return err
}

return nil

Now complains about the doAThirdThing block and suggests transforming it into return doAThirdThing() making the function:

if err := doSomething(); err != nil {
    return err
}

if err := doSomethingElse(); err != nil {
    return err
}

return doAThirdThing()

Which I think is a regression in terms of code readability, it makes it non-uniform and implies that doAThirdThing is somehow different or special to what came earlier. It also means that adding more steps results in needing to transform this line (for similar reasons Go insists that the last line in a struct literal still has a trailing , so it doesn't need to be touched if the struct is extended).

Perhaps the heuristic could be tweaked to only emit the warning if the block is not proceeded by a similar block?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions