Skip to content

Commit 159c13f

Browse files
authored
Merge pull request #2517 from tech-geek29/enable-additional-linters
🌱 Add addtional linters
2 parents e3916f2 + 31bb3d8 commit 159c13f

File tree

238 files changed

+1034
-1049
lines changed

Some content is hidden

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

238 files changed

+1034
-1049
lines changed

.golangci.yml

+123-42
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- asciicheck
5+
- bodyclose
6+
- deadcode
7+
- depguard
8+
- dogsled
9+
- errcheck
10+
- exportloopref
11+
- goconst
12+
- gocritic
13+
- gocyclo
14+
- godot
15+
- gofmt
16+
- goheader
17+
- goimports
18+
- goprintffuncname
19+
- gosec
20+
- gosimple
21+
- govet
22+
- ifshort
23+
- importas
24+
- ineffassign
25+
- maligned
26+
- misspell
27+
- nakedret
28+
- nilerr
29+
- noctx
30+
- nolintlint
31+
- prealloc
32+
- revive
33+
- rowserrcheck
34+
- staticcheck
35+
- structcheck
36+
- stylecheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- varcheck
41+
- whitespace
42+
143
linters-settings:
244
# Restrict revive to exported.
345
revive:
@@ -7,48 +49,43 @@ linters-settings:
749
rules:
850
- name: exported
951
severity: warning
10-
linters:
11-
disable-all: true
12-
enable:
13-
- asciicheck
14-
- bodyclose
15-
- deadcode
16-
- depguard
17-
- dogsled
18-
- goconst
19-
- gocyclo
20-
- gofmt
21-
- goheader
22-
- goimports
23-
- goprintffuncname
24-
- gosimple
25-
- govet
26-
- ineffassign
27-
- maligned
28-
- misspell
29-
- nakedret
30-
- noctx
31-
- nolintlint
32-
- rowserrcheck
33-
- staticcheck
34-
- structcheck
35-
- typecheck
36-
- unconvert
37-
- unparam
38-
- unused
39-
- varcheck
40-
- revive
41-
# Run with --fast=false for more extensive checks
42-
fast: true
52+
ifshort:
53+
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
54+
max-decl-chars: 50
55+
importas:
56+
no-unaliased: true
57+
alias:
58+
# Kubernetes
59+
- pkg: k8s.io/api/core/v1
60+
alias: corev1
61+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
62+
alias: apiextensionsv1
63+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
64+
alias: metav1
65+
- pkg: k8s.io/apimachinery/pkg/api/errors
66+
alias: apierrors
67+
- pkg: k8s.io/apimachinery/pkg/util/errors
68+
alias: kerrors
69+
# Controller Runtime
70+
- pkg: sigs.k8s.io/controller-runtime
71+
alias: ctrl
72+
staticcheck:
73+
go: "1.16"
74+
stylecheck:
75+
go: "1.16"
4376
issues:
4477
max-same-issues: 0
45-
max-per-linter: 0
46-
# List of regexps of issue texts to exclude, empty list by default.
78+
max-issues-per-linter: 0
79+
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
80+
# changes in PRs and avoid nitpicking.
4781
exclude-use-default: false
82+
# List of regexps of issue texts to exclude, empty list by default.
4883
exclude:
49-
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
50-
- "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
84+
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
85+
- "exported: exported (const|function|method|type|var) (.+) should have comment or be unexported"
5186
- "exported: (func|type) name will be used as (.+) by other packages, and that stutters; consider calling this (.+)"
87+
- (G104|G107|G404|G505|ST1000)
88+
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
5289
# Exclude noctx error for calling http.Get directly.
5390
# See https://pkg.go.dev/github.com/sonatard/noctx#readme-how-to-fix for reasons it breaks and ways to fix it.
5491
# This exclusion should be removed if the decision is made to fix the error.
@@ -67,11 +104,55 @@ issues:
67104
- revive
68105
text: exported (method|function|type|const) (.+) should have comment or be unexported
69106
path: .*test/(providers|framework|e2e).*.go
107+
- linters:
108+
- errcheck
109+
text: Error return value is not checked
110+
path: _test\.go
111+
- linters:
112+
- errcheck
113+
text: Error return value of (.+) is not checked
114+
path: _test\.go
115+
- linters:
116+
- gosec
117+
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
118+
- linters:
119+
- godot
120+
text: "Comment should end in a period"
121+
path: "(.*)/(v1alpha3|v1alpha4|v1alpha1)/(.*)types.go"
122+
- linters:
123+
- errcheck
124+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
125+
# With Go 1.16, the new embed directive can be used with an un-named import,
126+
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
127+
# This directive allows the embed package to be imported with an underscore everywhere.
128+
- linters:
129+
- revive
130+
source: _ "embed"
131+
# This directive allows the variable in defaults.go files to have underscore
132+
- linters:
133+
- revive
134+
text: "var-naming: don't use underscores in Go names; func (.+) should be (.+)"
135+
path: .*/defaults.go
136+
# Disable unparam "always receives" which might not be really
137+
# useful when building libraries.
138+
- linters:
139+
- unparam
140+
text: always receives
141+
- linters:
142+
- unparam
143+
text: (.+) - (`t`|`g`) is unused
144+
- path: _test\.go
145+
text: cyclomatic complexity
146+
# Append should be able to assign to a different var/slice.
147+
- linters:
148+
- gocritic
149+
text: "appendAssign: append result not assigned to the same slice"
150+
70151
run:
71152
timeout: 10m
72-
tests: false
73153
skip-files:
74-
- "zz_generated.*\\.go$"
75-
# Skip autogenerated doc.go files
76-
- "doc\\.go"
77-
- "mock\\.go"
154+
- "zz_generated.*\\.go$"
155+
- ".*conversion.*\\.go$"
156+
skip-dirs:
157+
- third_party
158+
allow-parallel-runners: true

