Skip to content

Commit

Permalink
Run 'lint-install', Address golangci-lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Stromberg <[email protected]>
  • Loading branch information
tstromberg committed Aug 31, 2021
1 parent 8550bae commit 6402b21
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-non-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if ! shfmt -f . | xargs shfmt -s -l -d; then
failed=1
fi

if ! shfmt -f . | xargs shellcheck; then
if ! make lint; then
failed=1
fi

Expand Down
199 changes: 199 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
linters-settings:
cyclop:
# NOTE: This is a very high transitional threshold
max-complexity: 37
package-average: 34.0
skip-tests: true

gocognit:
# NOTE: This is a very high transitional threshold
min-complexity: 98

dupl:
threshold: 200

goconst:
min-len: 4
min-occurrences: 5
ignore-tests: true

errorlint:
# these are still common in Go: for instance, exit errors.
asserts: false

exhaustive:
default-signifies-exhaustive: true

nestif:
min-complexity: 8

nolintlint:
require-explanation: true
allow-unused: false
require-specific: true

revive:
ignore-generated-header: true
severity: warning
rules:
- name: atomic
- name: blank-imports
- name: bool-literal-in-expr
- name: confusing-naming
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: deep-exit
- name: defer
- name: range-val-in-closure
- name: range-val-address
- name: dot-imports
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: struct-tag
- name: time-naming
- name: unexported-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
- name: unconditional-recursion
- name: waitgroup-by-value

staticcheck:
go: "1.16"

unused:
go: "1.16"

output:
sort-results: true

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- cyclop
- deadcode
- dogsled
- dupl
- durationcheck
- errcheck
# errname is only available in golangci-lint v1.42.0+ - wait until v1.43 is available to settle
#- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocognit
- goconst
- gocritic
- godot
- gofmt
- goheader
- goimports
- goprintffuncname
- gosimple
- govet
- ifshort
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nestif
- nilerr
- noctx
- nolintlint
- predeclared
# disabling for the initial iteration of the linting tool
#- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
- whitespace

# Disabled linters, due to being misaligned with Go practices
# - exhaustivestruct
# - gochecknoglobals
# - gochecknoinits
# - goconst
# - godox
# - goerr113
# - gomnd
# - lll
# - nlreturn
# - testpackage
# - wsl

# Disabled linters, due to not being relevant to our code base:
# - maligned
# - prealloc "For most programs usage of prealloc will be a premature optimization."

# Disabled linters due to bad error messages or bugs
# - gofumpt
# - gosec
# - tagliatelle


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

- path: cmd.*
linters:
- noctx

- path: main\.go
linters:
- noctx

- path: cmd.*
text: "deep-exit"

- path: main\.go
text: "deep-exit"

# This check is of questionable value
- linters:
- tparallel
text: "call t.Parallel on the top level as well as its subtests"

# Don't hide lint issues just because there are many of them
max-same-issues: 0
max-issues-per-linter: 0
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# BEGIN: lint-install ../sandbox
# http://github.com/tinkerbell/lint-install

GOLINT_VERSION ?= v1.42.0

SHELLCHECK_VERSION ?= v0.7.2
LINT_OS := $(shell uname)
LINT_ARCH := $(shell uname -m)
LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# shellcheck and hadolint lack arm64 native binaries: rely on x86-64 emulation
ifeq ($(LINT_OS),Darwin)
ifeq ($(LINT_ARCH),arm64)
LINT_ARCH=x86_64
endif
endif

LINT_LOWER_OS = $(shell echo $(LINT_OS) | tr '[:upper:]' '[:lower:]')
GOLINT_CONFIG:=$(LINT_ROOT)/.golangci.yml

lint: out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)
find . -name go.mod | xargs -n1 dirname | xargs -n1 -I{} sh -c "cd {} && $(LINT_ROOT)/out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH) run -c $(GOLINT_CONFIG)"
out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck $(shell find . -name "*.sh")

out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)/shellcheck:
mkdir -p out/linters
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/$(SHELLCHECK_VERSION)/shellcheck-$(SHELLCHECK_VERSION).$(LINT_LOWER_OS).$(LINT_ARCH).tar.xz | tar -C out/linters -xJf -
mv out/linters/shellcheck-$(SHELLCHECK_VERSION) out/linters/shellcheck-$(SHELLCHECK_VERSION)-$(LINT_ARCH)

out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH):
mkdir -p out/linters
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)-$(LINT_ARCH)

# END: lint-install ../sandbox
13 changes: 11 additions & 2 deletions test/vagrant/vagrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ func TestVagrantSetupGuide(t *testing.T) {
}

for ii := 0; ii < 5; ii++ {
resp, err := http.Get("http://localhost:42114/healthz")
req, err := http.NewRequestWithContext(ctx, "GET", "http://localhost:42114/healthz", nil)
if err != nil {
t.Errorf("error forming request: %v", err)
}

h := &http.Client{}
resp, err := h.Do(req)
if err != nil || resp.StatusCode != http.StatusOK {
if err != nil {
t.Logf("err tinkerbell healthcheck... retrying: %s", err)
Expand All @@ -70,6 +76,9 @@ func TestVagrantSetupGuide(t *testing.T) {
}
time.Sleep(10 * time.Second)
}
if err := resp.Body.Close(); err != nil {
t.Logf("error closing body: %v", err)
}
}

t.Log("Tinkerbell is up and running")
Expand Down Expand Up @@ -173,7 +182,7 @@ tasks:
return resp.Id, nil
}

func registerHardware(ctx context.Context, cl *client.FullClient) error {
func registerHardware(_ context.Context, cl *client.FullClient) error {
data := []byte(`{
"id": "ce2e62ed-826f-4485-a39f-a82bb74338e2",
"metadata": {
Expand Down

0 comments on commit 6402b21

Please sign in to comment.