Skip to content

Commit cbfd37d

Browse files
committed
BUILD/MEDIUM: update linters, use local version
1 parent 3029b7d commit cbfd37d

File tree

21 files changed

+91
-45
lines changed

21 files changed

+91
-45
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
steps:
5959
- name: Check out code into the Go module directory
6060
uses: actions/checkout@v2
61+
- name: Set up Go
62+
uses: actions/setup-go@v2
63+
with:
64+
go-version: 1.19
6165
- uses: actions/cache@v2
6266
with:
6367
path: |
@@ -66,10 +70,9 @@ jobs:
6670
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
6771
restore-keys: |
6872
${{ runner.os }}-go-
69-
- name: golangci-lint
70-
uses: docker://ghcr.io/haproxytech/go-linter:1.33
71-
with:
72-
args: --timeout 5m
73+
- name: Lint
74+
run: |
75+
make lint
7376
build:
7477
name: build
7578
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
kubernetes-ingress
44
dist/
55
.code-generator/
6+
bin/golangci-lint

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ golangci_lint:
4242
stage: lint
4343
needs: []
4444
image:
45-
name: $CI_REGISTRY_GO/lint:1.33
45+
name: $CI_REGISTRY_GO/golang:1.19
4646
entrypoint: [""]
4747
tags:
4848
- go
4949
script:
50-
- golangci-lint run --enable-all --timeout=10m
50+
- make lint
5151
only:
5252
- merge_requests
5353
- branches

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ linters-settings:
77
suggest-new: true
88
dupl:
99
threshold: 200
10+
revive:
11+
rules:
12+
- name: var-naming
13+
severity: warning
14+
disabled: true
15+
arguments:
16+
- [] # AllowList
17+
- [] # DenyList
1018

1119
linters:
1220
enable-all: true
@@ -32,3 +40,15 @@ linters:
3240
- nakedret
3341
- paralleltest
3442
- testpackage
43+
- varnamelen
44+
- tagliatelle
45+
- nonamedreturns
46+
- forcetypeassert
47+
- exhaustruct
48+
- ireturn
49+
- cyclop
50+
- stylecheck
51+
- errchkjson
52+
- forbidigo
53+
- nosnakecase
54+
- interfacebloat

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT_PATH=${PWD}
22
TARGETPLATFORM?=linux/amd64
3+
GOLANGCI_LINT_VERSION=1.50.1
34

45
.PHONY: test
56
test:
@@ -21,8 +22,12 @@ doc:
2122

2223
.PHONY: lint
2324
lint:
25+
cd bin;GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} sh lint-check.sh
26+
bin/golangci-lint run --timeout 5m --color always --max-issues-per-linter 0 --max-same-issues 0
27+
28+
.PHONY: yaml-lint
29+
yaml-lint:
2430
docker run --rm -v $(pwd):/data cytopia/yamllint .
25-
golangci-lint run --color always --timeout 240s
2631

2732
.PHONY: example
2833
example:

bin/lint-check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
V=$(./golangci-lint --version)
3+
4+
case "$V" in
5+
*$GOLANGCI_LINT_VERSION*) echo "$V" ;;
6+
*) curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(pwd) "v$GOLANGCI_LINT_VERSION" ;;
7+
esac

deploy/tests/e2e/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"crypto/tls"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net"
2525
"net/http"
2626
"os"
@@ -67,7 +67,7 @@ func newClient(host string, port int, tls bool) (*Client, error) {
6767
if port != 0 {
6868
dstPort = port
6969
}
70-
req, err := http.NewRequest("GET", fmt.Sprintf("%s://%s", scheme, host), nil)
70+
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s://%s", scheme, host), nil)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -112,7 +112,7 @@ func NewHTTPSClient(host string, port ...int) (*Client, error) {
112112
return client, nil
113113
}
114114

