Skip to content

Commit bab013f

Browse files
committed
feat: add golangci-lint check
Signed-off-by: Abirdcfly <[email protected]>
1 parent db38e85 commit bab013f

File tree

119 files changed

+534
-740
lines changed

Some content is hidden

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

119 files changed

+534
-740
lines changed

.github/workflows/golangci.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
12+
jobs:
13+
golangci:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-go@v3
19+
with:
20+
go-version-file: 'go.mod'
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v3
23+
with:
24+
version: latest

.golangci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
run:
2+
timeout: 30m
3+
modules-download-mode: "mod"
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
# linters maintained by golang.org
9+
- gofmt
10+
- goimports
11+
- govet
12+
# linters enabled by default
13+
# - errcheck
14+
# - ineffassign
15+
- gosimple
16+
# - govet
17+
# - staticcheck
18+
# - typecheck
19+
# - unused
20+
# custom
21+
# please keep this alphabetized
22+
23+
issues:
24+
max-same-issues: 0
25+
26+
linters-settings: # please keep this alphabetized
27+
gosimple:
28+
checks: [
29+
"all",
30+
"-S1034"
31+
]
32+
33+
severity:
34+
default-severity: error

api/v1beta1/ibpca.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ func (s *IBPCASpec) HSMSet() bool {
200200
}
201201

202202
func (s *IBPCASpec) DomainSet() bool {
203-
if s.Domain != "" {
204-
return true
205-
}
206203

207-
return false
204+
return s.Domain != ""
208205
}
209206

