From 51bd3ff5076e55c595da572272d4870dea697679 Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Mon, 6 Jul 2026 09:00:38 -0700 Subject: [PATCH] [do not merge] setup golangci-lint This sets up golangci-lint. THis should only be merged after --- .github/workflows/ci.yml | 11 ++++----- .golangci.yml | 48 ++++++++++++++++++++++++++++++++++++++++ Makefile | 9 +++++++- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 218a623..b73ddf1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: - name: Checkout code uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 with: - # This job executes untrusted PR code (gazelle, gofmt, goimports). + # This job executes untrusted PR code (gazelle, golangci-lint). persist-credentials: false - name: Set up Go @@ -117,15 +117,12 @@ jobs: run: make gazelle - name: Run linters - run: | - gofmt -w . - go install golang.org/x/tools/cmd/goimports@latest - goimports -w . + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 - - name: Verify no uncommitted changes from linters + - name: Verify no uncommitted changes from gazelle run: | if [ -n "$(git status --porcelain)" ]; then - echo "::error::Code is not formatted. Please run 'make gazelle', 'gofmt -w .', and 'goimports -w .' locally and commit the results." + echo "::error::Code is not formatted. Please run 'make gazelle' locally and commit the results." git diff exit 1 fi diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f95f8a2 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,48 @@ +version: "2" + +run: + go: "1.24" + timeout: 5m + +linters: + default: standard + enable: + - goconst + - gocyclo + - misspell + - revive + settings: + goconst: + min-len: 3 + min-occurrences: 3 + gocyclo: + min-complexity: 30 + revive: + rules: + - name: blank-imports + - name: exported + arguments: + - disableStutteringCheck + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + exclusions: + generated: strict + presets: + - comments + - std-error-handling + rules: + - path: _test\.go + linters: + - errcheck + - goconst + paths: + - tangopb + - tangopbmock + - ".*/mock/" + - ".*mock/" + +formatters: + enable: + - gofmt + - goimports diff --git a/Makefile b/Makefile index 6c88155..46c4141 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build test proto gazelle clean clean-proto run-server run-client-get-graph run-client-changed-targets help +.PHONY: build clean clean-proto gazelle help lint proto run-client-changed-targets run-client-get-graph run-server test # Bazel wrapper BAZEL = ./tools/bazel @@ -15,6 +15,12 @@ test: @$(BAZEL) test //... @echo "All tests passed!" +# Run golangci-lint +lint: ## Run golangci-lint + @echo "Running golangci-lint..." + @golangci-lint run ./... + @echo "Lint passed!" + # Generate protobuf files using protoc proto: @echo "Generating protobuf files with protoc..." @@ -82,6 +88,7 @@ help: @echo "" @echo "Build & Test:" @echo " make build - Build all targets" + @echo " make lint - Run golangci-lint" @echo " make test - Run all tests" @echo " make gazelle - Update BUILD.bazel files" @echo " make clean - Clean generated files and binaries"