Skip to content

Commit

Permalink
Enable more linters (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Feb 22, 2024
1 parent e848697 commit d620391
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 37 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -34,8 +31,6 @@ jobs:

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

actionlint:
name: Actionlint
Expand Down
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ linters-settings:
errcheck:
exclude-functions:
- (github.com/go-kit/log.Logger).Log
govet:
check-shadowing: true
enable-all: true

linters:
enable:
- asciicheck
- bidichk
- dupword
- errcheck
- errorlint
- gofmt
Expand All @@ -44,18 +49,23 @@ linters:
- gosimple
- govet
- ineffassign
- loggercheck
- makezero
- misspell
- nilerr
- noctx
- perfsprint
- predeclared
- promlinter
- revive
- staticcheck
- tagalign
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
disable-all: true
issues:
Expand Down
14 changes: 2 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@ repos:
- id: requirements-txt-fixer
- id: fix-byte-order-marker

- repo: local
hooks:
- id: golang-diff
name: create-go-diff
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
language: system
types: [go]
pass_filenames: false

- repo: https://github.com/golangci/golangci-lint
rev: v1.56.2
hooks:
- id: golangci-lint
args: [--new-from-patch=/tmp/diff.patch]
- id: golangci-lint-full

- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
Expand All @@ -55,4 +45,4 @@ repos:
hooks:
- id: yamllint
ci:
skip: [golang-diff, golangci-lint, yamllint]
skip: [golangci-lint-full, yamllint]
2 changes: 1 addition & 1 deletion client/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Reading: %d Writing: %d Waiting: %d

// NginxClient allows you to fetch NGINX metrics from the stub_status page.
type NginxClient struct {
apiEndpoint string
httpClient *http.Client
apiEndpoint string
}

// StubStats represents NGINX stub_status metrics.
Expand Down
8 changes: 6 additions & 2 deletions collector/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ func TestMergeLabels(t *testing.T) {
t.Parallel()

tests := []struct {
name string
mapA, mapB, want map[string]string
mapA map[string]string
mapB map[string]string
want map[string]string
name string
}{
{
name: "base case",
Expand All @@ -32,7 +34,9 @@ func TestMergeLabels(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := MergeLabels(tt.mapA, tt.mapB); !reflect.DeepEqual(got, tt.want) {
t.Errorf("mergeLabels() = %v, want %v", got, tt.want)
}
Expand Down
4 changes: 2 additions & 2 deletions collector/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

// NginxCollector collects NGINX metrics. It implements prometheus.Collector interface.
type NginxCollector struct {
upMetric prometheus.Gauge
logger log.Logger
nginxClient *client.NginxClient
metrics map[string]*prometheus.Desc
upMetric prometheus.Gauge
mutex sync.Mutex
logger log.Logger
}

// NewNginxCollector creates an NginxCollector.
Expand Down
24 changes: 12 additions & 12 deletions collector/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type LabelUpdater interface {

// NginxPlusCollector collects NGINX Plus metrics. It implements prometheus.Collector interface.
type NginxPlusCollector struct {
upMetric prometheus.Gauge
logger log.Logger
cacheZoneMetrics map[string]*prometheus.Desc
workerMetrics map[string]*prometheus.Desc
nginxClient *plusclient.NginxClient
totalMetrics map[string]*prometheus.Desc
serverZoneMetrics map[string]*prometheus.Desc
upstreamMetrics map[string]*prometheus.Desc
upstreamServerMetrics map[string]*prometheus.Desc
streamServerZoneMetrics map[string]*prometheus.Desc
streamZoneSyncMetrics map[string]*prometheus.Desc
streamUpstreamMetrics map[string]*prometheus.Desc
Expand All @@ -47,21 +47,21 @@ type NginxPlusCollector struct {
limitRequestMetrics map[string]*prometheus.Desc
limitConnectionMetrics map[string]*prometheus.Desc
streamLimitConnectionMetrics map[string]*prometheus.Desc
cacheZoneMetrics map[string]*prometheus.Desc
upMetric prometheus.Gauge
mutex sync.Mutex
variableLabelNames VariableLabelNames
upstreamServerMetrics map[string]*prometheus.Desc
upstreamMetrics map[string]*prometheus.Desc
streamUpstreamServerPeerLabels map[string][]string
serverZoneMetrics map[string]*prometheus.Desc
upstreamServerLabels map[string][]string
streamUpstreamServerLabels map[string][]string
serverZoneLabels map[string][]string
streamServerZoneLabels map[string][]string
upstreamServerPeerLabels map[string][]string
streamUpstreamServerPeerLabels map[string][]string
workerLabels map[string][]string
cacheZoneLabels map[string][]string
totalMetrics map[string]*prometheus.Desc
variableLabelNames VariableLabelNames
variableLabelsMutex sync.RWMutex
logger log.Logger
workerLabels map[string][]string
workerMetrics map[string]*prometheus.Desc
mutex sync.Mutex
}

// UpdateUpstreamServerPeerLabels updates the Upstream Server Peer Labels
Expand Down
6 changes: 3 additions & 3 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseUnixSocketAddress(address string) (string, string, error) {
addressPartsLength := len(addressParts)

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

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

type userAgentRoundTripper struct {
agent string
rt http.RoundTripper
agent string
}

func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
Expand Down
4 changes: 4 additions & 0 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func TestParsePositiveDuration(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := parsePositiveDuration(tt.testInput)
if (err != nil) != tt.wantErr {
t.Errorf("parsePositiveDuration() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -91,7 +93,9 @@ func TestParseUnixSocketAddress(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
socketPath, requestPath, err := parseUnixSocketAddress(tt.testInput)
if (err != nil) != tt.wantErr {
t.Errorf("parseUnixSocketAddress() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit d620391

Please sign in to comment.