Skip to content

Commit 51e8da1

Browse files
Merge pull request #1394 from Nordix/add/golangci-lint-workflow-kashif
🌱 Add golangci-lint github workflow
2 parents fc4a036 + d7229e2 commit 51e8da1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+547
-537
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: golangci-lint
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
# Remove all permissions from GITHUB_TOKEN except metadata.
8+
permissions: {}
9+
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
working-directory:
18+
- ""
19+
- test
20+
- apis
21+
- pkg/hardwareutils
22+
steps:
23+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
24+
- name: Calculate go version
25+
id: vars
26+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
27+
- name: Set up Go
28+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
29+
with:
30+
go-version: ${{ steps.vars.outputs.go_version }}
31+
- name: golangci-lint-${{matrix.working-directory}}
32+
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
33+
with:
34+
version: v1.54.2
35+
working-directory: ${{matrix.working-directory}}

.golangci.yaml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
run:
2+
deadline: 5m
3+
skip-dirs:
4+
- mock*
5+
skip-files:
6+
- "zz_generated.*\\.go$"
7+
- ".*conversion.*\\.go$"
8+
linters:
9+
disable-all: true
10+
enable:
11+
- asciicheck
12+
- bodyclose
13+
- dogsled
14+
# - errcheck
15+
# - errorlint
16+
- exportloopref
17+
# - goconst
18+
# - gocritic
19+
# - godot
20+
# - gofmt
21+
# - goimports
22+
# - gosimple
23+
# - govet
24+
# - importas
25+
# - gosec
26+
# - ineffassign
27+
# - misspell
28+
# - nakedret
29+
# - nilerr
30+
# - noctx
31+
# - nolintlint
32+
# - prealloc
33+
# - predeclared
34+
# - revive
35+
# - rowserrcheck
36+
# - staticcheck
37+
# - stylecheck
38+
# - thelper
39+
# - typecheck
40+
# - unconvert
41+
# - unused
42+
# - whitespace
43+
# Run with --fast=false for more extensive checks
44+
fast: true
45+
46+
linters-settings:
47+
gosec:
48+
go: "1.20"
49+
severity: medium
50+
confidence: medium
51+
concurrency: 8
52+
importas:
53+
no-unaliased: true
54+
alias:
55+
# Kubernetes
56+
- pkg: k8s.io/api/core/v1
57+
alias: corev1
58+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
59+
alias: apiextensionsv1
60+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
61+
alias: metav1
62+
- pkg: k8s.io/apimachinery/pkg/api/errors
63+
alias: k8serrors
64+
- pkg: k8s.io/apimachinery/pkg/util/errors
65+
alias: kerrors
66+
- pkg: k8s.io/component-base/logs/api/v1
67+
alias: logsv1
68+
# Controller Runtime
69+
- pkg: sigs.k8s.io/controller-runtime
70+
alias: ctrl
71+
# BMO
72+
- pkg: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
73+
alias: metal3api
74+
nolintlint:
75+
allow-unused: false
76+
allow-leading-space: false
77+
require-specific: true
78+
staticcheck:
79+
go: "1.20"
80+
stylecheck:
81+
go: "1.20"
82+
gocritic:
83+
enabled-tags:
84+
- experimental
85+
disabled-checks:
86+
- appendAssign
87+
- dupImport # https://github.com/go-critic/go-critic/issues/845
88+
- evalOrder
89+
- ifElseChain
90+
- octalLiteral
91+
- regexpSimplify
92+
- sloppyReassign
93+
- truncateCmp
94+
- typeDefFirst
95+
- unnamedResult
96+
- unnecessaryDefer
97+
- whyNoLint
98+
- wrapperFunc
99+
unused:
100+
go: "1.20"
101+
issues:
102+
exclude-rules:
103+
- path: test/e2e
104+
linters:
105+
- gosec
106+
- path: _test\.go
107+
linters:
108+
- unused
109+
# Specific exclude rules for deprecated fields that are still part of the codebase.
110+
# These should be removed as the referenced deprecated item is removed from the project.
111+
- linters:
112+
- staticcheck
113+
text: "SA1019:"
114+
# Disable linters for conversion
115+
- linters:
116+
- staticcheck
117+
text: "SA1019:"
118+
path: .*(api|types)\/.*\/conversion.*\.go$
119+
# Dot imports for gomega or ginkgo are allowed
120+
# within test files.
121+
- path: _test\.go
122+
text: should not use dot imports
123+
- path: (test|e2e)/.*.go
124+
text: should not use dot imports
125+
- linters:
126+
- revive
127+
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
128+
# Exclude some packages or code to require comments, for example test code, or fake clients.
129+
- linters:
130+
- revive
131+
text: exported (method|function|type|const) (.+) should have comment or be unexported
132+
source: (func|type).*Fake.*
133+
- linters:
134+
- revive
135+
text: exported (method|function|type|const) (.+) should have comment or be unexported
136+
path: fake_\.go
137+
- linters:
138+
- revive
139+
text: exported (method|function|type|const) (.+) should have comment or be unexported
140+
path: .*(api|types)\/.*\/conversion.*\.go$
141+
- linters:
142+
- revive
143+
text: "var-naming: don't use underscores in Go names;"
144+
path: .*(api|types)\/.*\/conversion.*\.go$
145+
- linters:
146+
- revive
147+
text: "receiver-naming: receiver name"
148+
path: .*(api|types)\/.*\/conversion.*\.go$
149+
- linters:
150+
- stylecheck
151+
text: "ST1003: should not use underscores in Go names;"
152+
path: .*(api|types)\/.*\/conversion.*\.go$
153+
- linters:
154+
- stylecheck
155+
text: "ST1016: methods on the same type should have the same receiver name"
156+
path: .*(api|types)\/.*\/conversion.*\.go$
157+
include:
158+
- EXC0002 # include "missing comments" issues from golangci-lint
159+
max-issues-per-linter: 0
160+
max-same-issues: 0

