Skip to content

Commit 81c0463

Browse files
Update golangci-lint:
Enable linters in golangci-lint config. This makes it so that linters are actually run. Update golangci-lint version to latest. Fix all issues after upgrade. Pass through exit code/status from golangci-lint. This will cause the Make target to fail with a non 0 exit. This is needed so that linting is enforced by CI. Remove golangci-lint from GitHub Actions. make all-checks handles downloading and running golangci-lint and will keep it the version up-to-date. Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
1 parent d7961f0 commit 81c0463

File tree

10 files changed

+169
-146
lines changed

10 files changed

+169
-146
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ jobs:
1515
uses: actions/setup-go@v3
1616
with:
1717
go-version-file: go.mod
18-
- name: Run golangci-lint
19-
uses: golangci/golangci-lint-action@v3
20-
with:
21-
args: -v --config .golangci.yml --timeout=5m
22-
version: latest
2318
- name: make all-checks
2419
run: make all-checks
2520
test:

.golangci.yml

Lines changed: 148 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,156 @@
1-
govet:
2-
auto-fix: true
3-
linters-settings:
4-
enable:
5-
- fieldalignment
6-
check-shadowing: true
7-
settings:
8-
printf:
9-
funcs:
10-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
11-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
12-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
13-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
14-
golint:
15-
min-confidence: 0
16-
gocyclo:
17-
min-complexity: 10
18-
maligned:
19-
suggest-new: true
20-
dupl:
21-
threshold: 100
22-
goconst:
23-
min-len: 2
24-
min-occurrences: 2
25-
depguard:
26-
list-type: blacklist
27-
packages:
28-
# logging is allowed only by logutils.Log, logrus
29-
# is allowed to use only in logutils package
30-
- github.com/sirupsen/logrus
31-
misspell:
32-
locale: US
33-
auto-fix: true
34-
lll:
35-
line-length: 140
36-
goimports:
37-
local-prefixes: github.com/golangci/golangci-lint
38-
gocritic:
39-
auto-fix: true
40-
enabled-tags:
41-
- performance
42-
- style
43-
- experimental
44-
disabled-checks:
45-
- wrapperFunc
46-
gofumpt:
47-
extra-rules: true
48-
auto-fix: true
49-
wsl:
50-
auto-fix: true
51-
stylecheck:
52-
auto-fix: true
53-
1+
version: "2"
2+
run:
3+
# The default runtime timeout is 1m, which doesn't work well on Github Actions.
4+
timeout: 4m
545
linters:
6+
default: none
557
enable:
8+
- asciicheck
9+
- bodyclose
10+
- copyloopvar
11+
- cyclop
12+
- dogsled
13+
- dupl
14+
- durationcheck
5615
- errcheck
57-
- gosimple
16+
- errname
17+
- errorlint
18+
- exhaustive
19+
- forcetypeassert
20+
- gocognit
21+
- goconst
22+
- gocritic
23+
- goheader
24+
- goprintffuncname
25+
- gosec
5826
- govet
59-
- gofmt
60-
- gocyclo
27+
- importas
6128
- ineffassign
62-
- stylecheck
63-
- deadcode
29+
- makezero
30+
- misspell
31+
- nakedret
32+
- nestif
33+
- nilerr
34+
- noctx
35+
- nolintlint
36+
- predeclared
37+
- revive
38+
- rowserrcheck
39+
- sqlclosecheck
6440
- staticcheck
65-
- structcheck
41+
- thelper
42+
- tparallel
43+
- unconvert
44+
- unparam
6645
- unused
67-
- prealloc
68-
- typecheck
69-
- varcheck
70-
# additional linters
71-
- bodyclose
72-
- gocritic
46+
- wastedassign
7347
- whitespace
74-
- wsl
75-
- goimports
76-
- golint
77-
- misspell
78-
- goerr113
79-
- noctx
80-
enable-all: false
81-
disable-all: true
82-
83-
run:
84-
skip-dirs:
85-
86-
87-
issues:
88-
exclude-rules:
89-
- linters:
90-
- gosec
91-
text: "weak cryptographic primitive"
92-
93-
- linters:
94-
- stylecheck
95-
text: "ST1016"
96-
exclude:
97-
# Default excludes from `golangci-lint run --help` with EXC0002 removed
98-
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
99-
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
100-
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments
101-
# - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
102-
# EXC0003 golint: False positive when tests are defined in package 'test'
103-
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
104-
# EXC0004 govet: Common false positives
105-
- (possible misuse of unsafe.Pointer|should have signature)
106-
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
107-
- ineffective break statement. Did you mean to break out of the outer loop
108-
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
109-
- Use of unsafe calls should be audited
110-
# EXC0007 gosec: Too many false-positives for parametrized shell calls
111-
- Subprocess launch(ed with variable|ing should be audited)
112-
# EXC0008 gosec: Duplicated errcheck checks
113-
- (G104|G307)
114-
# EXC0009 gosec: Too many issues in popular repos
115-
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
116-
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
117-
- Potential file inclusion via variable
118-
exclude-use-default: false
119-
120-
# golangci.com configuration
121-
# https://github.com/golangci/golangci/wiki/Configuration
122-
#service:
123-
# golangci-lint-version: 1.15.x # use the fixed version to not introduce new linters unexpectedly
124-
# prepare:
125-
# - echo "here I can run custom commands, but no preparation needed for this repo"
48+
settings:
49+
govet:
50+
enable:
51+
- fieldalignment
52+
settings:
53+
printf:
54+
funcs:
55+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
56+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
57+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
58+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
59+
gocyclo:
60+
min-complexity: 10
61+
dupl:
62+
threshold: 100
63+
goconst:
64+
min-len: 2
65+
min-occurrences: 2
66+
misspell:
67+
locale: US
68+
lll:
69+
line-length: 140
70+
gocritic:
71+
enabled-tags:
72+
- performance
73+
- style
74+
- experimental
75+
disabled-checks:
76+
- wrapperFunc
77+
cyclop:
78+
max-complexity: 37
79+
package-average: 34
80+
errorlint:
81+
# Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make
82+
# an error part of a package API should be a conscious decision by the author.
83+
# Also see Hyrums Law.
84+
errorf: false
85+
asserts: false
86+
exhaustive:
87+
default-signifies-exhaustive: true
88+
gocognit:
89+
min-complexity: 98
90+
nestif:
91+
min-complexity: 8
92+
nolintlint:
93+
require-explanation: true
94+
require-specific: true
95+
allow-unused: false
96+
revive:
97+
severity: warning
98+
rules:
99+
- name: atomic
100+
- name: blank-imports
101+
- name: bool-literal-in-expr
102+
- name: confusing-naming
103+
- name: constant-logical-expr
104+
- name: context-as-argument
105+
- name: context-keys-type
106+
- name: deep-exit
107+
- name: defer
108+
- name: range-val-in-closure
109+
- name: range-val-address
110+
- name: dot-imports
111+
- name: error-naming
112+
- name: error-return
113+
- name: error-strings
114+
- name: errorf
115+
- name: exported
116+
- name: identical-branches
117+
- name: if-return
118+
- name: import-shadowing
119+
- name: increment-decrement
120+
- name: indent-error-flow
121+
- name: indent-error-flow
122+
- name: package-comments
123+
- name: range
124+
- name: receiver-naming
125+
- name: redefines-builtin-id
126+
- name: superfluous-else
127+
- name: struct-tag
128+
- name: time-naming
129+
- name: unexported-naming
130+
- name: unexported-return
131+
- name: unnecessary-stmt
132+
- name: unreachable-code
133+
- name: unused-parameter
134+
- name: var-declaration
135+
- name: var-naming
136+
- name: unconditional-recursion
137+
- name: waitgroup-by-value
138+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
139+
- name: struct-tag
140+
arguments:
141+
- json,inline
142+
- yaml,omitzero
143+
exclusions:
144+
generated: lax
145+
presets:
146+
- comments
147+
- common-false-positives
148+
- legacy
149+
- std-error-handling
150+
paths:
151+
- examples
152+
formatters:
153+
exclusions:
154+
generated: lax
155+
paths:
156+
- examples

