From ed236ec539efbaa1a5ef8c07e2d522dd71491e2a Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Mon, 30 Mar 2026 16:23:12 +0200 Subject: [PATCH] Add Make targets for formatting and linting Add configuration and document usage in README Entire-Checkpoint: 53425877e242 --- .golangci.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 10 +++++++++- README.md | 20 ++++++++++++++++++++ gopls.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 .golangci.yml create mode 100644 gopls.json diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..3ea8b8ee --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +run: + timeout: 5m + +linters: + enable: + - gofumpt # gofumpt = true + - staticcheck # staticcheck = true + - unparam # unusedparams = true + - nilnil # nilness = true (catches nil returns of nil interface values) + - govet # base vet; nilness + unusedwrite via govet analyzers + +linters-settings: + gofumpt: + module-path: github.com/ClusterCockpit/cc-backend + + govet: + enable: + - nilness + - unusedwrite + +issues: + exclude-dirs: + - .git + - .vscode + - .idea + - node_modules + exclude-rules: + - path: _test\.go + linters: + - unparam diff --git a/Makefile b/Makefile index 4de1623a..d139583d 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ SVELTE_SRC = $(wildcard $(FRONTEND)/src/*.svelte) \ $(wildcard $(FRONTEND)/src/header/*.svelte) \ $(wildcard $(FRONTEND)/src/job/*.svelte) -.PHONY: clean distclean test tags frontend swagger graphql $(TARGET) +.PHONY: clean distclean fmt lint test tags frontend swagger graphql $(TARGET) .NOTPARALLEL: @@ -75,6 +75,14 @@ test: @go vet ./... @go test ./... +fmt: + $(info ===> FORMAT) + @gofumpt -l -w . + +lint: + $(info ===> LINT) + @golangci-lint run ./... + tags: $(info ===> TAGS) @ctags -R diff --git a/README.md b/README.md index 030c9bd3..80a21a39 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,26 @@ the following targets: frontend source files will result in a complete rebuild. - `make clean`: Clean go build cache and remove binary. - `make test`: Run the tests that are also run in the GitHub workflow setup. +- `make fmt`: Format all Go source files using + [gofumpt](https://github.com/mvdan/gofumpt), a stricter superset of `gofmt`. + Requires `gofumpt` to be installed (see below). +- `make lint`: Run [golangci-lint](https://golangci-lint.run/) with the project + configuration in `.golangci.yml`. Requires `golangci-lint` to be installed + (see below). + +### Installing development tools + +`gofumpt` and `golangci-lint` are not part of the Go module and must be +installed separately: + +```sh +# Formatter (gofumpt) +go install mvdan.cc/gofumpt@latest + +# Linter (golangci-lint) — use the official install script to get a +# pre-built binary; installing via `go install` is not supported upstream. +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin +``` A common workflow for setting up cc-backend from scratch is: diff --git a/gopls.json b/gopls.json new file mode 100644 index 00000000..cea2d908 --- /dev/null +++ b/gopls.json @@ -0,0 +1,49 @@ +{ + "gofumpt": true, + "codelenses": { + "gc_details": false, + "generate": true, + "regenerate_cgo": true, + "run_govulncheck": true, + "test": true, + "tidy": true, + "upgrade_dependency": true, + "vendor": true + }, + "hints": { + "assignVariableTypes": true, + "compositeLiteralFields": true, + "compositeLiteralTypes": true, + "constantValues": true, + "functionTypeParameters": true, + "parameterNames": true, + "rangeVariableTypes": true + }, + "analyses": { + "nilness": true, + "unusedparams": true, + "unusedwrite": true, + "useany": true + }, + "usePlaceholders": true, + "completeUnimported": true, + "staticcheck": true, + "directoryFilters": [ + "-.git", + "-.vscode", + "-.idea", + "-.vscode-test", + "-node_modules", + "-web/frontend", + "-web/templates", + "-var", + "-api", + "-configs", + "-init", + "-internal/repository/migrations", + "-internal/repository/testdata", + "-internal/importer/testdata", + "-pkg/archive/testdata" + ], + "semanticTokens": true +}