tinkerbell / lint-install

Consistently install reasonable linter rules for open-source projects
Apache License 2.0
6 stars 7 forks source link

golangci-line exit code lost #46

Open jacobweinstock opened 2 years ago

jacobweinstock commented 2 years ago

This repo uses the find command to execute golangci-lint in the top level directory. As a side affect of this I believe this swallows the exit code from the actual golangci-lint command. This makes it impossible to use lint-install in CI where a non-zero exit code should fail a build.

❯ make lint
find . -name go.mod -execdir "out/linters/golangci-lint-v1.46.2-x86_64" run -c "" \;
otel/otel.go:229:1: exported: exported method Encoder.EncodeFILE should have comment or be unexported (revive)
func (e *Encoder) EncodeFILE(d *dhcpv4.DHCPv4, namespace string) error {
^
❯ echo $?
0

Same golanglint-ci command run on its own:

❯ out/linters/golangci-lint-v1.46.2-x86_64 run -c "" 
otel/otel.go:229:1: exported: exported method Encoder.EncodeFILE should have comment or be unexported (revive)
func (e *Encoder) EncodeFILE(d *dhcpv4.DHCPv4, namespace string) error {
^
❯ echo $?
1

Expected Behaviour

Current Behaviour

Possible Solution

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Your Environment

mmlb commented 2 years ago

I'm able to reproduce this. Reading the find docs on my linux box it states that using the + form does not swallow the exit code. Can you modify lint-install.go and give that a try?

jacobweinstock commented 2 years ago

hmmm....i must be reading something different. https://man7.org/linux/man-pages/man1/find.1.html:

"-execdir command {} + always returns true, while -execdir command {} ; returns true only if command returns 0."

Also, I can't get the command to work when i use {} and/or +.

jacobweinstock commented 2 years ago

Also, it seems the way the find command is used is just to execute the golangci-lint in a specific directory and not to actually find files. So using {} wouldn't make sense.

mmlb commented 2 years ago

Hmm I was going off of a couple sentences before that line:

If any invocation with the `+' form returns a non-zero value as exit status, then find returns a non-zero exit status.

And verified using the following experiment:

14:28  ~/go/src/github.com/tinkerbell/lint-install $ find . -name go.mod -execdir sh -c 'exit 1' '{}' '+'

14:28  ~/go/src/github.com/tinkerbell/lint-install $ echo $?
1
mmlb commented 2 years ago

find is used to find the go.mod files (there may be many in a repo, in subdirs for e.g.) and then runs golangci-lint run from within that dir https://github.com/mistifyio/go-zfs/ is an example repo.