From 6659e3d62a6065ae74f4f29272e0286b8ed73934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Mon, 7 Nov 2022 11:34:05 +0100 Subject: [PATCH] chore: Use depguard instead of revive.imports-blacklist (#12153) --- .golangci.yml | 53 +++++++++++++++++++++++++--------- plugins/common/logrus/hook.go | 2 +- plugins/common/shim/config.go | 3 +- plugins/common/shim/logger.go | 2 +- plugins/inputs/snmp/netsnmp.go | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 725e204d7..2e3663530 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,7 @@ linters: - asasalint - bidichk - bodyclose + - depguard - dogsled - exportloopref - errcheck @@ -25,6 +26,45 @@ linters: - unused linters-settings: + depguard: + # Kind of list is passed in. + # Allowed values: allowlist|denylist + # Default: denylist + list-type: denylist + # Check the list against standard lib. + # Default: false + include-go-root: true + # A list of packages for the list type specified. + # Can accept both string prefixes and string glob patterns. + # Default: [] + packages: + - log + # A list of packages for the list type specified. + # Specify an error message to output when a denied package is used. + # Default: [] + packages-with-error-message: + - log: 'Use injected telegraf.Logger instead' + # Specify rules by which the linter ignores certain files for consideration. + # Can accept both string prefixes and string glob patterns. + # The ! character in front of the rule is a special character + # which signals that the linter should negate the rule. + # This allows for more precise control, but it is only available for glob patterns. + # Default: [] + ignore-file-rules: + - "**/agent/**" + - "**/cmd/**" + - "**/config/**" + - "**/filter/**" + - "**/internal/**" + - "**/logger/**" + - "**/metric/**" + - "**/models/**" + - "**/plugins/serializers/**" + - "**/scripts/**" + - "**/selfstat/**" + - "**/testutil/**" + - "**/tools/**" + - "**/*_test.go" revive: rules: - name: argument-limit @@ -50,13 +90,10 @@ linters-settings: - name: error-return - name: error-strings - name: errorf - # - name: flag-parameter #disable for now - name: function-result-limit arguments: [ 3 ] - name: identical-branches - name: if-return - - name: imports-blacklist - arguments: [ "log" ] - name: import-shadowing - name: increment-decrement - name: indent-error-flow @@ -100,8 +137,6 @@ run: - assets - docs - etc - - scripts - # - plugins/parsers/influx/machine.go # which files to skip: they will be analyzed, but issues from them # won't be reported. Default value is empty list, but there is @@ -127,14 +162,6 @@ issues: linters: - govet - - path: _test\.go - text: "parameter.*seems to be a control flag, avoid control coupling" - - - path: (^agent/|^cmd/|^config/|^filter/|^internal/|^logger/|^metric/|^models/|^selfstat/|^testutil/|^tools|^plugins/serializers/|^plugins/inputs/zipkin/cmd) - text: "imports-blacklist: should not use the following blacklisted import: \"log\"" - linters: - - revive - - path: cmd/telegraf/(main|printer).go text: "Error return value of `outputBuffer.Write` is not checked" diff --git a/plugins/common/logrus/hook.go b/plugins/common/logrus/hook.go index 84aae8fe8..71d6df655 100644 --- a/plugins/common/logrus/hook.go +++ b/plugins/common/logrus/hook.go @@ -2,7 +2,7 @@ package logrus import ( "io" - "log" //nolint:revive // Allow exceptional but valid use of log here. + "log" //nolint:depguard // Allow exceptional but valid use of log here. "strings" "sync" diff --git a/plugins/common/shim/config.go b/plugins/common/shim/config.go index ad08e08ea..a78bf81f7 100644 --- a/plugins/common/shim/config.go +++ b/plugins/common/shim/config.go @@ -3,10 +3,11 @@ package shim import ( "errors" "fmt" - "log" //nolint:revive // Allow exceptional but valid use of log here. + "log" //nolint:depguard // Allow exceptional but valid use of log here. "os" "github.com/BurntSushi/toml" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/outputs" diff --git a/plugins/common/shim/logger.go b/plugins/common/shim/logger.go index 74bfbfdef..71ae05b67 100644 --- a/plugins/common/shim/logger.go +++ b/plugins/common/shim/logger.go @@ -2,7 +2,7 @@ package shim import ( "fmt" - "log" //nolint:revive // Allow exceptional but valid use of log here. + "log" //nolint:depguard // Allow exceptional but valid use of log here. "os" "reflect" diff --git a/plugins/inputs/snmp/netsnmp.go b/plugins/inputs/snmp/netsnmp.go index 09f56ed4a..cd8cce7ac 100644 --- a/plugins/inputs/snmp/netsnmp.go +++ b/plugins/inputs/snmp/netsnmp.go @@ -4,7 +4,7 @@ import ( "bufio" "bytes" "fmt" - "log" //nolint:revive + "log" //nolint:depguard // Allow exceptional but valid use of log here. "os/exec" "strings" "sync"