From 5232164d78dd7e144fd89233bd9c41d0877b4a30 Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Wed, 15 Dec 2021 17:16:41 +1100 Subject: [PATCH 1/6] Add golangci linter --- .gitignore | 1 + .golangci.yaml | 11 +++++++++++ Makefile | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 .gitignore create mode 100644 .golangci.yaml create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..c50a73b --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,11 @@ +run: + timeout: 5m + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - ineffassign + - staticcheck + - unused diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..65f2212 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +GOBIN=$(shell pwd)/bin + +install-lint: + @curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.42.0 + +lint: install-lint + @echo "golangci-lint run ../..." + @$(GOBIN)/golangci-lint run ./... From 01e337832b6a8ea84169c390ce41260a4d710a08 Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Wed, 15 Dec 2021 17:20:17 +1100 Subject: [PATCH 2/6] Close response body --- mux_httpserver_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index 907ab91..4333346 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -25,6 +25,8 @@ func TestSchemeMatchers(t *testing.T) { if err != nil { t.Fatalf("unexpected error getting from server: %v", err) } + defer resp.Body.Close() + if resp.StatusCode != 200 { t.Fatalf("expected a status code of 200, got %v", resp.StatusCode) } From c99abc657a7d2f8047d408585bad36f8e823d87c Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Wed, 15 Dec 2021 17:23:53 +1100 Subject: [PATCH 3/6] Remove ineffectual assignment to matchErr "matchErr = nil" --- route.go | 1 - 1 file changed, 1 deletion(-) diff --git a/route.go b/route.go index 750afe5..7e72c6a 100644 --- a/route.go +++ b/route.go @@ -64,7 +64,6 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool { match.MatchErr = nil } - matchErr = nil return false } } From 4475f8548de5614b0493104c2062a584586dfb51 Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Wed, 15 Dec 2021 17:25:00 +1100 Subject: [PATCH 4/6] Conditional install of linter. Make command for "test" --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 65f2212..b39fe99 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ GOBIN=$(shell pwd)/bin install-lint: - @curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.42.0 + @if [ ! -f "$(GOBIN)/golangci-lint" ]; then \ + curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.42.0; \ + fi lint: install-lint @echo "golangci-lint run ../..." @$(GOBIN)/golangci-lint run ./... + +test: + go test -race -failfast ./... From 0f9946f404c274ab2d282c7e75259fb47d63908a Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Tue, 11 Jan 2022 10:01:42 +1100 Subject: [PATCH 5/6] Fix typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b39fe99..cfc8d16 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ install-lint: fi lint: install-lint - @echo "golangci-lint run ../..." + @echo "golangci-lint run ./..." @$(GOBIN)/golangci-lint run ./... test: From 6873cd4a8f118d3a273add6af78c4c6d619b24f4 Mon Sep 17 00:00:00 2001 From: Sukhjit Singh Date: Tue, 11 Jan 2022 10:06:19 +1100 Subject: [PATCH 6/6] Re-add ineffectual statement, but mark it with "// nolint" --- route.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/route.go b/route.go index 7e72c6a..29cc2ea 100644 --- a/route.go +++ b/route.go @@ -64,6 +64,8 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool { match.MatchErr = nil } + // nolint: ineffassign + matchErr = nil return false } }