selinux icon indicating copy to clipboard operation
selinux copied to clipboard

golangci-lint: enable more linters and address linting issues

Open thaJeztah opened this issue 3 years ago • 4 comments

  • follow-up to https://github.com/opencontainers/selinux/pull/189

(more coming after this, but I have ETOOMANYBRANCHES already)

thaJeztah avatar Oct 12 '22 17:10 thaJeztah

I am ok with almost all of these, although I am not crazy about the err:= shadow issue. I find it a lot easier to read

if err := foobar(); err != nil }

Then err := foobar() if err != nil { }

Bottom line, I think err should be handled differently then other shadowed vars. But I am willing to live with the changes.

LGTM

rhatdan avatar Oct 12 '22 17:10 rhatdan

I am not crazy about the err:= shadow issue.

Yes, I'm slightly on the fence on that one as well;

  • in most cases, it's mostly "noise"
  • ^^ that said, I'm not against doing a "once in a while" round on changing them
  • ^^^ but ... that said; I've also encountered situations where an err was masking an err that was checked in a defer(). Admitted, those situations are rare (and usually better to have a distinct name for "special" errors).

I don't think the linter itself has a config for this, but perhaps a string match exclusion would work (see https://golangci-lint.run/usage/false-positives/#exclude-issue-by-text)

thaJeztah avatar Oct 13 '22 11:10 thaJeztah

Tests are failing for go-fumpt?

rhatdan avatar Oct 13 '22 19:10 rhatdan

Tests are failing for go-fumpt?

I probably need to rebase see https://github.com/opencontainers/selinux/pull/189#issuecomment-1277485676

thaJeztah avatar Oct 13 '22 20:10 thaJeztah

Rebased, and tweaked the settings to ignore "err" for shadowing 👍 PTAL

thaJeztah avatar Oct 16 '22 20:10 thaJeztah

Oh! Had one more change staged in another branch; just pushed that one as well.

thaJeztah avatar Oct 16 '22 20:10 thaJeztah

Nice work @thaJeztah

rhatdan avatar Oct 17 '22 10:10 rhatdan