bmc/firmware.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88

99
"github.com/bmc-toolbox/bmclib/v2/constants"
10-
bconsts "github.com/bmc-toolbox/bmclib/v2/constants"
1110
bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
1211

1312
"github.com/hashicorp/go-multierror"
@@ -499,7 +498,7 @@ type FirmwareTaskVerifier interface {
499498
// return values:
500499
// state - returns one of the FirmwareTask statuses (see devices/constants.go).
501500
// status - returns firmware task progress or other arbitrary task information.
502-
FirmwareTaskStatus(ctx context.Context, kind bconsts.FirmwareInstallStep, component, taskID, installVersion string) (state constants.TaskState, status string, err error)
501+
FirmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string) (state constants.TaskState, status string, err error)
503502
}
504503

505504
// firmwareTaskVerifierProvider is an internal struct to correlate an implementation/provider and its name
@@ -510,7 +509,7 @@ type firmwareTaskVerifierProvider struct {
510509

511510
// firmwareTaskStatus returns the status of the firmware upload process.
512511

513-
func firmwareTaskStatus(ctx context.Context, kind bconsts.FirmwareInstallStep, component, taskID, installVersion string, generic []firmwareTaskVerifierProvider) (state constants.TaskState, status string, metadata Metadata, err error) {
512+
func firmwareTaskStatus(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string, generic []firmwareTaskVerifierProvider) (state constants.TaskState, status string, metadata Metadata, err error) {
514513
metadata = newMetadata()
515514

516515
for _, elem := range generic {
@@ -540,7 +539,7 @@ func firmwareTaskStatus(ctx context.Context, kind bconsts.FirmwareInstallStep, c
540539
}
541540

542541
// FirmwareTaskStatusFromInterfaces identifies implementations of the FirmwareTaskVerifier interface and passes the found implementations to the firmwareTaskStatus() wrapper.
543-
func FirmwareTaskStatusFromInterfaces(ctx context.Context, kind bconsts.FirmwareInstallStep, component, taskID, installVersion string, generic []interface{}) (state constants.TaskState, status string, metadata Metadata, err error) {
542+
func FirmwareTaskStatusFromInterfaces(ctx context.Context, kind constants.FirmwareInstallStep, component, taskID, installVersion string, generic []interface{}) (state constants.TaskState, status string, metadata Metadata, err error) {
544543
metadata = newMetadata()
545544

546545
implementations := make([]firmwareTaskVerifierProvider, 0)

bmc/inventory_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/bmc-toolbox/bmclib/v2/errors"
9-
bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
109
"github.com/bmc-toolbox/common"
1110
"github.com/stretchr/testify/assert"
1211
)
@@ -73,7 +72,7 @@ func TestInventoryFromInterfaces(t *testing.T) {
7372
badImplementation bool
7473
}{
7574
{"success with metadata", &common.Device{Common: common.Common{Vendor: "foo"}}, nil, 5 * time.Second, "foo", 1, false},
76-
{"failure with bad implementation", nil, bmclibErrs.ErrProviderImplementation, 5 * time.Second, "foo", 1, true},
75+
{"failure with bad implementation", nil, errors.ErrProviderImplementation, 5 * time.Second, "foo", 1, true},
7776
}
7877

7978
for _, tc := range testCases {

errors/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var (
112112
ErrBMCColdResetRequired = errors.New("BMC cold reset required")
113113

114114
// ErrHostPowercycleRequired is returned when a host powercycle is required.
115-
ErrHostPowercycleRequired = errors.New("Host power cycle required")
115+
ErrHostPowercycleRequired = errors.New("host power cycle required")
116116

117117
// ErrSessionExpired is returned when the BMC session is not valid
118118
// the receiver can then choose to request a new session.

lint.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LINTERS :=
2020
FIXERS :=
2121

2222
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
23-
GOLANGCI_LINT_VERSION ?= v1.61.0
23+
GOLANGCI_LINT_VERSION ?= v2.6.1
2424
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
2525
$(GOLANGCI_LINT_BIN):
2626
mkdir -p $(LINT_ROOT)/out/linters
@@ -30,11 +30,11 @@ $(GOLANGCI_LINT_BIN):
3030

3131
LINTERS += golangci-lint-lint
3232
golangci-lint-lint: $(GOLANGCI_LINT_BIN)
33-
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" \;
33+
find . -name go.mod -not -path "./out/*" -execdir sh -c '"$(GOLANGCI_LINT_BIN)" run --timeout 10m -c "$(GOLANGCI_LINT_CONFIG)"' '{}' '+'
3434

3535
FIXERS += golangci-lint-fix
3636
golangci-lint-fix: $(GOLANGCI_LINT_BIN)
37-
find . -name go.mod -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \;
37+
find . -name go.mod -not -path "./out/*" -execdir "$(GOLANGCI_LINT_BIN)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \;
3838

3939
.PHONY: _lint $(LINTERS)
4040
_lint: $(LINTERS)

0 commit comments

Comments
 (0)