Add golangci-lint custom linter infrastructure
We have a comprehensive style guide. As this style guide is becoming more complicated, it's quite hard for both implementers and reviewers to remember every detail. Linters are the best way to catch style guide violations systematically and without personal hard feelings. In addition, I feel the urge of having linters to advocate some direction in the source code. One example I have in mind is to apply structerr.
Unfortunately, golangci-lint doesn't support dynamic linter. I missed the flexibility of rubocop, a Ruby-equivalent of golangci-lint, where it's trivial to add a new linter. This MR adds the infrastructure to support custom linters. Golangci-lint allows to configure a linter compiled under plugin mode. It means that we need to compile each linter with -buildmode=plugin
flag. The compiled artifacts are then configured in .golangci.yml
file. New linter implementation follows the guide in this link: https://golangci-lint.run/contributing/new-linters/
Implementing this linter requires the following steps:
- Add analyzers implemting the checks to tools/gitaly-linters package
- Add the new checks to
lint.go
file - Re-compile via
make gitaly-linters
ormake lint
This MR also implement some checks for https://gitlab.com/gitlab-org/gitaly/-/blob/master/STYLE.md
NOTE: The new linter is not enabled by default because we have to fix the occurrences beforehand. I'll open follow-up MRs later. They are temporarily enabled here, just for references: https://gitlab.com/gitlab-org/gitaly/-/jobs/3781938533
Use %w when wrapping errors
Source: https://gitlab.com/gitlab-org/gitaly/-/blob/master/STYLE.md#use-w-when-wrapping-errors
Use %q when interpolating strings
Source: https://gitlab.com/gitlab-org/gitaly/-/blob/master/STYLE.md#use-q-when-interpolating-strings