From 6ec08b304db93ceaf83af23c655e107f29b4c8d3 Mon Sep 17 00:00:00 2001 From: Stojan Dimitrovski Date: Sun, 28 Apr 2024 14:23:34 +0200 Subject: [PATCH] ci: add exhaustive switch statement linter (#1557) Adds [a linter that checks for non-exhaustive `switch` statements](https://github.com/nishanths/exhaustive). --- .github/workflows/test.yml | 1 + Makefile | 2 ++ internal/api/logout.go | 1 + internal/observability/logging.go | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18241fef6..bc3baf1fe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,7 @@ jobs: run: | set -x go install honnef.co/go/tools/cmd/staticcheck@latest + go install github.com/nishanths/exhaustive/cmd/exhaustive@latest make static - name: Check gosec run: | diff --git a/Makefile b/Makefile index 9f8a5441f..f505cd446 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ dev-deps: ## Install developer dependencies @go install github.com/securego/gosec/v2/cmd/gosec@latest @go install honnef.co/go/tools/cmd/staticcheck@latest @go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest + @go install github.com/nishanths/exhaustive/cmd/exhaustive@latest deps: ## Install dependencies. @go mod download @@ -54,6 +55,7 @@ unused: dev-deps # Look for unused code static: dev-deps staticcheck ./... + exhaustive ./... generate: dev-deps go generate ./... diff --git a/internal/api/logout.go b/internal/api/logout.go index 2d5a2ecbf..ea5b871f7 100644 --- a/internal/api/logout.go +++ b/internal/api/logout.go @@ -48,6 +48,7 @@ func (a *API) Logout(w http.ResponseWriter, r *http.Request) error { return terr } + //exhaustive:ignore Default case is handled below. switch scope { case LogoutLocal: return models.LogoutSession(tx, s.ID) diff --git a/internal/observability/logging.go b/internal/observability/logging.go index 74a50c436..2e2595679 100644 --- a/internal/observability/logging.go +++ b/internal/observability/logging.go @@ -91,7 +91,7 @@ func setPopLogger(sql string) { } switch lvl { - case logging.Debug: + case logging.SQL, logging.Debug: l.Debug(s) case logging.Info: l.Info(s)