From 08485232ed628015c86a10e02dc3490c30b49e08 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 3 Feb 2023 08:41:07 +0100 Subject: [PATCH] lint: replace deprecated golang.org/x/lint/golint with golangci-lint golint is deprecated. golangci-lint is a more than adequate replacement. Because it combines different linters, a single invocation in the Makefile is enough and then produces consistent output for all of them. It also gets enabled as a GitHub action. This will annotate pull requests. The godox linter gets enabled as replacement for the manual "grep -i fixme". For the sake of convenience, "make lint" installs golangci-lint. In contrast to golint before, this is done without polluting the go.mod file with the extra dependencies. --- .github/workflows/go.yml | 4 ---- .github/workflows/golangci-lint.yml | 25 +++++++++++++++++++++++++ .golangci.yml | 5 +++++ Makefile | 20 +++++++++----------- go.mod | 6 +----- go.sum | 10 ---------- tools_test.go | 29 ----------------------------- 7 files changed, 40 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml delete mode 100644 tools_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 22f771f..e4b2cf9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -38,10 +38,6 @@ jobs: - name: Download Dependencies run: go mod download - - name: Lint - if: matrix.latest - run: make lint - - name: Test run: make cover diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..d88cdb4 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,25 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + pull_request: +permissions: + contents: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + # When bumping this, then also bump the version in the Makefile's "go install". + version: v1.51.0 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..ad85878 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +linters: + enable: + - godox + - gofmt + diff --git a/Makefile b/Makefile index 53763fa..8f75aaa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ export GOBIN ?= $(shell pwd)/bin -GOLINT = $(GOBIN)/golint +GOLINT = $(GOBIN)/golangci-lint GO_FILES := $(shell \ find . '(' -path '*/.*' -o -path './vendor' ')' -prune \ @@ -24,18 +24,16 @@ cover: go test -race -coverprofile=cover.out -coverpkg=./... ./... go tool cover -html=cover.out -o cover.html +# Note that installation via "go install" is not recommended +# (https://golangci-lint.run/usage/install/#install-from-source). +# If this causes problems, install a pre-built binary. +# +# When bumping the version here, then also bump the version in +# .github/workflows/golangci-lint.yml $(GOLINT): - go install golang.org/x/lint/golint + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0 .PHONY: lint lint: $(GOLINT) - @rm -rf lint.log - @echo "Checking formatting..." - @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log - @echo "Checking vet..." - @go vet ./... 2>&1 | tee -a lint.log @echo "Checking lint..." - @$(GOLINT) ./... 2>&1 | tee -a lint.log - @echo "Checking for unresolved FIXMEs..." - @git grep -i fixme | grep -v -e '^vendor/' -e '^Makefile' | tee -a lint.log - @[ ! -s lint.log ] + @$(GOLINT) run ./... diff --git a/go.mod b/go.mod index afc8490..926ce59 100644 --- a/go.mod +++ b/go.mod @@ -2,16 +2,12 @@ module go.uber.org/goleak go 1.18 -require ( - github.com/stretchr/testify v1.8.0 - golang.org/x/lint v0.0.0-20190930215403-16217165b5de -) +require github.com/stretchr/testify v1.8.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/tools v0.1.5 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 88e9e00..f750522 100644 --- a/go.sum +++ b/go.sum @@ -13,16 +13,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/tools_test.go b/tools_test.go deleted file mode 100644 index 1aac1f1..0000000 --- a/tools_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2019 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -//go:build tools -// +build tools - -package goleak - -import ( - // Tools we use during development. - _ "golang.org/x/lint/golint" -)