diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 65a3c00..0c31de4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,5 @@ name: Lint + on: push: pull_request: @@ -24,11 +25,6 @@ jobs: go mod verify go mod download - LINT_VERSION=1.64.8 - curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \ - tar xz --strip-components 1 --wildcards \*/golangci-lint - mkdir -p bin && mv golangci-lint bin/ - - name: Run checks run: | STATUS=0 @@ -41,10 +37,10 @@ jobs: STATUS=1 fi } - - assert-nothing-changed go fmt ./... assert-nothing-changed go mod tidy - - bin/golangci-lint run --out-format=colored-line-number --timeout=3m || STATUS=$? - exit $STATUS + + - name: golangci-lint + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 + with: + version: v2.1.6 diff --git a/.golangci.yaml b/.golangci.yaml index 0224acc..459bb04 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,3 +1,6 @@ +# https://golangci-lint.run/usage/configuration +version: "2" + run: timeout: 5m tests: true @@ -7,17 +10,13 @@ linters: disable-all: true enable: - errcheck - - gosimple - govet - ineffassign - staticcheck - - typecheck - unused - gocyclo - gosec - misspell - - gofmt - - goimports - revive - interfacebloat - iface @@ -26,31 +25,35 @@ linters: - makezero - lll -linters-settings: - gocyclo: - min-complexity: 15 - dupl: - threshold: 100 - goconst: - min-len: 2 - min-occurrences: 2 - goimports: - local-prefixes: github.com/razorpay/razorpay-mcp-server - interfacebloat: - max: 5 - iface: - enable: - - opaque - - identical - revive: - rules: - - name: blank-imports - disabled: true - lll: - line-length: 80 - tab-width: 1 + settings: + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + gocyclo: + min-complexity: 15 + interfacebloat: + max: 5 + iface: + enable: + - opaque + - identical + lll: + line-length: 120 + tab-width: 1 + revive: + rules: + - name: blank-imports + disabled: true + +formatters: + enable: + - gofmt + - goimports output: - formats: colored-line-number - print-issued-lines: true - print-linter-name: true + formats: + text: + print-linter-name: true + print-issued-lines: true diff --git a/Makefile b/Makefile index 3854acc..0a9edf8 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ test-coverage: # Install golangci-lint install-lint: - @LINT_VERSION=1.64.8; \ + @LINT_VERSION=2.1.6; \ if ! command -v golangci-lint > /dev/null 2>&1; then \ echo "Installing golangci-lint v$$LINT_VERSION..."; \ curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v$$LINT_VERSION/golangci-lint-$$LINT_VERSION-$$($(GO) env GOOS)-$$($(GO) env GOARCH).tar.gz | \ @@ -68,7 +68,7 @@ lint: install-lint @if [ -f ./bin/golangci-lint ]; then \ ./bin/golangci-lint run --out-format=colored-line-number --timeout=3m; \ else \ - golangci-lint run --out-format=colored-line-number --timeout=3m; \ + golangci-lint run --timeout=3m; \ fi # Clean build artifacts @@ -90,4 +90,4 @@ help: @echo " test-coverage - Run tests with coverage" @echo " lint - Run linter" @echo " clean - Clean build artifacts" - @echo " help - Show this help message" \ No newline at end of file + @echo " help - Show this help message" diff --git a/pkg/log/log.go b/pkg/log/log.go index 0b4966a..20b50a2 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -32,7 +32,7 @@ func New(path string) (*slog.Logger, func(), error) { path = getDefaultLogPath() } - file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) // nolint:gosec if err != nil { // Fall back to stderr if we can't open the log file fmt.Fprintf( diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index 9603f6f..678125c 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -41,10 +41,10 @@ func TestNew(t *testing.T) { t.Run(tt.name, func(t *testing.T) { defer func() { if tt.path != "" { - os.Remove(tt.path) + _ = os.Remove(tt.path) } if tt.path == "" { - os.Remove(getDefaultLogPath()) + _ = os.Remove(getDefaultLogPath()) } }() diff --git a/pkg/razorpay/mock/server_test.go b/pkg/razorpay/mock/server_test.go index 20ce610..a7a69f7 100644 --- a/pkg/razorpay/mock/server_test.go +++ b/pkg/razorpay/mock/server_test.go @@ -25,7 +25,9 @@ func TestNewHTTPClient(t *testing.T) { resp, err := client.Get(server.URL + "/test") assert.NoError(t, err) - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) @@ -143,7 +145,9 @@ func TestNewServer(t *testing.T) { client := server.Client() resp, err := client.Do(req) assert.NoError(t, err) - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() assert.Equal(t, tc.expectedStatus, resp.StatusCode) @@ -204,14 +208,17 @@ func TestMultipleEndpoints(t *testing.T) { err error ) - if tc.method == "GET" { + switch tc.method { + case "GET": resp, err = client.Get(server.URL + tc.path) - } else if tc.method == "POST" { + case "POST": resp, err = client.Post(server.URL+tc.path, "application/json", nil) } assert.NoError(t, err) - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() assert.Equal(t, http.StatusOK, resp.StatusCode)