Skip to content

Commit

Permalink
Create Make target for linting
Browse files Browse the repository at this point in the history
Inclusion of golangci-lint config file allows local lint
execution and Makefile inclusion lowers the barrier for
devs and GH workflow consumption.

Signed-off-by: Kennelly, Martin <[email protected]>
  • Loading branch information
martinkennelly committed May 5, 2021
1 parent bbb5b8c commit ede7d2f
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Tested with golangci-lint ver. 1.37
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- unnamedResult
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/k8snetworkplumbingwg/sriov-network-device-plugin
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
lll:
line-length: 140
misspell:
locale: US
prealloc:
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- funlen
#- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
#- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- rowserrcheck
#- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- gosec
- dupl

run:
skip-dirs:
- .github/
- deployments/
- docs/
- images/
- scripts/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ image :
test :
scripts/test.sh

lint :
scripts/lint.sh

vendor :
go mod tidy && go mod vendor

Expand Down
32 changes: 32 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -eo pipefail

GOLANGCI_LINT_VER="v1.37.1"
GOLANGCI_BIN_NAME="golangci-lint"
GOLANGCI_INSTALL_URL="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
RETRY=3
TIMEOUT=300

repo_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
repo_bin="${repo_root:?}/bin"
export PATH="${PATH}:${repo_bin}"

# install golangci lint if not available in PATH
if ! command -v "${GOLANGCI_BIN_NAME}" &> /dev/null; then
mkdir -p "${repo_bin}"

curl --silent --show-error --fail --location --retry "${RETRY}" \
--connect-timeout "${TIMEOUT}" "${GOLANGCI_INSTALL_URL}" \
| sh -s -- -b "${repo_bin}" "${GOLANGCI_LINT_VER}"

export PATH="${PATH}:${repo_bin}"

# validate that we can access golangci lint
if ! command -v "${GOLANGCI_BIN_NAME}" &> /dev/null; then
echo "failed to install golangci lint in '${repo_bin}'"
exit 2
fi
fi

cd "${repo_root}"
"${GOLANGCI_BIN_NAME}" run

0 comments on commit ede7d2f

Please sign in to comment.