diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000000..5a887a56d5 --- /dev/null +++ b/.golangci.yaml @@ -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" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f9fcd93630..49e5c41120 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/backend/README.md b/backend/README.md index 74c403113c..ecbad2f390 100644 --- a/backend/README.md +++ b/backend/README.md @@ -3,7 +3,7 @@ Pipelines backend. ## Building & Testing -To run all unittests for backend: +To run all unittests for backend: ``` go test -v -cover ./backend/... @@ -17,17 +17,15 @@ 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 -The API server image can be built from the root folder of the repo using: +The API server image can be built from the root folder of the repo using: ``` export API_SERVER_IMAGE=api_server docker build -f backend/Dockerfile . --tag $API_SERVER_IMAGE