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: implement golang linter #11

Merged
merged 9 commits into from
May 22, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Lint the entire golang project. This workflow relies on the
# '.golangci.yml' file for its configuration settings.
name: Lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.21'

- uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.57.2
args: --timeout 15m
70 changes: 70 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
run:
timeout: 10m
tests: true

# These linter checks can be modified on a per project basis.
# Simply remove them from the enable list to disable them.
linters:
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- decorder
- dupl
- dupword
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- forbidigo
- gci
- goconst
- gocritic
- godot
- gofumpt
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- ineffassign
- loggercheck
- misspell
- nilerr
- nilnil
- noctx
- staticcheck
- stylecheck
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace

linters-settings:
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(cosmossdk.io)
- prefix(github.com/cosmos)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cometbft/cometbft)
# TODO: Replace below with '- prefix(<project-package-name>)'
- prefix(github.com/strangelove-ventures/oss-repo-template)
gosec:
excludes:
- G404 # disables checks on insecure random number source

issues:
max-issues-per-linter: 0
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
golangci_lint_cmd=golangci-lint
golangci_version=v1.57.2
gofumpt_cmd=gofumpt
gofumpt_version=v0.6.0

default: help

.PHONY: help
## help: Prints this help message
help: Makefile
@echo
@echo "Available make commands:"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo

.PHONY: lint
## lint: Lint the repository
lint:
@echo "--> Running linter"
@if ! $(golangci_lint_cmd) --version 2>/dev/null | grep -q $(golangci_version); then \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version); \
fi
@$(golangci_lint_cmd) run ./... --timeout 15m
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: lint-fix
## lint-fix: Lint the repository and fix warnings (if applicable)
lint-fix:
@echo "--> Running linter and fixing issues"
@if ! $(golangci_lint_cmd) --version 2>/dev/null | grep -q $(golangci_version); then \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version); \
fi
@$(golangci_lint_cmd) run ./... --fix --timeout 15m

.PHONY: gofumpt
## gofumpt: Format the code with gofumpt
gofumpt:
@echo "--> Running gofumpt"
@if ! $(gofumpt_cmd) -version 2>/dev/null | grep -q $(gofumpt_version); then \
go install mvdan.cc/gofumpt@$(gofumpt_version); \
fi
@gofumpt -l -w .
Loading