Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Lint

on:
push:
pull_request:
Expand All @@ -17,34 +18,9 @@ jobs:
- name: Set up Go
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b
with:
go-version-file: 'go.mod'

- name: Verify dependencies
run: |
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
assert-nothing-changed() {
local diff
"$@" >/dev/null || return 1
if ! diff="$(git diff -U1 --color --exit-code)"; then
printf '\e[31mError: running `\e[1m%s\e[22m` results in modifications that you must check into version control:\e[0m\n%s\n\n' "$*" "$diff" >&2
git checkout -- .
STATUS=1
fi
}
go-version-file: "go.mod"

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
63 changes: 33 additions & 30 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# https://golangci-lint.run/usage/configuration
version: "2"

run:
timeout: 5m
tests: true
Expand All @@ -7,17 +10,13 @@ linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- gocyclo
- gosec
- misspell
- gofmt
- goimports
- revive
- interfacebloat
- iface
Expand All @@ -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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand All @@ -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
Expand All @@ -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"
@echo " help - Show this help message"
2 changes: 1 addition & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestNew(t *testing.T) {
},
}

// nolint:all
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
Expand Down
11 changes: 6 additions & 5 deletions pkg/razorpay/mock/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNewHTTPClient(t *testing.T) {

resp, err := client.Get(server.URL + "/test")
assert.NoError(t, err)
defer resp.Body.Close()
defer resp.Body.Close() // nolint:errcheck

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestNewServer(t *testing.T) {
client := server.Client()
resp, err := client.Do(req)
assert.NoError(t, err)
defer resp.Body.Close()
defer resp.Body.Close() // nolint:errcheck

assert.Equal(t, tc.expectedStatus, resp.StatusCode)

Expand Down Expand Up @@ -204,14 +204,15 @@ 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 resp.Body.Close() // nolint:errcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can u avoid these no lint

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I need to fix this but unsure on how to do this like mentioned in the description. I'll try out something and we can talk through it.

Oh, I missed the go mod checks in the workflow. I'll fix it right away.


assert.Equal(t, http.StatusOK, resp.StatusCode)

Expand Down