Skip to content

Commit afc1f3b

Browse files
committed
Enable more linters
1 parent 547224c commit afc1f3b

File tree

8 files changed

+47
-51
lines changed

8 files changed

+47
-51
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ jobs:
1919
lint:
2020
name: Lint
2121
runs-on: ubuntu-22.04
22-
permissions:
23-
contents: read
24-
pull-requests: read # for golangci-lint-action
2522
steps:
2623
- name: Checkout Repository
2724
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -33,8 +30,6 @@ jobs:
3330

3431
- name: Lint Code
3532
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
36-
with:
37-
only-new-issues: true
3833

3934
actionlint:
4035
name: Actionlint

.golangci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ linters-settings:
2828
- name: unused-parameter
2929
- name: var-declaration
3030
- name: var-naming
31+
govet:
32+
check-shadowing: true
33+
enable-all: true
3134

3235
linters:
33-
enable:
36+
enable:
3437
- asciicheck
38+
- bidichk
39+
- dupword
3540
- errcheck
3641
- errorlint
3742
- gofmt
@@ -45,15 +50,21 @@ linters:
4550
- misspell
4651
- nilerr
4752
- noctx
53+
- perfsprint
4854
- predeclared
55+
- reassign
4956
- revive
5057
- staticcheck
58+
- tagalign
59+
- tparallel
5160
- typecheck
5261
- unconvert
5362
- unparam
5463
- unused
64+
- usestdlibvars
5565
- wastedassign
56-
disable-all: true
66+
- whitespace
67+
disable-all: true
5768
issues:
5869
max-issues-per-linter: 0
5970
max-same-issues: 0

.pre-commit-config.yaml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,10 @@ repos:
2626
- id: fix-byte-order-marker
2727
- id: detect-private-key
2828

29-
- repo: local
30-
hooks:
31-
- id: golang-diff
32-
name: create-go-diff
33-
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
34-
language: system
35-
types: [go]
36-
pass_filenames: false
37-
3829
- repo: https://github.com/golangci/golangci-lint
3930
rev: v1.56.1
4031
hooks:
41-
- id: golangci-lint
42-
args: [--new-from-patch=/tmp/diff.patch]
32+
- id: golangci-lint-full
4333

4434
- repo: https://github.com/asottile/pyupgrade
4535
rev: v3.15.0
@@ -59,7 +49,7 @@ repos:
5949
- repo: https://github.com/DavidAnson/markdownlint-cli2
6050
rev: v0.12.1
6151
hooks:
62-
- id: markdownlint-cli2
52+
- id: markdownlint-cli2
6353

6454
ci:
65-
skip: [golang-diff, golangci-lint]
55+
skip: [golangci-lint-full]

