Skip to content

Commit

Permalink
ci(golangci-lint): Bump linter to the latest version (#30990)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz authored Nov 12, 2024
1 parent 1b848a5 commit a12f04a
Show file tree
Hide file tree
Showing 13 changed files with 430 additions and 405 deletions.
120 changes: 86 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
run:
skip-files:
- pkg/util/cloudproviders/cloudfoundry/bbscache_test.go # implements interface from imported package whose method names fail linting
- pkg/util/intern/string.go # TODO: fix govet 'unsafeptr' error
- pkg/serverless/trace/inferredspan/constants.go # TODO: fox revive exported const error
skip-dirs:
- pkg/proto/patches


issues:
exclude-use-default: false
# Do not limit the number of issues per linter.
Expand All @@ -15,9 +6,20 @@ issues:
# Do not limit the number of times a same issue is reported.
max-same-issues: 0

exclude-files:
- pkg/util/cloudproviders/cloudfoundry/bbscache_test.go # implements interface from imported package whose method names fail linting
- pkg/util/intern/string.go # TODO: fix govet 'unsafeptr' error
- pkg/serverless/trace/inferredspan/constants.go # TODO: fox revive exported const error

exclude-dirs:
- pkg/proto/patches
- tasks/unit_tests/testdata/components_src

exclude:
- "Error return value of `io.WriteString` is not checked" # 'errcheck' errors in tools/dep_tree_resolver/go_deps.go
- "Error return value of `pem.Encode` is not checked" # 'errcheck' errors in test/integration/utils/certificates.go
- "Error return value of `c.logErrorNotImplemented` is not checked" # 'errcheck' errors in pkg/config/nodetreemodel/config.go
- "Error return value of `n.logErrorNotImplemented` is not checked" # 'errcheck' errors in pkg/config/nodetreemodel/config.go
- "exported: exported const Exec should have comment \\(or a comment on this block\\) or be unexported" # 'revive' errors in pkg/process/events/model/model_common.go
- "exported: exported const APIName should have comment \\(or a comment on this block\\) or be unexported" # 'revive' errors in pkg/serverless/trace/inferredspan/constants.go
- "unnecessary conversion" # 'unconvert' errors in test/integration/utils/certificates_test.go
Expand All @@ -39,8 +41,6 @@ issues:
# disable typecheck in folder where it breaks because of build tags
- path: "pkg/security/"
linters: [typecheck]
- path: "pkg/process/"
linters: [typecheck]
# Ignore name repetition for checks (docker.Docker*, jmx.JMX*, etc.)
- path: pkg/collector/corechecks/
text: "name will be used as .* by other packages, and that stutters"
Expand All @@ -61,22 +61,21 @@ issues:
# We are using it and it's not clear how to replace it.
- text: "Temporary has been deprecated since Go 1.18"
linters: [staticcheck]

linters:
disable-all: true
enable:
- unconvert # Remove unnecessary type conversions
- unused # Checks Go code for unused constants, variables, functions and types
- ineffassign # Detects when assignments to existing variables are not used
- misspell # Finds commonly misspelled English words in comments
- gofmt # Gofmt checks whether code was gofmt-ed
- revive # Revive is a replacement for golint, a coding style checker
- errcheck # errcheck is a program for checking for unchecked errors in go programs.
- staticcheck # staticcheck is a go vet on steroids, applying a ton of static analysis checks
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- depguard # Depguard is useful for preventing specific packages from being used
- bodyclose # checks whether HTTP response body is closed successfully
- gosimple # Linter for Go source code that specializes in simplifying code.
- unconvert # Remove unnecessary type conversions
- unused # Checks Go code for unused constants, variables, functions and types
- ineffassign # Detects when assignments to existing variables are not used
- misspell # Finds commonly misspelled English words in comments
- gofmt # Gofmt checks whether code was gofmt-ed
- revive # Revive is a replacement for golint, a coding style checker
- errcheck # errcheck is a program for checking for unchecked errors in go programs.
- staticcheck # staticcheck is a go vet on steroids, applying a ton of static analysis checks
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- depguard # Depguard is useful for preventing specific packages from being used
- bodyclose # checks whether HTTP response body is closed successfully
- gosimple # Linter for Go source code that specializes in simplifying code.

linters-settings:
depguard:
Expand All @@ -85,8 +84,6 @@ linters-settings:
files:
- $all
deny:
- pkg: "sync/atomic"
desc: "Use go.uber.org/atomic instead; see docs/dev/atomics.md"
- pkg: "io/ioutil"
desc: "Deprecated since Go 1.16. Use package io or os instead."
- pkg: "github.com/golang/glog"
Expand All @@ -97,19 +94,72 @@ linters-settings:
# the goal is just to limit the risk of accidental imports
- pkg: "gotest.tools/assert"
desc: "Not really forbidden to use, but it is usually imported by mistake instead of github.com/stretchr/testify/assert"
- pkg: "github.com/tj/assert"
desc: "Not really forbidden to use, but it is usually imported by mistake instead of github.com/stretchr/testify/assert, and confusing since it actually has the behavior of github.com/stretchr/testify/require"

errcheck:
# Disable warnings for `fmt`, `log` and `seelog` packages. Also ignore `Write` functions from `net/http` package.
# Disable warnings for select Windows functions
ignore: fmt:.*,github.com/DataDog/datadog-agent/pkg/util/log:.*,github.com/DataDog/datadog-agent/comp/core/log:.*,github.com/cihub/seelog:.*,net/http:Write,github.com/DataDog/datadog-agent/pkg/trace/metrics:.*,github.com/DataDog/datadog-agent/pkg/collector/corechecks:Warnf?,golang.org/x/sys/windows:(CloseHandle|FreeLibrary|FreeSid|RegCloseKey|SetEvent|LocalFree),syscall:CloseHandle,golang.org/x/sys/windows/svc/mgr:Disconnect,golang.org/x/sys/windows/svc/debug:(Close|Error|Info|Warning),github.com/lxn/walk:Dispose,github.com/DataDog/datadog-agent/comp/core/flare/types:(AddFile.*|CopyDir.*|CopyFile.*),golang.org/x/sys/windows/registry:Close
ignore: "github.com/DataDog/datadog-agent/pkg/util/log:.*"
exclude-functions:
- (*github.com/DataDog/datadog-agent/pkg/collector/corechecks.CheckBase).Warn
- (*github.com/DataDog/datadog-agent/pkg/collector/corechecks.CheckBase).Warnf
- (*github.com/lxn/walk.NotifyIcon).Dispose
- (*golang.org/x/sys/windows/svc/mgr.Mgr).Disconnect
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).AddFile
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).AddFileFromFunc
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).AddFileWithoutScrubbing
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).CopyDir
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).CopyDirTo
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).CopyDirToWithoutScrubbing
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).CopyFile
- (github.com/DataDog/datadog-agent/comp/core/flare/types.FlareBuilder).CopyFileTo
- (github.com/DataDog/datadog-agent/comp/core/log.Component).ChangeLogLevel
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Critical
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Criticalf
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Error
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Errorf
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Warn
- (github.com/DataDog/datadog-agent/comp/core/log.Component).Warnf
- (net/http.ResponseWriter).Write
- fmt.Sscanf
- github.com/cihub/seelog.Warnf
- github.com/DataDog/datadog-agent/pkg/util/log.ChangeLogLevel
- github.com/DataDog/datadog-agent/pkg/util/log.Critical
- github.com/DataDog/datadog-agent/pkg/util/log.Criticalc
- github.com/DataDog/datadog-agent/pkg/util/log.Criticalf
- github.com/DataDog/datadog-agent/pkg/util/log.CriticalStackDepth
- github.com/DataDog/datadog-agent/pkg/util/log.Error
- github.com/DataDog/datadog-agent/pkg/util/log.Errorc
- github.com/DataDog/datadog-agent/pkg/util/log.Errorf
- github.com/DataDog/datadog-agent/pkg/util/log.ErrorStackDepth
- github.com/DataDog/datadog-agent/pkg/util/log.JMXError
- github.com/DataDog/datadog-agent/pkg/util/log.logContextWithError
- github.com/DataDog/datadog-agent/pkg/util/log.logFormatWithError
- github.com/DataDog/datadog-agent/pkg/util/log.Warn
- github.com/DataDog/datadog-agent/pkg/util/log.Warnc
- github.com/DataDog/datadog-agent/pkg/util/log.Warnf
- github.com/DataDog/datadog-agent/pkg/util/log.WarnStackDepth
- golang.org/x/sys/windows.CloseHandle
- golang.org/x/sys/windows.FreeLibrary
- golang.org/x/sys/windows.FreeSid
- golang.org/x/sys/windows.LocalFree
- golang.org/x/sys/windows.RegCloseKey
- golang.org/x/sys/windows.SetEvent
- golang.org/x/sys/windows/registry.Close
- golang.org/x/sys/windows/svc/debug.Close
- golang.org/x/sys/windows/svc/debug.Error
- golang.org/x/sys/windows/svc/debug.Info
- golang.org/x/sys/windows/svc/debug.Warning
- pkg/util/log.JMXError
- syscall.CloseHandle
staticcheck:
checks: ["all",
"-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", # These ones are disabled by default on staticcheck
"-ST1013", # Use HTTP code enums instead of integers
# Actual issues that should be fixed eventually
"-SA6002", # TODO: Fix sync.Pools
"-SA4025", # TODO: Fix trace unit test
"-SA4011", "-SA4031" # Disabling these to re-enable golanci-lint default tests
"-SA4011", "-SA4031", # Disabling these to re-enable golanci-lint default tests
"-SA4023" # Fix the lint_macos_gitlab_amd64 linter discrepancy while we find the issue (see https://github.com/dominikh/go-tools/issues/847)
]
govet:
settings:
Expand All @@ -124,11 +174,11 @@ linters-settings:
revive:
# in order to change revive config, the default configuration must be explicitly defined
# https://github.com/mgechev/revive/blob/master/defaults.toml
ignoreGeneratedHeader: false
#
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml for the golangci-lint config syntax
ignore-generated-header: false
severity: "warning"
confidence: 0.8
errorCode: 0
warningCode: 0
rules:
- name: blank-imports
- name: context-as-argument
Expand All @@ -150,7 +200,9 @@ linters-settings:
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
# - name: unused-parameter
# arguments:
# - allowRegex: "^_"
- name: var-declaration
- name: var-naming
# non-default rules:
Expand Down
6 changes: 3 additions & 3 deletions cmd/cluster-agent/api/v1/languagedetection/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ func (ownersLanguages *OwnersLanguages) handleKubeAPIServerUnsetEvents(events []
case workloadmeta.KindKubernetesDeployment:
// extract deployment name and namespace from entity id
deployment := event.Entity.(*workloadmeta.KubernetesDeployment)
deploymentIds := strings.Split(deployment.GetID().ID, "/")
namespace := deploymentIds[0]
deploymentName := deploymentIds[1]
deploymentIDs := strings.Split(deployment.GetID().ID, "/")
namespace := deploymentIDs[0]
deploymentName := deploymentIDs[1]
delete(ownersLanguages.containersLanguages, langUtil.NewNamespacedOwnerReference("apps/v1", langUtil.KindDeployment, deploymentName, namespace))
_ = wlm.Push(workloadmeta.SourceLanguageDetectionServer, workloadmeta.Event{
Type: workloadmeta.EventTypeUnset,
Expand Down
Loading

0 comments on commit a12f04a

Please sign in to comment.