210207
func (s *IBPCASpec) CAResourcesSet() bool {
@@ -240,10 +237,8 @@ func (s *IBPCASpec) GetCAConfigOverride() (CAConfig, error) {
240237
}
241238

242239
func (c *IBPCAStatus) HasType() bool {
243-
if c.CRStatus.Type != "" {
244-
return true
245-
}
246-
return false
240+
241+
return c.CRStatus.Type != ""
247242
}
248243

249244
// Override will look at requested images and use those to override default image

api/v1beta1/ibpconsole.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc
8080

8181
if len(requestedVersions.CA) != 0 {
8282
CAVersions := map[string]VersionCA{}
83-
for key, _ := range requestedVersions.CA {
83+
for key := range requestedVersions.CA {
8484
var caConfig VersionCA
8585
requestedCAVersion := requestedVersions.CA[key]
8686
caConfig.Image.Override(&requestedCAVersion.Image, registryURL, arch)
@@ -93,7 +93,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc
9393

9494
if len(requestedVersions.Peer) != 0 {
9595
PeerVersions := map[string]VersionPeer{}
96-
for key, _ := range requestedVersions.Peer {
96+
for key := range requestedVersions.Peer {
9797
var peerConfig VersionPeer
9898
requestedPeerVersion := requestedVersions.Peer[key]
9999
peerConfig.Image.Override(&requestedPeerVersion.Image, registryURL, arch)
@@ -106,7 +106,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc
106106

107107
if len(requestedVersions.Orderer) != 0 {
108108
OrdererVersions := map[string]VersionOrderer{}
109-
for key, _ := range requestedVersions.Orderer {
109+
for key := range requestedVersions.Orderer {
110110
var ordererConfig VersionOrderer
111111
requestedOrdererVersion := requestedVersions.Orderer[key]
112112
ordererConfig.Image.Override(&requestedOrdererVersion.Image, registryURL, arch)
@@ -123,8 +123,6 @@ func init() {
123123
}
124124

125125
func (c *IBPConsoleStatus) HasType() bool {
126-
if c.CRStatus.Type != "" {
127-
return true
128-
}
129-
return false
126+
127+
return c.CRStatus.Type != ""
130128
}

api/v1beta1/ibporderer.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,8 @@ func (s *IBPOrdererSpec) HSMSet() bool {
228228
}
229229

230230
func (s *IBPOrdererSpec) DomainSet() bool {
231-
if s.Domain != "" {
232-
return true
233-
}
234231

235-
return false
232+
return s.Domain != ""
236233
}
237234

238235
func (s *IBPOrdererSpec) IsPrecreateOrderer() bool {
@@ -277,8 +274,6 @@ func init() {
277274
}
278275

279276
func (o *IBPOrdererStatus) HasType() bool {
280-
if o.CRStatus.Type != "" {
281-
return true
282-
}
283-
return false
277+
278+
return o.CRStatus.Type != ""
284279
}

api/v1beta1/ibppeer.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ func (s *IBPPeer) IsHSMEnabled() bool {
137137
}
138138

139139
func (s *IBPPeer) UsingCouchDB() bool {
140-
if strings.ToLower(s.Spec.StateDb) == "couchdb" {
141-
return true
142-
}
143140

144-
return false
141+
return strings.ToLower(s.Spec.StateDb) == "couchdb"
145142
}
146143

147144
func (s *IBPPeer) GetPullSecrets() []corev1.LocalObjectReference {
@@ -252,19 +249,13 @@ func (s *IBPPeerSpec) HSMSet() bool {
252249
}
253250

254251
func (s *IBPPeerSpec) DomainSet() bool {
255-
if s.Domain != "" {
256-
return true
257-
}
258252

259-
return false
253+
return s.Domain != ""
260254
}
261255

262256
func (s *IBPPeerSpec) UsingLevelDB() bool {
263-
if strings.ToLower(s.StateDb) == "leveldb" {
264-
return true
265-
}
266257

267-
return false
258+
return strings.ToLower(s.StateDb) == "leveldb"
268259
}
269260

270261
func (s *IBPPeerSpec) GetNumSecondsWarningPeriod() int64 {
@@ -277,10 +268,8 @@ func (s *IBPPeerSpec) GetNumSecondsWarningPeriod() int64 {
277268
}
278269

279270
func (p *IBPPeerStatus) HasType() bool {
280-
if p.CRStatus.Type != "" {
281-
return true
282-
}
283-
return false
271+
272+
return p.CRStatus.Type != ""
284273
}
285274

286275
func (i *PeerImages) Override(requested *PeerImages, registryURL string, arch string) {

controllers/common/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ type Client interface {
3939
List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
4040
}
4141

42-
// 1. Only one existing instance (of the same type as 'instance') should have
43-
// the name 'instance.GetName()'; if more than one is present, return error
44-
// 2. If any instance of a different type share the same name, return error
42+
// 1. Only one existing instance (of the same type as 'instance') should have
43+
// the name 'instance.GetName()'; if more than one is present, return error
44+
// 2. If any instance of a different type share the same name, return error
4545
func ValidateCRName(k8sclient Client, name, namespace, kind string) error {
4646
listOptions := &client.ListOptions{
4747
Namespace: namespace,

controllers/ibpca/ibpca_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,11 @@ func (r *ReconcileIBPCA) UpdateFunc(e event.UpdateEvent) bool {
656656
}
657657
}
658658

659-
if newCA.Spec.Action.Restart == true {
659+
if newCA.Spec.Action.Restart {
660660
update.restartNeeded = true
661661
}
662662

663-
if newCA.Spec.Action.Renew.TLSCert == true {
663+
if newCA.Spec.Action.Renew.TLSCert {
664664
update.renewTLSCert = true
665665
}
666666

controllers/ibpconsole/ibpconsole_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func (r *ReconcileIBPConsole) UpdateFunc(e event.UpdateEvent) bool {
401401
log.Info(fmt.Sprintf("Spec update detected on IBPConsole custom resource: %s", oldConsole.Name))
402402
r.update.specUpdated = true
403403

404-
if newConsole.Spec.Action.Restart == true {
404+
if newConsole.Spec.Action.Restart {
405405
r.update.restartNeeded = true
406406
}
407407

controllers/ibppeer/ibppeer_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (r *ReconcileIBPPeer) UpdateFunc(e event.UpdateEvent) bool {
643643

644644
update.mspUpdated = commoncontroller.MSPInfoUpdateDetected(oldPeer.Spec.Secret, newPeer.Spec.Secret)
645645

646-
if newPeer.Spec.Action.Restart == true {
646+
if newPeer.Spec.Action.Restart {
647647
update.restartNeeded = true
648648
}
649649

@@ -683,15 +683,15 @@ func (r *ReconcileIBPPeer) UpdateFunc(e event.UpdateEvent) bool {
683683
update.migrateToV24 = true
684684
}
685685

686-
if newPeer.Spec.Action.UpgradeDBs == true {
686+
if newPeer.Spec.Action.UpgradeDBs {
687687
update.upgradedbs = true
688688
}
689689

690-
if newPeer.Spec.Action.Enroll.Ecert == true {
690+
if newPeer.Spec.Action.Enroll.Ecert {
691691
update.ecertEnroll = true
692692
}
693693

694-
if newPeer.Spec.Action.Enroll.TLSCert == true {
694+
if newPeer.Spec.Action.Enroll.TLSCert {
695695
update.tlscertEnroll = true
696696
}
697697

0 commit comments

Comments
 (0)