mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-30 20:47:31 +02:00
Add Make targets for formatting and linting
Add configuration and document usage in README Entire-Checkpoint: 53425877e242
This commit is contained in:
30
.golangci.yml
Normal file
30
.golangci.yml
Normal file
@@ -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
|
||||
10
Makefile
10
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
|
||||
|
||||
20
README.md
20
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:
|
||||
|
||||
|
||||
49
gopls.json
Normal file
49
gopls.json
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user