Skip to content

Commit 649ebd4

Browse files
authored
ci: Improve CI linting (#791)
* ci: enable more linters Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: diable few checks for temporary Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: read permission to ci Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: try removing cache Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: diable ifelse linter for temp Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * syle: run gofumpt Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * sytle: run gci Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: prevent misspell Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: run go import Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * style: fix style errors Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * style: fix trailing lines Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * remove unwanted conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * remove gci from generated file Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * style: remove init check Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix: type conversion Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix: remove context Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: update configuration file Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: skip generated files Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * ci: remove disabled lintesr Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> --------- Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
1 parent 4e66ea2 commit 649ebd4

37 files changed

+127
-176
lines changed

.github/workflows/operator-ci.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- master
99

10+
permissions:
11+
contents: read
12+
1013
env:
1114
GOLANG_VERSION: 1.21
1215
APPLICATION_NAME: redis-operator
@@ -44,15 +47,7 @@ jobs:
4447
uses: actions/setup-go@v4
4548
with:
4649
go-version: ${{ env.GOLANG_VERSION }}
47-
48-
- name: Download Go modules
49-
run: go mod download
50-
51-
- name: Check disk space
52-
run: df -h
53-
54-
- name: List Go module cache
55-
run: ls -la $(go env GOPATH)/pkg/mod
50+
cache: false
5651

5752
- name: Run GolangCI-Lint
5853
uses: golangci/golangci-lint-action@v3

.golangci.yml

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,59 @@ linters-settings:
22
govet:
33
check-shadowing: true
44
golint:
5-
min-confidence: 0.8
5+
min-confidence: 0.8
66
gofmt:
77
simplify: true
88

99
linters:
10-
disable:
11-
- errcheck
12-
- tagliatelle
10+
enable:
11+
- asasalint
12+
- asciicheck
13+
- bidichk
14+
- bodyclose
15+
- containedctx
16+
- decorder
17+
- dogsled
18+
- durationcheck
19+
- errcheck
20+
- errname
21+
- exportloopref
22+
- gci
23+
- gochecknoinits
24+
- gofmt
25+
- gofumpt
26+
- goprintffuncname
27+
- gosec
28+
- gosimple
29+
- govet
30+
- grouper
31+
- importas
1332
- ineffassign
33+
- makezero
34+
- misspell
35+
- noctx
36+
- nolintlint
37+
- nosprintfhostport
1438
- staticcheck
15-
16-
# Exclude the files that are causing the errors
17-
issues:
18-
exclude-rules:
19-
- path: _test\.go # Ignore test files for linting
20-
linters:
21-
- gocyclo
22-
- errcheck
23-
- dupl
24-
- gosec
25-
run:
26-
timeout: 5m
27-
go-version: "1.21"
28-
output:
29-
format: colored-line-number
30-
sort-results: true
39+
- tenv
40+
- thelper
41+
- tparallel
42+
- typecheck
43+
- unconvert
44+
- unused
45+
- wastedassign
46+
- whitespace
3147

32-
test: false
33-
# Exclude third-party packages and go.mod from the lint checks
34-
exclude: |
35-
'(^vendor/.*|.*_test\.go|go\.mod|.*validatingwebhookconfiguration\.go|.*mutatingwebhookconfiguration\.go)'
48+
run:
49+
timeout: 15m
50+
go: "1.21"
51+
tests: true
52+
show-stats: true
3653
skip-files:
37-
- '^.*validatingwebhookconfiguration\.go$'
38-
- controllers/suite_test.go
39-
skip-dirs:
40-
- k8s.io/client-go
41-
- github.com/banzaicloud/k8s-objectmatcher
42-
- github.com/go-logr/logr
43-
- github.com/redis/go-redis
44-
- github.com/onsi/ginkgo
45-
- github.com/onsi/gomega
46-
- github.com/pkg/errors
47-
- k8s.io/api
48-
- k8s.io/apimachinery
49-
- sigs.k8s.io/controller-runtime
50-
- golang.org/x/sys
51-
- vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
54+
- ".+\\.generated.go"
55+
56+
output:
57+
format: colored-line-number
58+
sort-results: true
59+
print-linter-name: true
60+
print-issued-lines: true

api/v1beta1/redis_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type RedisSpec struct {
4545
}
4646

4747
// RedisStatus defines the observed state of Redis
48-
type RedisStatus struct {
49-
}
48+
type RedisStatus struct{}
5049

5150
// +kubebuilder:object:root=true
5251
// +kubebuilder:subresource:status
@@ -69,6 +68,7 @@ type RedisList struct {
6968
Items []Redis `json:"items"`
7069
}
7170

71+
// //nolint:gochecknoinits
7272
func init() {
7373
SchemeBuilder.Register(&Redis{}, &RedisList{})
7474
}

api/v1beta1/rediscluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ type RedisFollower struct {
6464
}
6565

6666
// RedisClusterStatus defines the observed state of RedisCluster
67-
type RedisClusterStatus struct {
68-
}
67+
type RedisClusterStatus struct{}
6968

7069
// +kubebuilder:object:root=true
7170
// +kubebuilder:subresource:status
@@ -91,6 +90,7 @@ type RedisClusterList struct {
9190
Items []RedisCluster `json:"items"`
9291
}
9392

93+
//nolint:gochecknoinits
9494
func init() {
9595
SchemeBuilder.Register(&RedisCluster{}, &RedisClusterList{})
9696
}

api/v1beta1/redisreplication_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 {
3131
}
3232

3333
// RedisStatus defines the observed state of Redis
34-
type RedisReplicationStatus struct {
35-
}
34+
type RedisReplicationStatus struct{}
3635

3736
// +kubebuilder:object:root=true
3837
// +kubebuilder:subresource:status
@@ -55,6 +54,7 @@ type RedisReplicationList struct {
5554
Items []RedisReplication `json:"items"`
5655
}
5756

57+
//nolint:gochecknoinits
5858
func init() {
5959
SchemeBuilder.Register(&RedisReplication{}, &RedisReplicationList{})
6060
}

api/v1beta1/redissentinel_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ type RedisSentinelConfig struct {
3737
common.RedisSentinelConfig `json:",inline"`
3838
}
3939

40-
type RedisSentinelStatus struct {
41-
}
40+
type RedisSentinelStatus struct{}
4241

4342
// +kubebuilder:object:root=true
4443
// +kubebuilder:subresource:status
@@ -61,6 +60,7 @@ type RedisSentinelList struct {
6160
Items []RedisSentinel `json:"items"`
6261
}
6362

63+
//nolint:gochecknoinits
6464
func init() {
6565
SchemeBuilder.Register(&RedisSentinel{}, &RedisSentinelList{})
6666
}

api/v1beta2/redis_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ type RedisSpec struct {
5050
}
5151

5252
// RedisStatus defines the observed state of Redis
53-
type RedisStatus struct {
54-
}
53+
type RedisStatus struct{}
5554

5655
// +kubebuilder:object:root=true
5756
// +kubebuilder:subresource:status
@@ -75,6 +74,7 @@ type RedisList struct {
7574
Items []Redis `json:"items"`
7675
}
7776

77+
//nolint:gochecknoinits
7878
func init() {
7979
SchemeBuilder.Register(&Redis{}, &RedisList{})
8080
}

api/v1beta2/rediscluster_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type RedisClusterList struct {
113113
Items []RedisCluster `json:"items"`
114114
}
115115

116+
//nolint:gochecknoinits
116117
func init() {
117118
SchemeBuilder.Register(&RedisCluster{}, &RedisClusterList{})
118119
}

api/v1beta2/redisreplication_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 {
3636
}
3737

3838
// RedisStatus defines the observed state of Redis
39-
type RedisReplicationStatus struct {
40-
}
39+
type RedisReplicationStatus struct{}
4140

4241
// +kubebuilder:object:root=true
4342
// +kubebuilder:subresource:status
@@ -61,6 +60,7 @@ type RedisReplicationList struct {
6160
Items []RedisReplication `json:"items"`
6261
}
6362

63+
//nolint:gochecknoinits
6464
func init() {
6565
SchemeBuilder.Register(&RedisReplication{}, &RedisReplicationList{})
6666
}

api/v1beta2/redissentinel_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type RedisSentinelConfig struct {
4141
common.RedisSentinelConfig `json:",inline"`
4242
}
4343

44-
type RedisSentinelStatus struct {
45-
}
44+
type RedisSentinelStatus struct{}
4645

4746
// +kubebuilder:object:root=true
4847
// +kubebuilder:subresource:status
@@ -66,6 +65,7 @@ type RedisSentinelList struct {
6665
Items []RedisSentinel `json:"items"`
6766
}
6867

68+
//nolint:gochecknoinits
6969
func init() {
7070
SchemeBuilder.Register(&RedisSentinel{}, &RedisSentinelList{})
7171
}

0 commit comments

Comments
 (0)