Skip to content

Commit d620391

Browse files
authored
Enable more linters (#622)
1 parent e848697 commit d620391

File tree

9 files changed

+40
-37
lines changed

9 files changed

+40
-37
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ jobs:
2020
lint:
2121
name: Lint
2222
runs-on: ubuntu-22.04
23-
permissions:
24-
contents: read # for actions/checkout to fetch code
25-
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
2623
steps:
2724
- name: Checkout Repository
2825
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -34,8 +31,6 @@ jobs:
3431

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

4035
actionlint:
4136
name: Actionlint

.golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ linters-settings:
3131
errcheck:
3232
exclude-functions:
3333
- (github.com/go-kit/log.Logger).Log
34+
govet:
35+
check-shadowing: true
36+
enable-all: true
3437

3538
linters:
3639
enable:
3740
- asciicheck
41+
- bidichk
42+
- dupword
3843
- errcheck
3944
- errorlint
4045
- gofmt
@@ -44,18 +49,23 @@ linters:
4449
- gosimple
4550
- govet
4651
- ineffassign
52+
- loggercheck
4753
- makezero
4854
- misspell
4955
- nilerr
5056
- noctx
57+
- perfsprint
5158
- predeclared
5259
- promlinter
5360
- revive
5461
- staticcheck
62+
- tagalign
63+
- tparallel
5564
- typecheck
5665
- unconvert
5766
- unparam
5867
- unused
68+
- usestdlibvars
5969
- wastedassign
6070
disable-all: true
6171
issues:

.pre-commit-config.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,10 @@ repos:
2525
- id: requirements-txt-fixer
2626
- id: fix-byte-order-marker
2727

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

4333
- repo: https://github.com/gitleaks/gitleaks
4434
rev: v8.18.2
@@ -55,4 +45,4 @@ repos:
5545
hooks:
5646
- id: yamllint
5747
ci:
58-
skip: [golang-diff, golangci-lint, yamllint]
48+
skip: [golangci-lint-full, yamllint]

client/nginx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Reading: %d Writing: %d Waiting: %d
1616

1717
// NginxClient allows you to fetch NGINX metrics from the stub_status page.
1818
type NginxClient struct {
19-
apiEndpoint string
2019
httpClient *http.Client
20+
apiEndpoint string
2121
}
2222

2323
// StubStats represents NGINX stub_status metrics.

collector/helper_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ func TestMergeLabels(t *testing.T) {
99
t.Parallel()
1010

1111
tests := []struct {
12-
name string
13-
mapA, mapB, want map[string]string
12+
mapA map[string]string
13+
mapB map[string]string
14+
want map[string]string
15+
name string
1416
}{
1517
{
1618
name: "base case",
@@ -32,7 +34,9 @@ func TestMergeLabels(t *testing.T) {
3234
},
3335
}
3436
for _, tt := range tests {
37+
tt := tt
3538
t.Run(tt.name, func(t *testing.T) {
39+
t.Parallel()
3640
if got := MergeLabels(tt.mapA, tt.mapB); !reflect.DeepEqual(got, tt.want) {
3741
t.Errorf("mergeLabels() = %v, want %v", got, tt.want)
3842
}

collector/nginx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
// NginxCollector collects NGINX metrics. It implements prometheus.Collector interface.
1313
type NginxCollector struct {
14+
upMetric prometheus.Gauge
15+
logger log.Logger
1416
nginxClient *client.NginxClient
1517
metrics map[string]*prometheus.Desc
16-
upMetric prometheus.Gauge
1718
mutex sync.Mutex
18-
logger log.Logger
1919
}
2020

2121
// NewNginxCollector creates an NginxCollector.

collector/nginx_plus.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ type LabelUpdater interface {
3333

3434
// NginxPlusCollector collects NGINX Plus metrics. It implements prometheus.Collector interface.
3535
type NginxPlusCollector struct {
36+
upMetric prometheus.Gauge
37+
logger log.Logger
38+
cacheZoneMetrics map[string]*prometheus.Desc
39+
workerMetrics map[string]*prometheus.Desc
3640
nginxClient *plusclient.NginxClient
37-
totalMetrics map[string]*prometheus.Desc
38-
serverZoneMetrics map[string]*prometheus.Desc
39-
upstreamMetrics map[string]*prometheus.Desc
40-
upstreamServerMetrics map[string]*prometheus.Desc
4141
streamServerZoneMetrics map[string]*prometheus.Desc
4242
streamZoneSyncMetrics map[string]*prometheus.Desc
4343
streamUpstreamMetrics map[string]*prometheus.Desc
@@ -47,21 +47,21 @@ type NginxPlusCollector struct {
4747
limitRequestMetrics map[string]*prometheus.Desc
4848
limitConnectionMetrics map[string]*prometheus.Desc
4949
streamLimitConnectionMetrics map[string]*prometheus.Desc
50-
cacheZoneMetrics map[string]*prometheus.Desc
51-
upMetric prometheus.Gauge
52-
mutex sync.Mutex
53-
variableLabelNames VariableLabelNames
50+
upstreamServerMetrics map[string]*prometheus.Desc
51+
upstreamMetrics map[string]*prometheus.Desc
52+
streamUpstreamServerPeerLabels map[string][]string
53+
serverZoneMetrics map[string]*prometheus.Desc
5454
upstreamServerLabels map[string][]string
5555
streamUpstreamServerLabels map[string][]string
5656
serverZoneLabels map[string][]string
5757
streamServerZoneLabels map[string][]string
5858
upstreamServerPeerLabels map[string][]string
59-
streamUpstreamServerPeerLabels map[string][]string
59+
workerLabels map[string][]string
6060
cacheZoneLabels map[string][]string
61+
totalMetrics map[string]*prometheus.Desc
62+
variableLabelNames VariableLabelNames
6163
variableLabelsMutex sync.RWMutex
62-
logger log.Logger
63-
workerLabels map[string][]string
64-
workerMetrics map[string]*prometheus.Desc
64+
mutex sync.Mutex
6565
}
6666

6767
// UpdateUpstreamServerPeerLabels updates the Upstream Server Peer Labels

exporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func parseUnixSocketAddress(address string) (string, string, error) {
6767
addressPartsLength := len(addressParts)
6868

6969
if addressPartsLength > 3 || addressPartsLength < 1 {
70-
return "", "", fmt.Errorf("address for unix domain socket has wrong format")
70+
return "", "", errors.New("address for unix domain socket has wrong format")
7171
}
7272

7373
unixSocketPath := addressParts[1]
@@ -103,7 +103,7 @@ func main() {
103103
// convert deprecated flags to new format
104104
for i, arg := range os.Args {
105105
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 {
106-
newArg := fmt.Sprintf("-%s", arg)
106+
newArg := "-" + arg
107107
fmt.Printf("the flag format is deprecated and will be removed in a future release, please use the new format: %s\n", newArg)
108108
os.Args[i] = newArg
109109
}
@@ -261,8 +261,8 @@ func registerCollector(logger log.Logger, transport *http.Transport,
261261
}
262262

263263
type userAgentRoundTripper struct {
264-
agent string
265264
rt http.RoundTripper
265+
agent string
266266
}
267267

268268
func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

exporter_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func TestParsePositiveDuration(t *testing.T) {
3838
},
3939
}
4040
for _, tt := range tests {
41+
tt := tt
4142
t.Run(tt.name, func(t *testing.T) {
43+
t.Parallel()
4244
got, err := parsePositiveDuration(tt.testInput)
4345
if (err != nil) != tt.wantErr {
4446
t.Errorf("parsePositiveDuration() error = %v, wantErr %v", err, tt.wantErr)
@@ -91,7 +93,9 @@ func TestParseUnixSocketAddress(t *testing.T) {
9193
},
9294
}
9395
for _, tt := range tests {
96+
tt := tt
9497
t.Run(tt.name, func(t *testing.T) {
98+
t.Parallel()
9599
socketPath, requestPath, err := parseUnixSocketAddress(tt.testInput)
96100
if (err != nil) != tt.wantErr {
97101
t.Errorf("parseUnixSocketAddress() error = %v, wantErr %v", err, tt.wantErr)

0 commit comments

Comments
 (0)