diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..f7ec89c1 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,19 @@ +linters: + enable: + - contextcheck + - gocritic + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - misspell + - staticcheck + - unused + - gofumpt + +linters-settings: + goimports: + local-prefixes: github.com/NVIDIA/dcgm-exporter + diff --git a/Makefile b/Makefile index 76873b03..34342c1e 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ include hack/VERSION MKDIR ?= mkdir REGISTRY ?= nvidia +GOLANGCILINT_TIMEOUT ?= 10m DCGM_VERSION := $(NEW_DCGM_VERSION) GOLANG_VERSION := 1.21.5 @@ -83,7 +84,7 @@ test-coverage: .PHONY: lint lint: - golangci-lint run ./... + golangci-lint run ./... --timeout $(GOLANGCILINT_TIMEOUT) --new-from-rev=HEAD~1 --verbose .PHONY: validate-modules validate-modules: @@ -98,6 +99,10 @@ tools: ## Install required tools and utilities go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 go install github.com/axw/gocov/gocov@latest go install golang.org/x/tools/cmd/goimports@latest + go install mvdan.cc/gofumpt@latest + +fmt: + find . -name '*.go' | xargs gofumpt -l -w goimports: go list -f {{.Dir}} $(MODULE)/... \ diff --git a/pkg/dcgmexporter/kubernetes_test.go b/pkg/dcgmexporter/kubernetes_test.go index 6f6137cc..cdb35ff7 100644 --- a/pkg/dcgmexporter/kubernetes_test.go +++ b/pkg/dcgmexporter/kubernetes_test.go @@ -162,7 +162,6 @@ func (s *PodResourcesMockServer) List( return &podresourcesapi.ListPodResourcesResponse{ PodResources: podResources, }, nil - } func TestProcessPodMapper_WithD_Different_Format_Of_DeviceID(t *testing.T) { @@ -273,7 +272,8 @@ func TestProcessPodMapper_WithD_Different_Format_Of_DeviceID(t *testing.T) { podMapper, err := NewPodMapper(&Config{ KubernetesGPUIdType: tc.KubernetesGPUIDType, - PodResourcesKubeletSocket: socketPath}) + PodResourcesKubeletSocket: socketPath, + }) require.NoError(t, err) require.NotNil(t, podMapper) metrics := MetricsByCounter{}