Skip to content

Commit

Permalink
ci: Use golangci-lint for linting (#108)
Browse files Browse the repository at this point in the history
Instead of hand-managing and running linters, use golangci-lint.
This simplifies the Makefile and allows lint to run in parallel
with the build/test job.

Along with the golangci-lint defaults,
enable a couple other linters we generally agree with.
See also uber-go/zap#1323 and uber-go/sally#121 for similar changes.
  • Loading branch information
abhinav committed Oct 21, 2023
1 parent 03cb6e6 commit f995fdb
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 179 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,55 @@
name: CI

on:
push:
branches: [master]
tags: ['v*']
pull_request:
branches: ['*']

permissions:
contents: read

jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.20.x", "1.21.x"]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

- name: Test
run: make cover

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
name: Check out repository
- uses: actions/setup-go@v4
name: Set up Go
with:
go-version: 1.21.x
cache: false # managed by golangci-lint

- uses: golangci/golangci-lint-action@v3
name: Install golangci-lint
with:
version: latest
args: --version # make lint will run the linter

- run: make lint
name: Lint
52 changes: 0 additions & 52 deletions .github/workflows/go.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .golangci.yml
@@ -0,0 +1,28 @@
output:
# Make output more digestible with quickfix in vim/emacs/etc.
sort-results: true
print-issued-lines: false

linters:
enable:
- gofumpt
- nolintlint
- revive

linters-settings:
govet:
# These govet checks are disabled by default, but they're useful.
enable:
- niliness
- reflectvaluecompare
- sortslice
- unusedwrite

issues:
# Print all issues reported by all linters.
max-issues-per-linter: 0
max-same-issues: 0

# Don't ignore some of the issues that golangci-lint considers okay.
# This includes documenting all exported entities.
exclude-use-default: false
50 changes: 27 additions & 23 deletions Makefile
@@ -1,19 +1,26 @@
export GOBIN ?= $(shell pwd)/bin
# Directory containing the Makefile.
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

REVIVE = $(GOBIN)/revive
export GOBIN = $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)

GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
-o -name '*.go' -print | cut -b3-)
GO_FILES = $(shell find . \
-path '*/.*' -prune -o \
'(' -type f -a -name '*.go' ')' -print)

# Additional test flags.
TEST_FLAGS ?=

.PHONY: all
all: lint build test

.PHONY: lint
lint: golangci-lint tidy-lint

.PHONY: build
build:
go build ./...

.PHONY: install
install:
go mod download

.PHONY: test
test:
go test -v -race ./...
Expand All @@ -24,18 +31,15 @@ cover:
go test -race -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out -o cover.html

$(REVIVE):
cd tools && go install github.com/mgechev/revive
.PHONY: golangci-lint
golangci-lint:
golangci-lint run

.PHONY: lint
lint: $(REVIVE)
@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..."
@$(REVIVE) -set_exit_status ./... 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 ]
.PHONY: tidy
tidy:
go mod tidy

.PHONY: tidy-lint
tidy-lint:
go mod tidy
git diff --exit-code -- go.mod go.sum
8 changes: 0 additions & 8 deletions glide.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions tools/go.mod

This file was deleted.

46 changes: 0 additions & 46 deletions tools/go.sum

This file was deleted.

29 changes: 0 additions & 29 deletions tools/tools.go

This file was deleted.

0 comments on commit f995fdb

Please sign in to comment.