Skip to content

cherry-pick: golangci-lint version and action update #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
go-version-file: go.mod

- name: Lint Go
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
version: v1.64.8 # renovate: datasource=github-tags depName=golangci/golangci-lint
version: v2.1.5 # renovate: datasource=github-tags depName=golangci/golangci-lint

actionlint:
name: Actionlint
Expand Down
119 changes: 66 additions & 53 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
linters-settings:
misspell:
locale: US
revive:
ignore-generated-header: true
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
- name: duplicated-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: superfluous-else
- name: time-naming
- name: unchecked-type-assertion
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
govet:
enable-all: true
sloglint:
static-msg: true
key-naming-case: snake
version: "2"
linters:
default: none
enable:
- asasalint
- asciicheck
Expand All @@ -61,11 +20,7 @@ linters:
- gochecksumtype
- gocritic
- godot
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- gosmopolitan
- govet
- ineffassign
Expand All @@ -88,22 +43,80 @@ linters:
- revive
- sloglint
- staticcheck
- stylecheck
- tagalign
- tenv
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- wrapcheck
disable-all: true
settings:
govet:
enable-all: true
misspell:
locale: US
revive:
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
- name: duplicated-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: superfluous-else
- name: time-naming
- name: unchecked-type-assertion
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
sloglint:
static-msg: true
key-naming-case: snake
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
run:
timeout: 5m
formatters:
enable:
- gofmt
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
- id: fix-byte-order-marker

- repo: https://github.com/golangci/golangci-lint
rev: v1.64.8
rev: v2.1.5
hooks:
- id: golangci-lint-full

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VERSION = 1.4.0
TAG = $(VERSION)
PREFIX = nginx/nginx-prometheus-exporter
# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION = v1.64.8
GOLANGCI_LINT_VERSION = v2.1.5

.DEFAULT_GOAL:=nginx-prometheus-exporter

Expand All @@ -21,7 +21,7 @@ build-goreleaser: ## Build all binaries using GoReleaser

.PHONY: lint
lint: ## Run linter
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix

.PHONY: test
test: ## Run tests
Expand Down
2 changes: 1 addition & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func cloneRequest(req *http.Request) *http.Request {
// addMissingEnvironmentFlags sets Envar on any flag which has
// the "web." prefix which doesn't already have an Envar set.
func addMissingEnvironmentFlags(ka *kingpin.Application) {
for _, f := range ka.Model().FlagGroupModel.Flags {
for _, f := range ka.Model().Flags {
if strings.HasPrefix(f.Name, "web.") && f.Envar == "" {
retrievedFlag := ka.GetFlag(f.Name)
if retrievedFlag != nil {
Expand Down
2 changes: 1 addition & 1 deletion exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestAddMissingEnvironmentFlags(t *testing.T) {
// instead of checking the envar of each matching flag name
for k, v := range expectedMatches {
matched := false
for _, f := range kingpin.CommandLine.Model().FlagGroupModel.Flags {
for _, f := range kingpin.CommandLine.Model().Flags {
if f.Name == k && f.Envar == v {
matched = true
}
Expand Down
Loading