tetragon
tetragon copied to clipboard
cleanup: add new linters and fix bugs and alerts
This is a follow-up of https://github.com/cilium/tetragon/pull/976 to enable new linters to increase the code quality, remove bugs and improve readability in a sustainable way.
Add the following linters and fix their alerts:
- gosimple: Linter for Go source code that specializes in simplifying code
- typecheck: Like the front-end of a Go compiler, parses and type-checks Go code
- asciicheck: Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk: Checks for dangerous unicode character sequences
- makezero: Finds slice declarations with non-zero initial length (found bugs)
- loggercheck: Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). (found bugs)
- exportloopref: Checks for pointers to enclosing loop variables. (found bugs)
- dupword: Checks for duplicate words in the source code
- gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification.
- errname: Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
- gocritic: Provides diagnostics that check for bugs, performance and style issues. Extensible without recompilation through dynamic rules. Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion.
- unparam: Reports unused function parameters
I would love to enable these ones about errors, but those will be a followup cleanup PR since this is a lot of work:
- errcheck (this one is particularly important)
- nilnil
- nilerr
- errorlint
We still don't catch situations where we use the return value before checking the error.
Added this issue for follow-up https://github.com/cilium/tetragon/issues/989.
Just for info the pattern used here, that defaults to error and rely on the function to return nil and override is a bit weird and led to an issue while removing useless "always nil" return value from functions: https://github.com/cilium/tetragon/blob/557a6c93b1f71aed0af6da3c94323867426b2e97/pkg/sensors/manager.go#L60
Btw I'm also not a fan of that "BUG in SensorCtl" thing. Maybe we can refactor that slightly in the future.
LGTM just couple questions/nits.
waw thanks a lot for that fast and good review! :)