cmd/sync/aws.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78
"reflect"
@@ -34,18 +35,18 @@ func NewAWSClient(data []byte) (*AWSClient, error) {
3435
if cfg.Region == "self" {
3536
httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second}
3637

37-
conf, err := config.LoadDefaultConfig(context.TODO())
38-
if err != nil {
39-
return nil, err
38+
conf, loadErr := config.LoadDefaultConfig(context.TODO())
39+
if loadErr != nil {
40+
return nil, loadErr
4041
}
4142

4243
client := imds.NewFromConfig(conf, func(o *imds.Options) {
4344
o.HTTPClient = httpClient
4445
})
4546

46-
response, err := client.GetRegion(context.TODO(), &imds.GetRegionInput{})
47-
if err != nil {
48-
return nil, fmt.Errorf("unable to retrieve region from ec2metadata: %w", err)
47+
response, regionErr := client.GetRegion(context.TODO(), &imds.GetRegionInput{})
48+
if regionErr != nil {
49+
return nil, fmt.Errorf("unable to retrieve region from ec2metadata: %w", regionErr)
4950
}
5051
cfg.Region = response.Region
5152
}
@@ -197,13 +198,13 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s
197198
const maxItems = 50
198199
var result []string
199200
keys := reflect.ValueOf(insIDtoIP).MapKeys()
200-
instanceIds := make([]string, len(keys))
201+
instanceIDs := make([]string, len(keys))
201202

202203
for i := 0; i < len(keys); i++ {
203-
instanceIds[i] = keys[i].String()
204+
instanceIDs[i] = keys[i].String()
204205
}
205206

206-
batches := prepareBatches(maxItems, instanceIds)
207+
batches := prepareBatches(maxItems, instanceIDs)
207208
for _, batch := range batches {
208209
params := &autoscaling.DescribeAutoScalingInstancesInput{
209210
InstanceIds: batch,
@@ -249,13 +250,13 @@ type awsConfig struct {
249250
type awsUpstream struct {
250251
Name string
251252
AutoscalingGroup string `yaml:"autoscaling_group"`
252-
Port int
253253
Kind string
254-
MaxConns int `yaml:"max_conns"`
255-
MaxFails int `yaml:"max_fails"`
256254
FailTimeout string `yaml:"fail_timeout"`
257255
SlowStart string `yaml:"slow_start"`
258-
InService bool `yaml:"in_service"`
256+
Port int
257+
MaxConns int `yaml:"max_conns"`
258+
MaxFails int `yaml:"max_fails"`
259+
InService bool `yaml:"in_service"`
259260
}
260261

261262
func validateAWSConfig(cfg *awsConfig) error {
@@ -264,12 +265,12 @@ func validateAWSConfig(cfg *awsConfig) error {
264265
}
265266

266267
if len(cfg.Upstreams) == 0 {
267-
return fmt.Errorf("there are no upstreams found in the config file")
268+
return errors.New("there are no upstreams found in the config file")
268269
}
269270

270271
for _, ups := range cfg.Upstreams {
271272
if ups.Name == "" {
272-
return fmt.Errorf(upstreamNameErrorMsg)
273+
return errors.New(upstreamNameErrorMsg)
273274
}
274275
if ups.AutoscalingGroup == "" {
275276
return fmt.Errorf(upstreamErrorMsgFormat, "autoscaling_group", ups.Name)

cmd/sync/aws_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,11 @@ func areEqualUpstreamsAWS(u1 awsUpstream, u2 Upstream) bool {
167167
func TestPrepareBatches(t *testing.T) {
168168
const maxItems = 3
169169
ids := []string{"i-394ujfs", "i-dfdinf", "i-fsfsf", "i-8hr83hfwif", "i-nsnsnan"}
170-
instanceIds := make([]string, len(ids))
170+
instanceIDs := make([]string, len(ids))
171171

172-
for i := 0; i < len(ids); i++ {
173-
instanceIds[i] = ids[i]
174-
}
172+
copy(instanceIDs, ids)
175173

176-
batches := prepareBatches(maxItems, instanceIds)
174+
batches := prepareBatches(maxItems, instanceIDs)
177175

178176
if len(batches) > len(ids)/maxItems+1 {
179177
t.Error("prepareBatches() didn't split the slice correctly")

cmd/sync/azure.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
@@ -154,12 +155,12 @@ type azureConfig struct {
154155
type azureUpstream struct {
155156
Name string
156157
VMScaleSet string `yaml:"virtual_machine_scale_set"`
157-
Port int
158158
Kind string
159-
MaxConns int `yaml:"max_conns"`
160-
MaxFails int `yaml:"max_fails"`
161159
FailTimeout string `yaml:"fail_timeout"`
162160
SlowStart string `yaml:"slow_start"`
161+
Port int
162+
MaxConns int `yaml:"max_conns"`
163+
MaxFails int `yaml:"max_fails"`
163164
}
164165

165166
func validateAzureConfig(cfg *azureConfig) error {
@@ -172,12 +173,12 @@ func validateAzureConfig(cfg *azureConfig) error {
172173
}
173174

174175
if len(cfg.Upstreams) == 0 {
175-
return fmt.Errorf("there are no upstreams found in the config file")
176+
return errors.New("there are no upstreams found in the config file")
176177
}
177178

178179
for _, ups := range cfg.Upstreams {
179180
if ups.Name == "" {
180-
return fmt.Errorf(upstreamNameErrorMsg)
181+
return errors.New(upstreamNameErrorMsg)
181182
}
182183
if ups.VMScaleSet == "" {
183184
return fmt.Errorf(upstreamErrorMsgFormat, "virtual_machine_scale_set", ups.Name)

cmd/sync/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"time"
67

@@ -10,8 +11,8 @@ import (
1011
// commonConfig stores the configuration parameters common to all providers
1112
type commonConfig struct {
1213
APIEndpoint string `yaml:"api_endpoint"`
13-
SyncIntervalInSeconds time.Duration `yaml:"sync_interval_in_seconds"`
1414
CloudProvider string `yaml:"cloud_provider"`
15+
SyncIntervalInSeconds time.Duration `yaml:"sync_interval_in_seconds"`
1516
}
1617

1718
func parseCommonConfig(data []byte) (*commonConfig, error) {
@@ -35,7 +36,7 @@ func validateCommonConfig(cfg *commonConfig) error {
3536
}
3637

3738
if cfg.SyncIntervalInSeconds == 0 {
38-
return fmt.Errorf(intervalErrorMsg)
39+
return errors.New(intervalErrorMsg)
3940
}
4041

4142
if cfg.CloudProvider == "" {
@@ -51,13 +52,13 @@ func validateCommonConfig(cfg *commonConfig) error {
5152

5253
// Upstream is the cloud agnostic representation of an Upstream (eg, common fields for every cloud provider)
5354
type Upstream struct {
55+
MaxConns *int
56+
MaxFails *int
5457
Name string
55-
Port int
5658
ScalingGroup string
5759
Kind string
58-
MaxConns *int
59-
MaxFails *int
6060
FailTimeout string
6161
SlowStart string
62+
Port int
6263
InService bool
6364
}

cmd/sync/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func main() {
160160
upstream.Name, upstream.ScalingGroup, addedAddresses, removedAddresses, updatedAddresses)
161161
}
162162
}
163-
164163
}
165164

166165
select {

0 commit comments

Comments
 (0)