115-
func (c *Client) Do() (res *http.Response, close func() error, err error) {
115+
func (c *Client) Do() (res *http.Response, closeFunc func() error, err error) {
116116
client := &http.Client{}
117117
if c.Transport != nil {
118118
client.Transport = c.Transport
@@ -130,7 +130,7 @@ func (c *Client) Do() (res *http.Response, close func() error, err error) {
130130
if err != nil {
131131
return
132132
}
133-
close = res.Body.Close
133+
closeFunc = res.Body.Close
134134
return
135135
}
136136

@@ -177,7 +177,7 @@ func ProxyProtoConn() (result []byte, err error) {
177177
return
178178
}
179179

180-
return ioutil.ReadAll(conn)
180+
return io.ReadAll(conn)
181181
}
182182

183183
func runtimeCommand(command string) (result []byte, err error) {

deploy/tests/e2e/utils.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -17,11 +16,15 @@ import (
1716
"k8s.io/client-go/tools/clientcmd"
1817
)
1918

20-
var WaitDuration = 60 * time.Second
21-
var TickDuration = 2 * time.Second
19+
var (
20+
WaitDuration = 60 * time.Second
21+
TickDuration = 2 * time.Second
22+
)
2223

23-
var devModeFlag = flag.Bool("dev", false, "keep test environment after finishing")
24-
var devMode bool
24+
var (
25+
devModeFlag = flag.Bool("dev", false, "keep test environment after finishing")
26+
devMode bool
27+
)
2528

2629
type Test struct {
2730
namespace string
@@ -50,7 +53,7 @@ func NewTest() (test Test, err error) {
5053
return nil
5154
}}
5255
// TemplateDir
53-
test.templateDir, err = ioutil.TempDir("/tmp/", "haproxy-ic-test-tmpl")
56+
test.templateDir, err = os.MkdirTemp("/tmp/", "haproxy-ic-test-tmpl")
5457
if err != nil {
5558
return test, fmt.Errorf("error creating template dir: %w ", err)
5659
}
@@ -69,7 +72,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
6972
return err
7073
}
7174
}
72-
if file, err = ioutil.ReadFile(path); err != nil {
75+
if file, err = os.ReadFile(path); err != nil {
7376
return fmt.Errorf("error reading yaml file: %w", err)
7477
}
7578
// kubectl -n $NS apply -f -
@@ -80,7 +83,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
8083
}
8184

8285
func (t *Test) processTemplate(path string, tmplData interface{}) (string, error) {
83-
file, err := ioutil.ReadFile(path)
86+
file, err := os.ReadFile(path)
8487
if err != nil {
8588
return "", fmt.Errorf("error reading yaml template: %w", err)
8689
}
@@ -91,13 +94,13 @@ func (t *Test) processTemplate(path string, tmplData interface{}) (string, error
9194
return "", fmt.Errorf("error parsing yaml template: %w", err)
9295
}
9396
yaml := filepath.Join(t.templateDir, t.namespace+time.Now().Format("2006-01-02-1504051111")+".yaml")
94-
return yaml, ioutil.WriteFile(yaml, result.Bytes(), 0600)
97+
return yaml, os.WriteFile(yaml, result.Bytes(), 0o600)
9598
}
9699

97100
func (t *Test) Delete(path string) error {
98101
var err error
99102
var file []byte
100-
if file, err = ioutil.ReadFile(path); err != nil {
103+
if file, err = os.ReadFile(path); err != nil {
101104
return fmt.Errorf("error reading yaml file: %w", err)
102105
}
103106
if out, errApply := t.execute(string(file), "kubectl", "delete", "-f", "-"); errApply != nil {

deploy/tests/integration/customresources/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package customresources
1616

1717
import (
18-
"io/ioutil"
18+
"os"
1919
"path/filepath"
2020
"testing"
2121

@@ -47,7 +47,7 @@ type Test struct {
4747
}
4848

4949
func (suite *CustomResourceSuite) BeforeTest(suiteName, testName string) {
50-
tempDir, err := ioutil.TempDir("", "ut-"+testName+"-*")
50+
tempDir, err := os.MkdirTemp("", "ut-"+testName+"-*")
5151
if err != nil {
5252
suite.T().Fatalf("Suite '%s': Test '%s' : error : %s", suiteName, testName, err)
5353
}

pkg/annotations/cfgSnippet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var cfgSnippet struct {
3535
backends map[string]*cfgData
3636
}
3737

38-
//nolint: gochecknoinits
38+
//nolint:gochecknoinits
3939
func init() {
4040
cfgSnippet.global = &cfgData{}
4141
cfgSnippet.frontends = make(map[string]*cfgData)

0 commit comments

Comments
 (0)