api/v1alpha3/awscluster_types.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
// removing it from the apiserver.
2727
ClusterFinalizer = "awscluster.infrastructure.cluster.x-k8s.io"
2828

29-
// AWSClusterControllerIdentityName is the name of the AWSClusterControllerIdentity singleton
29+
// AWSClusterControllerIdentityName is the name of the AWSClusterControllerIdentity singleton.
3030
AWSClusterControllerIdentityName = "default"
3131
)
3232

@@ -95,13 +95,13 @@ type AWSClusterSpec struct {
9595
type AWSIdentityKind string
9696

9797
var (
98-
// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity
98+
// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity.
9999
ControllerIdentityKind = AWSIdentityKind("AWSClusterControllerIdentity")
100100

101-
// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity
101+
// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity.
102102
ClusterRoleIdentityKind = AWSIdentityKind("AWSClusterRoleIdentity")
103103

104-
// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity
104+
// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity.
105105
ClusterStaticIdentityKind = AWSIdentityKind("AWSClusterStaticIdentity")
106106
)
107107

@@ -144,7 +144,7 @@ type Bastion struct {
144144
AMI string `json:"ami,omitempty"`
145145
}
146146

147-
// AWSLoadBalancerSpec defines the desired state of an AWS load balancer
147+
// AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
148148
type AWSLoadBalancerSpec struct {
149149
// Scheme sets the scheme of the load balancer (defaults to Internet-facing)
150150
// +kubebuilder:default=Internet-facing
@@ -167,7 +167,7 @@ type AWSLoadBalancerSpec struct {
167167
// +optional
168168
Subnets []string `json:"subnets,omitempty"`
169169

170-
// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs.
170+
// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
171171
// This is optional - if not provided new security groups will be created for the load balancer
172172
// +optional
173173
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
@@ -203,7 +203,7 @@ type AWSCluster struct {
203203

204204
// +kubebuilder:object:root=true
205205

206-
// AWSClusterList contains a list of AWSCluster
206+
// AWSClusterList contains a list of AWSCluster.
207207
type AWSClusterList struct {
208208
metav1.TypeMeta `json:",inline"`
209209
metav1.ListMeta `json:"metadata,omitempty"`

api/v1alpha3/awsidentity_types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type AWSClusterStaticIdentity struct {
8585

8686
// +kubebuilder:object:root=true
8787

88-
// AWSClusterStaticIdentityList contains a list of AWSClusterStaticIdentity
88+
// AWSClusterStaticIdentityList contains a list of AWSClusterStaticIdentity.
8989
type AWSClusterStaticIdentityList struct {
9090
metav1.TypeMeta `json:",inline"`
9191
metav1.ListMeta `json:"metadata,omitempty"`
@@ -118,7 +118,7 @@ type AWSClusterRoleIdentity struct {
118118

119119
// +kubebuilder:object:root=true
120120

121-
// AWSClusterRoleIdentityList contains a list of AWSClusterRoleIdentity
121+
// AWSClusterRoleIdentityList contains a list of AWSClusterRoleIdentity.
122122
type AWSClusterRoleIdentityList struct {
123123
metav1.TypeMeta `json:",inline"`
124124
metav1.ListMeta `json:"metadata,omitempty"`
@@ -161,7 +161,7 @@ type AWSClusterControllerIdentity struct {
161161

162162
// +kubebuilder:object:root=true
163163

164-
// AWSClusterControllerIdentityList contains a list of AWSClusterControllerIdentity
164+
// AWSClusterControllerIdentityList contains a list of AWSClusterControllerIdentity.
165165
type AWSClusterControllerIdentityList struct {
166166
metav1.TypeMeta `json:",inline"`
167167
metav1.ListMeta `json:"metadata,omitempty"`

api/v1alpha3/awsmachine_types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ const (
3232
type SecretBackend string
3333

3434
var (
35-
// SecretBackendSSMParameterStore defines AWS Systems Manager Parameter Store as the secret backend
35+
// SecretBackendSSMParameterStore defines AWS Systems Manager Parameter Store as the secret backend.
3636
SecretBackendSSMParameterStore = SecretBackend("ssm-parameter-store")
3737

38-
// SecretBackendSecretsManager defines AWS Secrets Manager as the secret backend
38+
// SecretBackendSecretsManager defines AWS Secrets Manager as the secret backend.
3939
SecretBackendSecretsManager = SecretBackend("secrets-manager")
4040
)
4141

@@ -267,7 +267,7 @@ func (r *AWSMachine) SetConditions(conditions clusterv1.Conditions) {
267267

268268
// +kubebuilder:object:root=true
269269

270-
// AWSMachineList contains a list of AWSMachine
270+
// AWSMachineList contains a list of AWSMachine.
271271
type AWSMachineList struct {
272272
metav1.TypeMeta `json:",inline"`
273273
metav1.ListMeta `json:"metadata,omitempty"`

api/v1alpha3/awsmachinetemplate_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type AWSMachineTemplate struct {
3838

3939
// +kubebuilder:object:root=true
4040

41-
// AWSMachineTemplateList contains a list of AWSMachineTemplate
41+
// AWSMachineTemplateList contains a list of AWSMachineTemplate.
4242
type AWSMachineTemplateList struct {
4343
metav1.TypeMeta `json:",inline"`
4444
metav1.ListMeta `json:"metadata,omitempty"`

api/v1alpha3/conditions_consts.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@ const (
3131
// PrincipalUsageUnauthorizedReason used when AWSCluster namespace is not in the identity's allowed namespaces list.
3232
PrincipalUsageUnauthorizedReason = "PrincipalUsageUnauthorized"
3333
// SourcePrincipalUsageUnauthorizedReason used when AWSCluster is not in the intersection of source identity allowed namespaces
34-
// and allowed namespaces of the identities that source identity depends to
34+
// and allowed namespaces of the identities that source identity depends to.
3535
SourcePrincipalUsageUnauthorizedReason = "SourcePrincipalUsageUnauthorized"
3636
)
3737

3838
const (
39-
// VpcReadyCondition reports on the successful reconciliation of a VPC
39+
// VpcReadyCondition reports on the successful reconciliation of a VPC.
4040
VpcReadyCondition clusterv1.ConditionType = "VpcReady"
4141
// VpcCreationStartedReason used when attempting to create a VPC for a managed cluster.
4242
// Will not be applied to unmanaged clusters.
4343
VpcCreationStartedReason = "VpcCreationStarted"
44-
// VpcReconciliationFailedReason used when errors occur during VPC reconciliation
44+
// VpcReconciliationFailedReason used when errors occur during VPC reconciliation.
4545
VpcReconciliationFailedReason = "VpcReconciliationFailed"
4646
)
4747

4848
const (
4949
// SubnetsReadyCondition reports on the successful reconciliation of subnets.
5050
SubnetsReadyCondition clusterv1.ConditionType = "SubnetsReady"
51-
// SubnetsReconciliationFailedReason used to report failures while reconciling subnets
51+
// SubnetsReconciliationFailedReason used to report failures while reconciling subnets.
5252
SubnetsReconciliationFailedReason = "SubnetsReconciliationFailed"
5353
)
5454

5555
const (
5656
// InternetGatewayReadyCondition reports on the successful reconciliation of internet gateways.
5757
// Only applicable to managed clusters.
5858
InternetGatewayReadyCondition clusterv1.ConditionType = "InternetGatewayReady"
59-
// InternetGatewayFailedReason used when errors occur during internet gateway reconciliation
59+
// InternetGatewayFailedReason used when errors occur during internet gateway reconciliation.
6060
InternetGatewayFailedReason = "InternetGatewayFailed"
6161
)
6262

@@ -95,22 +95,22 @@ const (
9595

9696
const (
9797
// BastionHostReadyCondition reports whether a bastion host is ready. Depending on the configuration, a cluster
98-
// may not require a bastion host and this condition will be skipped
98+
// may not require a bastion host and this condition will be skipped.
9999
BastionHostReadyCondition clusterv1.ConditionType = "BastionHostReady"
100-
// BastionCreationStartedReason used when creating a new bastion host
100+
// BastionCreationStartedReason used when creating a new bastion host.
101101
BastionCreationStartedReason = "BastionCreationStarted"
102-
// BastionHostFailedReason used when an error occurs during the creation of a bastion host
102+
// BastionHostFailedReason used when an error occurs during the creation of a bastion host.
103103
BastionHostFailedReason = "BastionHostFailed"
104104
)
105105

106106
const (
107107
// LoadBalancerReadyCondition reports on whether a control plane load balancer was successfully reconciled.
108108
LoadBalancerReadyCondition clusterv1.ConditionType = "LoadBalancerReady"
109-
// WaitForDNSNameReason used while waiting for a DNS name for the API server to be populated
109+
// WaitForDNSNameReason used while waiting for a DNS name for the API server to be populated.
110110
WaitForDNSNameReason = "WaitForDNSName"
111-
// WaitForDNSNameResolveReason used while waiting for DNS name to resolve
111+
// WaitForDNSNameResolveReason used while waiting for DNS name to resolve.
112112
WaitForDNSNameResolveReason = "WaitForDNSNameResolve"
113-
// LoadBalancerFailedReason used when an error occurs during load balancer reconciliation
113+
// LoadBalancerFailedReason used when an error occurs during load balancer reconciliation.
114114
LoadBalancerFailedReason = "LoadBalancerFailed"
115115
)
116116

@@ -140,7 +140,7 @@ const (
140140
// SecurityGroupsReadyCondition indicates the security groups are up to date on the AWSMachine.
141141
SecurityGroupsReadyCondition clusterv1.ConditionType = "SecurityGroupsReady"
142142

143-
// SecurityGroupsFailedReason used when the security groups could not be synced
143+
// SecurityGroupsFailedReason used when the security groups could not be synced.
144144
SecurityGroupsFailedReason = "SecurityGroupsSyncFailed"
145145
)
146146

@@ -150,8 +150,8 @@ const (
150150
// Note this is only applicable to control plane machines.
151151
ELBAttachedCondition clusterv1.ConditionType = "ELBAttached"
152152

153-
// ELBAttachFailedReason used when a control plane node fails to attach to the ELB
153+
// ELBAttachFailedReason used when a control plane node fails to attach to the ELB.
154154
ELBAttachFailedReason = "ELBAttachFailed"
155-
// ELBDetachFailedReason used when a control plane node fails to detach from an ELB
155+
// ELBDetachFailedReason used when a control plane node fails to detach from an ELB.
156156
ELBDetachFailedReason = "ELBDetachFailed"
157157
)

0 commit comments

Comments
 (0)