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
Description
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
Labels
No labels