Skip to content

Commit

Permalink
Apply golangci-lint config and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Mar 13, 2024
1 parent b9971a4 commit 9c97def
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 132 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: test
on: ["push", "pull_request"]

env:
GO_VERSION: "1.20"
GO_VERSION: "1.22"
LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le"

jobs:
Expand Down Expand Up @@ -37,11 +37,9 @@ jobs:
- uses: actions/checkout@v4

- name: Install test binaries
env:
GO111MODULE: off
run: |
go get github.com/modocache/gover
go get github.com/mattn/goveralls
go install github.com/modocache/gover
go install github.com/mattn/goveralls
- name: test
run: PATH=$PATH:$(go env GOPATH)/bin COVERALLS=1 make check
Expand All @@ -53,3 +51,11 @@ jobs:
PATH=$PATH:$(go env GOPATH)/bin
gover
goveralls -coverprofile=gover.coverprofile -service=github
lint:
name: Run golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: make lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build
/_output/
*.o
*.orig
Expand Down
219 changes: 219 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
---
run:
concurrency: 6
deadline: 10m
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- goconst
- gocritic
- gocyclo
- godox
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- logrlint
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- zerologlint
# - cyclop
# - depguard
# - exhaustruct
# - funlen
# - gci
# - ginkgolinter
# - gochecknoglobals
# - gocognit
# - godot
# - goerr113
# - gomnd
# - gosec
# - ireturn
# - lll
# - nestif
# - nlreturn
# - nonamedreturns
# - revive
# - tagliatelle
# - testpackage
# - varnamelen
# - wrapcheck
# - wsl
linters-settings:
gocritic:
enabled-checks:
- appendAssign
- appendCombine
- argOrder
- assignOp
- badCall
- badCond
- badLock
- badRegexp
- badSorting
- badSyncOnceFunc
- boolExprSimplify
- builtinShadow
- builtinShadowDecl
- captLocal
- caseOrder
- codegenComment
- commentFormatting
- commentedOutCode
- commentedOutImport
- defaultCaseOrder
- deferInLoop
- deferUnlambda
- deprecatedComment
- docStub
- dupArg
- dupBranchBody
- dupCase
- dupImport
- dupSubExpr
- dynamicFmtString
- elseif
- emptyDecl
- emptyFallthrough
- emptyStringTest
- equalFold
- evalOrder
- exitAfterDefer
- exposedSyncMutex
- externalErrorReassign
- filepathJoin
- flagDeref
- flagName
- hexLiteral
- httpNoBody
- hugeParam
- ifElseChain
- importShadow
- indexAlloc
- initClause
- mapKey
- methodExprCall
- nestingReduce
- newDeref
- nilValReturn
- octalLiteral
- offBy1
- paramTypeCombine
- preferDecodeRune
- preferFilepathJoin
- preferFprint
- preferStringWriter
- preferWriteByte
- ptrToRefParam
- rangeExprCopy
- rangeValCopy
- redundantSprint
- regexpMust
- regexpPattern
- regexpSimplify
- returnAfterHttpError
- ruleguard
- singleCaseSwitch
- sliceClear
- sloppyLen
- sloppyReassign
- sloppyTypeAssert
- sortSlice
- sprintfQuotedString
- sqlQuery
- stringConcatSimplify
- stringXbytes
- stringsCompare
- switchTrue
- syncMapLoadAndDelete
- timeExprSimplify
- todoCommentWithoutDetail
- tooManyResultsChecker
- truncateCmp
- typeAssertChain
- typeDefFirst
- typeSwitchVar
- typeUnparen
- uncheckedInlineErr
- underef
- unlabelStmt
- unlambda
- unnamedResult
- unnecessaryBlock
- unnecessaryDefer
- unslice
- valSwap
- weakCond
- whyNoLint
- wrapperFunc
- yodaStyleExpr
27 changes: 20 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export GO111MODULE=off

GO ?= go
EPOCH_TEST_COMMIT ?= b0fc980
PROJECT := github.com/cri-o/ocicni
Expand All @@ -16,6 +14,10 @@ ETCDIR ?= ${DESTDIR}/etc
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_INFO := $(shell date +%s)

BUILD_PATH := $(shell pwd)/build
GOLANGCI_LINT := ${BUILD_PATH}/golangci-lint
GOLANGCI_LINT_VERSION := v1.56.2

# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
Expand Down Expand Up @@ -73,10 +75,20 @@ install.tools: .install.gitvalidation
fi

vendor:
export GO111MODULE=on \
$(GO) mod tidy && \
$(GO) mod vendor && \
$(GO) mod verify
$(GO) mod tidy && \
$(GO) mod vendor && \
$(GO) mod verify

$(GOLANGCI_LINT):
export VERSION=$(GOLANGCI_LINT_VERSION) \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=${BUILD_PATH} && \
curl -sSfL $$URL/$$VERSION/install.sh | sh -s $$VERSION

lint: ${GOLANGCI_LINT}
${GOLANGCI_LINT} version
${GOLANGCI_LINT} linters
GL_DEBUG=gocritic ${GOLANGCI_LINT} run

.PHONY: \
binaries \
Expand All @@ -87,4 +99,5 @@ vendor:
check \
install.tools \
.gitvalidation \
vendor
vendor \
lint
Loading

0 comments on commit 9c97def

Please sign in to comment.