.golangci.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

cmd/get-hardware-details/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
ironicTrustedCAFile := os.Getenv("IRONIC_CACERT_FILE")
2929
ironicInsecureStr := os.Getenv("IRONIC_INSECURE")
3030
ironicInsecure := false
31-
if strings.ToLower(ironicInsecureStr) == "true" {
31+
if strings.EqualFold(ironicInsecureStr, "true") {
3232
ironicInsecure = true
3333
}
3434

cmd/make-bm-worker/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,4 @@ func main() {
105105
}
106106

107107
fmt.Fprint(os.Stdout, result)
108-
109108
}

cmd/make-bm-worker/templates/templates_test.go

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

88
func compareStrings(t *testing.T, s1, s2 string) bool {
9+
t.Helper()
910
if s1 == s2 {
1011
return true
1112
}

cmd/make-virt-host/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ const (
2929
</interface>
3030
*/
3131

32-
// MAC is a hardware address for a NIC
32+
// MAC is a hardware address for a NIC.
3333
type MAC struct {
3434
XMLName xml.Name `xml:"mac"`
3535
Address string `xml:"address,attr"`
3636
}
3737

38-
// Source is the network to which the interface is attached
38+
// Source is the network to which the interface is attached.
3939
type Source struct {
4040
XMLName xml.Name `xml:"source"`
4141
Bridge string `xml:"bridge,attr"`
4242
}
4343

44-
// Interface is one NIC
44+
// Interface is one NIC.
4545
type Interface struct {
4646
XMLName xml.Name `xml:"interface"`
4747
MAC MAC `xml:"mac"`
4848
Source Source `xml:"source"`
4949
}
5050

51-
// Domain is the main tag for the XML document
51+
// Domain is the main tag for the XML document.
5252
type Domain struct {
5353
Interfaces []Interface `xml:"devices>interface"`
5454
}
@@ -113,7 +113,7 @@ vbmc list -f json -c 'Domain name' -c Port
113113
*/
114114

115115
// VBMC holds the parameters for describing a virtual machine
116-
// controller
116+
// controller.
117117
type VBMC struct {
118118
Port int `json:"Port"`
119119
Name string `json:"Domain name"`

controllers/metal3.io/action_result.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1010

11-
metal3 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
11+
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
1212
"github.com/metal3-io/baremetal-operator/pkg/provisioner"
1313
)
1414

1515
// This is an upper limit for the ErrorCount, so that the max backoff
16-
// timeout will not exceed (roughly) 8 hours
16+
// timeout will not exceed (roughly) 8 hours.
1717
const maxBackOffCount = 9
1818

1919
func init() {
@@ -57,7 +57,7 @@ func (r actionUpdate) Dirty() bool {
5757
}
5858

5959
// actionDelayed it's the same of an actionUpdate, but the requeue time
60-
// is calculated using a fixed backoff with jitter
60+
// is calculated using a fixed backoff with jitter.
6161
type actionDelayed struct {
6262
actionUpdate
6363
}
@@ -120,7 +120,7 @@ func (r actionError) NeedsRegistration() bool {
120120
// and that the resource should be marked as in error.
121121
type actionFailed struct {
122122
dirty bool
123-
ErrorType metal3.ErrorType
123+
ErrorType metal3api.ErrorType
124124
errorCount int
125125
}
126126

@@ -133,9 +133,8 @@ type actionFailed struct {
133133
// 6 [32m, 1h4m]
134134
// 7 [1h4m, 2h8m]
135135
// 8 [2h8m, 4h16m]
136-
// 9 [4h16m, 8h32m]
136+
// 9 [4h16m, 8h32m].
137137
func calculateBackoff(errorCount int) time.Duration {
138-
139138
if errorCount > maxBackOffCount {
140139
errorCount = maxBackOffCount
141140
}

controllers/metal3.io/action_result_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ import (
99
)
1010

1111
func TestBackoffIncrements(t *testing.T) {
12-
1312
var backOff time.Duration
1413
for i := 1; i <= maxBackOffCount; i++ {
1514
prev := backOff
1615
backOff = calculateBackoff(i)
1716

1817
assert.GreaterOrEqual(t, backOff.Milliseconds(), prev.Milliseconds())
1918
}
20-
2119
}
2220

2321
func TestMaxBackoffDuration(t *testing.T) {
24-
2522
maxBackOffDuration := (time.Minute * time.Duration(math.Exp2(float64(maxBackOffCount)))).Milliseconds()
2623

2724
assert.LessOrEqual(t, calculateBackoff(maxBackOffCount-1).Milliseconds(), maxBackOffDuration)

0 commit comments

Comments
 (0)