You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seeking some clarify here: What does "supporting all linters" mean? I was looking through the yaml file and these seem to be in there, and enable-all being set to true, just a little unclear on what the goal is here. A little new to the Golang ecosystem, appreciate any support, thanks!
using all linters will create a house of pain because they conflict with one another.
I know this because I've tried to do it before. The key linter in golangci-lint is revive which replaced golint. It has tons of features and is quite configurable.
will make our type assertions of the comma, ok variety:
types/event_bus_test.go:195:5: type assertion must be checked (forcetypeassert)
data := msg.Data().(EventDataTx)
^
types/event_bus_test.go:246:3: type assertion must be checked (forcetypeassert)
edt := msg.Data().(EventDataNewBlockHeader)
^
types/event_bus_test.go:281:3: type assertion must be checked (forcetypeassert)
edt := msg.Data().(EventDataNewBlockEvents)
^
types/event_bus_test.go:325:3: type assertion must be checked (forcetypeassert)
edt := msg.Data().(EventDataNewEvidence)
I think that there are a few other deprecated linters that I haven't marked as deprecated yet.
There are numerous linters that have been folded into revive over the years. If we would like to enable all of the linters, beginning with revive is pretty critical because so much has joined it in the past few years.
Basically, I don't actually think that it's a good idea to enable all of the linters. Instead, we should enable as many as it is sensible and practical to do.
by setting higher values for these, we've avoided too much refactoring, these values can be brought down over time.
enabled the nestif linter
going to reopen as a new PR, because if it is successfully broken out into other PRs, then the original PR will pass CI.
the point of this comment
Most of the linters are implemented, if and only if #2232 is merged. It covers the majority of the ones listed above, and doesn't cover the ones we don't want, and is kinda the ur-linter of golang. Many of the other PR's I've made depend on #2232 and that's because it is the uber-linter / ur-linter.
cool thing
If we do end up doing this here, I'll add what we've done here to the "linter of record", the one in ibc-go:
internal/state/indexer/sink/psql/psql_test.go:291:10: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"dropping tables: %v\", err)" (goerr113)
return fmt.Errorf("dropping tables: %v", err)
^
internal/state/indexer/sink/psql/psql_test.go:295:10: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"dropping views: %v\", err)" (goerr113)
return fmt.Errorf("dropping views: %v", err)
^
internal/state/indexer/sink/psql/psql_test.go:322:15: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"lookup transaction for hash %q failed: %v\", hashString, err)" (goerr113)
return nil, fmt.Errorf("lookup transaction for hash %q failed: %v", hashString, err)
^
internal/state/indexer/sink/psql/psql_test.go:327:15: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"unmarshaling txr: %v\", err)" (goerr113)
return nil, fmt.Errorf("unmarshaling txr: %v", err)
^
internal/state/indexer/sink/psql/psql_test.go:346:19: err113: do not compare errors directly "err == sql.ErrNoRows", use "errors.Is(err, sql.ErrNoRows)" instead (goerr113)
`, height).Err(); err == sql.ErrNoRows {
^
internal/state/indexer/sink/psql/psql_test.go:356:52: err113: do not compare errors directly "err == sql.ErrNoRows", use "errors.Is(err, sql.ErrNoRows)" instead (goerr113)
`, height, eventTypeFinalizeBlock, chainID).Err(); err == sql.ErrNoRows {
^
rpc/grpc/server/services/blockservice/service.go:144:14: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"unexpected event type: %v\", eventType)" (goerr113)
return -1, fmt.Errorf("unexpected event type: %v", eventType)
^
abci/example/kvstore/kvstore.go:214:11: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"wanted to punish val %q but can't find it\", addr)" (goerr113)
panic(fmt.Errorf("wanted to punish val %q but can't find it", addr))
^
abci/example/kvstore/kvstore.go:424:22: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"expected 'pubkeytype!pubkey!power'. Got %v\", typePubKeyAndPower)" (goerr113)
return "", nil, 0, fmt.Errorf("expected 'pubkeytype!pubkey!power'. Got %v", typePubKeyAndPower)
^
abci/example/kvstore/kvstore.go:431:22: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"pubkey (%s) is invalid base64\", pubkeyS)" (goerr113)
return "", nil, 0, fmt.Errorf("pubkey (%s) is invalid base64", pubkeyS)
^
abci/example/kvstore/kvstore.go:437:22: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"power (%s) is not an int\", powerS)" (goerr113)
return "", nil, 0, fmt.Errorf("power (%s) is not an int", powerS)
^
abci/example/kvstore/kvstore.go:441:22: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"power can not be less than 0, got %d\", power)" (goerr113)
return "", nil, 0, fmt.Errorf("power can not be less than 0, got %d", power)
^
internal/state/txindex/kv/kv.go:105:33: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"error setting last retain height '%v' while handling result deletion error '%v' for tx indexer\", errSetLastRetainHeight, errDeleteResult)" (goerr113)
return 0, lastRetainHeight, fmt.Errorf("error setting last retain height '%v' while handling result deletion error '%v' for tx indexer", errSetLastRetainHeight, errDeleteResult)
^
internal/state/txindex/kv/kv.go:109:33: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"error writing tx indexer batch '%v' while handling result deletion error '%v'\", errWriteBatch, errDeleteResult)" (goerr113)
return 0, lastRetainHeight, fmt.Errorf("error writing tx indexer batch '%v' while handling result deletion error '%v'", errWriteBatch, errDeleteResult)
^
internal/state/txindex/kv/kv.go:205:15: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"error reading TxResult: %v\", err)" (goerr113)
return nil, fmt.Errorf("error reading TxResult: %v", err)
^
internal/state/txindex/kv/kv.go:367:12: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"event type and attribute key \\\"%s\\\" is reserved; please use a different key\", compositeTag)" (goerr113)
return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeTag)
^
internal/state/txindex/kv/utils.go:48:13: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"unexpected remainder in key: %s\", remaining)" (goerr113)
return 0, fmt.Errorf("unexpected remainder in key: %s", remaining)
^
proxy/multi_app_conn_test.go:70:32: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"EOF\")" (goerr113)
clientMock.On("Error").Return(errors.New("EOF")).Once()
^
cmd/cometbft/commands/debug/dump.go:48:10: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"invalid output directory\")" (goerr113)
return errors.New("invalid output directory")
^
cmd/cometbft/commands/debug/dump.go:52:10: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"frequency must be positive\")" (goerr113)
return errors.New("frequency must be positive")
^
cmd/cometbft/commands/debug/kill.go:43:10: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"invalid output file\")" (goerr113)
return errors.New("invalid output file")
^
internal/store/store.go:312:17: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"height must be greater than 0\")" (goerr113)
return 0, -1, errors.New("height must be greater than 0")
^
internal/store/store.go:317:17: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"cannot prune beyond the latest height %v\", bs.height)" (goerr113)
return 0, -1, fmt.Errorf("cannot prune beyond the latest height %v", bs.height)
^
internal/store/store.go:322:17: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"cannot prune to height %v, it is lower than base height %v\",\n\theight, base)" (goerr113)
return 0, -1, fmt.Errorf("cannot prune to height %v, it is lower than base height %v",
^
internal/store/store.go:484:10: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"BlockStore can only save contiguous blocks. Wanted %v, got %v\", w, g)" (goerr113)
return fmt.Errorf("BlockStore can only save contiguous blocks. Wanted %v, got %v", w, g)
^
internal/store/store.go:487:10: err113: do not define dynamic errors, use wrapped static errors instead: "errors.New(\"BlockStore can only save complete block part sets\")" (goerr113)
return errors.New("BlockStore can only save complete block part sets")
^
internal/store/store.go:490:10: err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"BlockStore cannot save seen commit of a different height (block: %d, commit: %d)\", height, seenCommit.Height)" (goerr113)
return fmt.Errorf("BlockStore cannot save seen commit of a different height (block: %d, commit: %d)", height, seenCommit.Height)
^
I don't really think we want that, many hundreds of times?
to try out a new linter, remove it from the disabled list. Some of the ones that are disabled are disabled for a good reason, like being deprecated, but there are others that aren't. If you come across one that you think produces productive changes when you golangci-lint run ./... --fix you can make a PR enabling it.
Note: Most of the linters in the list have been enabled via revive so I recommend starting any work from:
...otherwise you'll likely be recreating the wheel.
The only time that you would not want to start from that PR would be when the linter produces a small changeset, in that case, feel free to write your PR against main directly.
Please also note that some of these linters actually kick off large refactors, the best example of this so far is the cyclomatic complexity / cognitive complexity linters that you can see here:
Activity
AbhinavMir commentedon Feb 9, 2024
Seeking some clarify here: What does "supporting all linters" mean? I was looking through the yaml file and these seem to be in there, and enable-all being set to true, just a little unclear on what the goal is here. A little new to the Golang ecosystem, appreciate any support, thanks!
faddat commentedon Feb 10, 2024
using all linters will create a house of pain because they conflict with one another.
I know this because I've tried to do it before. The key linter in golangci-lint is
revivewhich replacedgolint. It has tons of features and is quite configurable.Here's a list of linters we don't want, and why:
Here are some linters we do want
linters we might want
I think that there are a few other deprecated linters that I haven't marked as deprecated yet.
A lot of this is solved in #2232
There are numerous linters that have been folded into revive over the years. If we would like to enable all of the linters, beginning with revive is pretty critical because so much has joined it in the past few years.
Basically, I don't actually think that it's a good idea to enable all of the linters. Instead, we should enable as many as it is sensible and practical to do.
completed
revive, this has covered many of the other linters mentioned in this issue.mainbut was put on hold for pbts, so I linted pbtsthe point of this comment
Most of the linters are implemented, if and only if #2232 is merged. It covers the majority of the ones listed above, and doesn't cover the ones we don't want, and is kinda the ur-linter of golang. Many of the other PR's I've made depend on #2232 and that's because it is the uber-linter / ur-linter.
cool thing
If we do end up doing this here, I'll add what we've done here to the "linter of record", the one in ibc-go:
https://github.com/cosmos/ibc-go/blob/main/.golangci.yml
One of the goals with all the linting I've been doing for so long is to create a reproducible standard that can be used across Cosmos with confidence.
faddat commentedon Feb 10, 2024
Here's perfsprint:
faddat commentedon Feb 10, 2024
Here's what goerr113 would do:
I don't really think we want that, many hundreds of times?
faddat commentedon Feb 10, 2024
@AbhinavMir - hey, so, basically, right now we have all of the linters enabled in .golangci.yml. The ones that are not enabled are listed like this:
to try out a new linter, remove it from the disabled list. Some of the ones that are disabled are disabled for a good reason, like being deprecated, but there are others that aren't. If you come across one that you think produces productive changes when you
golangci-lint run ./... --fixyou can make a PR enabling it.Note: Most of the linters in the list have been enabled via
reviveso I recommend starting any work from:...otherwise you'll likely be recreating the wheel.
The only time that you would not want to start from that PR would be when the linter produces a small changeset, in that case, feel free to write your PR against main directly.
Please also note that some of these linters actually kick off large refactors, the best example of this so far is the cyclomatic complexity / cognitive complexity linters that you can see here:
.... but I bet there are others, for example, the testifylint linter, which could be coming towards root cause on some of the flaky tests:
and here's an example of a linter being enabled that produces no changes:
If you find one of those, I do recommend enabling it and submitting a PR, just to enhance future rigor.
[-]golangci-lint: enable all the linters[/-][+]golangci-lint: enable more linters[/+]faddat commentedon Mar 1, 2024
feat: enable revive linter (#2232)
feat: enable revive linter (#2232)
feat: enable revive linter (#2232)