Skip to content

Commit

Permalink
chore(backend): Add golangci-lint and pre-commit config (#9428)
Browse files Browse the repository at this point in the history
* Add golangci-lint and pre-commit config

* Adopt golanci-lint config from k8s
  • Loading branch information
gkcalat authored May 17, 2023
1 parent 9bce215 commit c2bc434
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
27 changes: 27 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 5 additions & 7 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand All @@ -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
Expand Down

0 comments on commit c2bc434

Please sign in to comment.