chore(backend): Add golangci-lint and pre-commit config (#9428)
* Add golangci-lint and pre-commit config * Adopt golanci-lint config from k8s
This commit is contained in:
parent
9bce215893
commit
c2bc434c11
|
|
@ -0,0 +1,27 @@
|
|||
run:
|
||||
timeout: 30m
|
||||
skip-files:
|
||||
- "api\\*.go$"
|
||||
- "backend\\api\\*.go"
|
||||
|
||||
issues:
|
||||
max-same-issues: 0
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable: # please keep this alphabetized
|
||||
- gocritic
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- unused
|
||||
|
||||
linters-settings: # please keep this alphabetized
|
||||
misspell:
|
||||
locale: US
|
||||
staticcheck:
|
||||
checks:
|
||||
- "all"
|
||||
|
|
@ -46,3 +46,16 @@ repos:
|
|||
# docformatter messes up certain sphinx link formatting.
|
||||
# The kubernetes_platform/python docstrings are heavy on links, so ignore.
|
||||
exclude: (sdk/python/kfp/compiler/compiler_test.py|kubernetes_platform/python/)
|
||||
|
||||
# Golang pre-submit hooks
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.52.2
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
name: golangci-lint
|
||||
description: Fast linters runner for Go.
|
||||
entry: golangci-lint run --new-from-rev HEAD --fix
|
||||
types: [go]
|
||||
language: golang
|
||||
require_serial: true
|
||||
pass_filenames: false
|
||||
|
|
|
|||
|
|
@ -17,13 +17,11 @@ go build -o /tmp/apiserver backend/src/apiserver/*.go
|
|||
|
||||
## Code Style
|
||||
|
||||
Use [gofmt](https://pkg.go.dev/cmd/gofmt) package to format your .go source files. There is no need to format the swagger generated go clients, so only run the following command in `./backend/src` and `./backend/test` folder.
|
||||
Backend codebase follows the [Google's Go Style Guide](https://google.github.io/styleguide/go/). Please, take time to get familiar with the [best practices](https://google.github.io/styleguide/go/best-practices). It is not intended to be exhaustive, but it often helps minimizing guesswork among developers and keep codebase uniform and consistent.
|
||||
|
||||
```
|
||||
go fmt ./...
|
||||
```
|
||||
We use [golangci-lint](https://golangci-lint.run/) tool that can catch common mistakes locally (see detailed configuration [here](https://github.com/kubeflow/pipelines/blob/master/.golangci.yaml)). It can be [conveniently integrated](https://golangci-lint.run/usage/integrations/) with multiple popular IDEs such as VS Code or Vim.
|
||||
|
||||
For more information, see [this blog](https://go.dev/blog/gofmt).
|
||||
Finally, it is advised to install [pre-commit](https://pre-commit.com/) in order to automate linter checks (see configuration [here](https://github.com/kubeflow/pipelines/blob/master/.pre-commit-config.yaml))
|
||||
|
||||
## Building APIServer image locally
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue