The linter complains because the second err occurs in a different scope.
"if err = f(); err != nil" scopes this err instance to the if block. It
re-uses the err from the outer scope, which might not be intended.
If you only use either of "err = f(); if err..." or "if err = f(); err..."
I would stop using that particular linter.
And keep calling your error value err.
It is idiomatic.
On Monday, 14 August 2023 at 22:36:11 UTC+1 David Finkel wrote:
> On Mon, Aug 14, 2023 at 4:54 PM Pablo Caballero wrote:
>
>> I started working on a Golang project (from my work). The following
On Mon, Aug 14, 2023 at 4:54 PM Pablo Caballero wrote:
> I started working on a Golang project (from my work). The following
> pattern makes the company configured linter to complain with:
> sloppyReassign: re-assignment to `err` can be replaced with `err :=
> myFunc2()` (gocritic)
>
> func
I started working on a Golang project (from my work). The following pattern
makes the company configured linter to complain with:
sloppyReassign: re-assignment to `err` can be replaced with `err :=
myFunc2()` (gocritic)
func myFunc() error {
...
blah, err := getBlah()
if err != nil {
return