Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Use golangci-lint for linting #108

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.