From 9275c5a0e1f8d5c98955c14194619274b3a9a04a Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 12 May 2026 00:04:36 +0000 Subject: [PATCH] Update golangci-lint and tighten lint config (#190) Bump `golangci-lint` to v2.12.2 and pin `govulncheck` to v1.3.0. Align `.golangci.yml` with the gitea repo's config: enable `revive` `var-naming` (with `skip-package-name-checks`) and drop the test-file exclusion for `errcheck`/`staticcheck`/`unparam`. Fix the now-surfaced `errcheck` violations in test handlers by discarding return values to match the existing codebase pattern. --- This PR was written with the help of Claude Opus 4.7 Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/190 Reviewed-by: Lunny Xiao Co-authored-by: silverwind Co-committed-by: silverwind --- .golangci.yml | 11 ++++------- Makefile | 4 ++-- operation/packages/packages_test.go | 6 +++--- operation/wiki/wiki_test.go | 4 ++-- pkg/gitea/redirect_test.go | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8fc98cd..f62038f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,7 +71,10 @@ linters: - name: unexported-return - name: var-declaration - name: var-naming - disabled: true + arguments: + - [] # AllowList - do not remove as args for the rule are positional and won't work without lists first + - [] # DenyList + - - skip-package-name-checks: true staticcheck: checks: - all @@ -91,12 +94,6 @@ linters: - common-false-positives - legacy - std-error-handling - rules: - - linters: - - errcheck - - staticcheck - - unparam - path: _test\.go issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/Makefile b/Makefile index cb8484e..9d94ca0 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ EXECUTABLE := gitea-mcp VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//') LDFLAGS := -X "main.Version=$(VERSION)" -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 -GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 +GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.3.0 .PHONY: help help: ## print this help message diff --git a/operation/packages/packages_test.go b/operation/packages/packages_test.go index 38dc8c5..200ef65 100644 --- a/operation/packages/packages_test.go +++ b/operation/packages/packages_test.go @@ -26,7 +26,7 @@ func TestPackageReadList(t *testing.T) { } mu.Unlock() w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`[{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0","html_url":"http://example.com","created_at":"2025-01-01T00:00:00Z","owner":{"login":"test-org"},"creator":{"login":"admin"}}]`)) + _, _ = w.Write([]byte(`[{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0","html_url":"http://example.com","created_at":"2025-01-01T00:00:00Z","owner":{"login":"test-org"},"creator":{"login":"admin"}}]`)) })) defer srv.Close() @@ -128,7 +128,7 @@ func TestPackageReadListVersions(t *testing.T) { } mu.Unlock() w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`[{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0"},{"id":2,"type":"container","name":"myrepo/myimage","version":"v2.0.0"}]`)) + _, _ = w.Write([]byte(`[{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0"},{"id":2,"type":"container","name":"myrepo/myimage","version":"v2.0.0"}]`)) })) defer srv.Close() @@ -195,7 +195,7 @@ func TestPackageReadGet(t *testing.T) { } mu.Unlock() w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0","html_url":"http://example.com","created_at":"2025-01-01T00:00:00Z","owner":{"login":"test-org"}}`)) + _, _ = w.Write([]byte(`{"id":1,"type":"container","name":"myrepo/myimage","version":"v1.0.0","html_url":"http://example.com","created_at":"2025-01-01T00:00:00Z","owner":{"login":"test-org"}}`)) })) defer srv.Close() diff --git a/operation/wiki/wiki_test.go b/operation/wiki/wiki_test.go index e72137d..2c9d5d9 100644 --- a/operation/wiki/wiki_test.go +++ b/operation/wiki/wiki_test.go @@ -32,10 +32,10 @@ func TestWikiWriteBase64Encoding(t *testing.T) { var gotBody map[string]string srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body, _ := io.ReadAll(r.Body) - json.Unmarshal(body, &gotBody) + _ = json.Unmarshal(body, &gotBody) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"title":"test"}`)) + _, _ = w.Write([]byte(`{"title":"test"}`)) })) defer srv.Close() diff --git a/pkg/gitea/redirect_test.go b/pkg/gitea/redirect_test.go index fc78bdb..761c34d 100644 --- a/pkg/gitea/redirect_test.go +++ b/pkg/gitea/redirect_test.go @@ -99,7 +99,7 @@ func TestDoJSON_GETRedirectFollowed(t *testing.T) { mux.HandleFunc("GET /api/v1/repos/owner/new-name/pulls/1", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(map[string]any{"id": 1, "title": "found"}) + _ = json.NewEncoder(w).Encode(map[string]any{"id": 1, "title": "found"}) }) srv := httptest.NewServer(mux) defer srv.Close()