Skip to content
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

Add more linters #857

Merged
merged 2 commits into from
Sep 26, 2024
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
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ linters-settings:
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
Expand All @@ -37,6 +46,7 @@ linters:
- asasalint
- asciicheck
- bidichk
- containedctx
- contextcheck
- copyloopvar
- dupword
Expand All @@ -62,9 +72,11 @@ linters:
- intrange
- loggercheck
- makezero
- mirror
- misspell
- musttag
- nilerr
- nilnil
- noctx
- nolintlint
- paralleltest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VERSION = 1.3.0
TAG = $(VERSION)
PREFIX = nginx/nginx-prometheus-exporter
# renovate: datasource=docker depName=golangci/golangci-lint
# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION = v1.61.0

.DEFAULT_GOAL:=nginx-prometheus-exporter
Expand All @@ -21,7 +21,7 @@ build-goreleaser: ## Build all binaries using GoReleaser

.PHONY: lint
lint: ## Run linter
docker run --pull always --rm -v $(shell pwd):/nginx-prometheus-exporter -w /nginx-prometheus-exporter -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint --color always run
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix

.PHONY: test
test: ## Run tests
Expand Down
6 changes: 3 additions & 3 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ func cloneRequest(req *http.Request) *http.Request {
func addMissingEnvironmentFlags(ka *kingpin.Application) {
for _, f := range ka.Model().FlagGroupModel.Flags {
if strings.HasPrefix(f.Name, "web.") && f.Envar == "" {
flag := ka.GetFlag(f.Name)
if flag != nil {
flag.Envar(convertFlagToEnvar(strings.TrimPrefix(f.Name, "web.")))
retrievedFlag := ka.GetFlag(f.Name)
if retrievedFlag != nil {
retrievedFlag.Envar(convertFlagToEnvar(strings.TrimPrefix(f.Name, "web.")))
}
}
}
Expand Down