Merge pull request #13973 from Luap99/linter-revive

replace golint with revive linter
This commit is contained in:
OpenShift Merge Robot
2022-04-23 06:32:41 -04:00
committed by GitHub
31 changed files with 59 additions and 53 deletions

View File

@ -51,7 +51,6 @@ linters:
- gosec - gosec
- maligned - maligned
- gomoddirectives - gomoddirectives
- revive
- containedctx - containedctx
- contextcheck - contextcheck
- cyclop - cyclop
@ -61,6 +60,10 @@ linters:
- varnamelen - varnamelen
- maintidx - maintidx
- nilnil - nilnil
# deprecated linters
- golint # replaced by revive
- scopelint # replaced by exportloopref
- interfacer
linters-settings: linters-settings:
errcheck: errcheck:
check-blank: false check-blank: false

View File

@ -225,7 +225,7 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
h.ImageSummary = *e h.ImageSummary = *e
h.Repository, h.Tag, err = tokenRepoTag(tag) h.Repository, h.Tag, err = tokenRepoTag(tag)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error parsing repository tag %q:", tag) return nil, errors.Wrapf(err, "error parsing repository tag: %q", tag)
} }
if h.Tag == "<none>" { if h.Tag == "<none>" {
untagged = append(untagged, h) untagged = append(untagged, h)

View File

@ -91,7 +91,7 @@ func load(cmd *cobra.Command, args []string) error {
} }
} else { } else {
if term.IsTerminal(int(os.Stdin.Fd())) { if term.IsTerminal(int(os.Stdin.Fd())) {
return errors.Errorf("cannot read from terminal. Use command-line redirection or the --input flag.") return errors.Errorf("cannot read from terminal, use command-line redirection or the --input flag")
} }
outFile, err := ioutil.TempFile(util.Tmpdir(), "podman") outFile, err := ioutil.TempFile(util.Tmpdir(), "podman")
if err != nil { if err != nil {

View File

@ -23,9 +23,9 @@ func SubCommandExists(cmd *cobra.Command, args []string) error {
if len(args) > 0 { if len(args) > 0 {
suggestions := cmd.SuggestionsFor(args[0]) suggestions := cmd.SuggestionsFor(args[0])
if len(suggestions) == 0 { if len(suggestions) == 0 {
return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0]) return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information", cmd.CommandPath(), args[0])
} }
return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t")) return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t"))
} }
cmd.Help() // nolint: errcheck cmd.Help() // nolint: errcheck
return errors.Errorf("missing command '%[1]s COMMAND'", cmd.CommandPath()) return errors.Errorf("missing command '%[1]s COMMAND'", cmd.CommandPath())

View File

@ -79,11 +79,11 @@ type ExecConfig struct {
type ExecSession struct { type ExecSession struct {
// Id is the ID of the exec session. // Id is the ID of the exec session.
// Named somewhat strangely to not conflict with ID(). // Named somewhat strangely to not conflict with ID().
// nolint:stylecheck,golint // nolint:stylecheck,revive
Id string `json:"id"` Id string `json:"id"`
// ContainerId is the ID of the container this exec session belongs to. // ContainerId is the ID of the container this exec session belongs to.
// Named somewhat strangely to not conflict with ContainerID(). // Named somewhat strangely to not conflict with ContainerID().
// nolint:stylecheck,golint // nolint:stylecheck,revive
ContainerId string `json:"containerId"` ContainerId string `json:"containerId"`
// State is the state of the exec session. // State is the state of the exec session.

View File

@ -266,7 +266,7 @@ func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr err
if c.ensureState(define.ContainerStateRunning, define.ContainerStatePaused) { if c.ensureState(define.ContainerStateRunning, define.ContainerStatePaused) {
return false, nil return false, nil
} else if c.state.State == define.ContainerStateUnknown { } else if c.state.State == define.ContainerStateUnknown {
return false, errors.Wrapf(define.ErrInternal, "invalid container state encountered in restart attempt!") return false, errors.Wrapf(define.ErrInternal, "invalid container state encountered in restart attempt")
} }
c.newContainerEvent(events.Restart) c.newContainerEvent(events.Restart)

View File

@ -3134,7 +3134,7 @@ func (c *Container) getOCICgroupPath() (string, error) {
} }
func (c *Container) copyTimezoneFile(zonePath string) (string, error) { func (c *Container) copyTimezoneFile(zonePath string) (string, error) {
var localtimeCopy string = filepath.Join(c.state.RunDir, "localtime") localtimeCopy := filepath.Join(c.state.RunDir, "localtime")
file, err := os.Stat(zonePath) file, err := os.Stat(zonePath)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -213,7 +213,7 @@ type YAMLContainer struct {
func ConvertV1PodToYAMLPod(pod *v1.Pod) *YAMLPod { func ConvertV1PodToYAMLPod(pod *v1.Pod) *YAMLPod {
cs := []*YAMLContainer{} cs := []*YAMLContainer{}
for _, cc := range pod.Spec.Containers { for _, cc := range pod.Spec.Containers {
var res *v1.ResourceRequirements = nil var res *v1.ResourceRequirements
if len(cc.Resources.Limits) > 0 || len(cc.Resources.Requests) > 0 { if len(cc.Resources.Limits) > 0 || len(cc.Resources.Requests) > 0 {
res = &cc.Resources res = &cc.Resources
} }

View File

@ -49,7 +49,7 @@ type InMemoryManager struct {
// of locks. // of locks.
func NewInMemoryManager(numLocks uint32) (Manager, error) { func NewInMemoryManager(numLocks uint32) (Manager, error) {
if numLocks == 0 { if numLocks == 0 {
return nil, errors.Errorf("must provide a non-zero number of locks!") return nil, errors.Errorf("must provide a non-zero number of locks")
} }
manager := new(InMemoryManager) manager := new(InMemoryManager)

View File

@ -2,7 +2,6 @@ package compat
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"os" "os"
@ -28,7 +27,7 @@ func Archive(w http.ResponseWriter, r *http.Request) {
case http.MethodHead, http.MethodGet: case http.MethodHead, http.MethodGet:
handleHeadAndGet(w, r, decoder, runtime) handleHeadAndGet(w, r, decoder, runtime)
default: default:
utils.Error(w, http.StatusNotImplemented, errors.New(fmt.Sprintf("unsupported method: %v", r.Method))) utils.Error(w, http.StatusNotImplemented, errors.Errorf("unsupported method: %v", r.Method))
} }
} }

View File

@ -45,7 +45,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
// need to check for memory limit to adjust swap // need to check for memory limit to adjust swap
if sg.ResourceLimits != nil && sg.ResourceLimits.Memory != nil { if sg.ResourceLimits != nil && sg.ResourceLimits.Memory != nil {
s := "" s := ""
var l int64 = 0 var l int64
if sg.ResourceLimits.Memory.Swap != nil { if sg.ResourceLimits.Memory.Swap != nil {
s = strconv.Itoa(int(*sg.ResourceLimits.Memory.Swap)) s = strconv.Itoa(int(*sg.ResourceLimits.Memory.Swap))
} }

View File

@ -289,7 +289,7 @@ func sshClient(_url *url.URL, secure bool, passPhrase string, identity string) (
}, },
) )
if err != nil { if err != nil {
return Connection{}, errors.Wrapf(err, "Connection to bastion host (%s) failed.", _url.String()) return Connection{}, errors.Wrapf(err, "connection to bastion host (%s) failed", _url.String())
} }
connection := Connection{URI: _url} connection := Connection{URI: _url}

View File

@ -51,7 +51,7 @@ var (
shortName: "busybox", shortName: "busybox",
tarballName: "busybox.tar", tarballName: "busybox.tar",
} }
CACHE_IMAGES = []testImage{alpine, busybox} //nolint:golint,stylecheck CACHE_IMAGES = []testImage{alpine, busybox} //nolint:revive,stylecheck
) )
type bindingTest struct { type bindingTest struct {

View File

@ -22,7 +22,7 @@ type NetworkReloadOptions struct {
// NetworkReloadReport describes the results of reloading a container network. // NetworkReloadReport describes the results of reloading a container network.
type NetworkReloadReport struct { type NetworkReloadReport struct {
// nolint:stylecheck,golint // nolint:stylecheck,revive
Id string Id string
Err error Err error
} }

View File

@ -270,7 +270,7 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
invalidPolicyNames = append(invalidPolicyNames, policy) invalidPolicyNames = append(invalidPolicyNames, policy)
} }
} }
var filterValueError error = nil var filterValueError error
if len(invalidPolicyNames) > 0 { if len(invalidPolicyNames) > 0 {
errPrefix := "invalid restart policy" errPrefix := "invalid restart policy"
if len(invalidPolicyNames) > 1 { if len(invalidPolicyNames) > 1 {

View File

@ -110,6 +110,10 @@ func (ir *ImageEngine) remoteManifestInspect(ctx context.Context, name string) (
if latestErr == nil { if latestErr == nil {
latestErr = e latestErr = e
} else { } else {
// FIXME should we use multierror package instead?
// we want the new line here so ignore the linter
//nolint:revive
latestErr = errors.Wrapf(latestErr, "tried %v\n", e) latestErr = errors.Wrapf(latestErr, "tried %v\n", e)
} }
} }

View File

@ -84,7 +84,7 @@ func (ir *ImageEngine) SetTrust(ctx context.Context, args []string, options enti
policyContentStruct.Default = newReposContent policyContentStruct.Default = newReposContent
} else { } else {
if len(policyContentStruct.Default) == 0 { if len(policyContentStruct.Default) == 0 {
return errors.Errorf("Default trust policy must be set.") return errors.Errorf("default trust policy must be set")
} }
registryExists := false registryExists := false
for transport, transportval := range policyContentStruct.Transports { for transport, transportval := range policyContentStruct.Transports {

View File

@ -26,7 +26,7 @@ func (rn ResourceName) String() string {
} }
// Cpu returns the Cpu limit if specified. // Cpu returns the Cpu limit if specified.
// nolint:golint,stylecheck //nolint:revive,stylecheck
func (rl *ResourceList) Cpu() *resource.Quantity { func (rl *ResourceList) Cpu() *resource.Quantity {
return rl.Name(ResourceCPU, resource.DecimalSI) return rl.Name(ResourceCPU, resource.DecimalSI)
} }

View File

@ -138,7 +138,7 @@ const (
var ( var (
// Errors that could happen while parsing a string. // Errors that could happen while parsing a string.
// nolint:golint //nolint:revive
ErrFormatWrong = errors.New("quantities must match the regular expression '" + splitREString + "'") ErrFormatWrong = errors.New("quantities must match the regular expression '" + splitREString + "'")
ErrNumeric = errors.New("unable to parse numeric part of quantity") ErrNumeric = errors.New("unable to parse numeric part of quantity")
ErrSuffix = errors.New("unable to parse quantity's suffix") ErrSuffix = errors.New("unable to parse quantity's suffix")

View File

@ -26,8 +26,8 @@ import (
// These should eventually be moved into machine/qemu as // These should eventually be moved into machine/qemu as
// they are specific to running qemu // they are specific to running qemu
var ( var (
artifact string = "qemu" artifact = "qemu"
Format string = "qcow2.xz" Format = "qcow2.xz"
) )
const ( const (

View File

@ -162,7 +162,7 @@ type Monitor struct {
var ( var (
// defaultQMPTimeout is the timeout duration for the // defaultQMPTimeout is the timeout duration for the
// qmp monitor interactions. // qmp monitor interactions.
defaultQMPTimeout time.Duration = 2 * time.Second defaultQMPTimeout = 2 * time.Second
) )
// GetPath returns the working path for a machinefile. it returns // GetPath returns the working path for a machinefile. it returns

View File

@ -907,7 +907,7 @@ func (v *MachineVM) SSH(_ string, opts machine.SSHOptions) error {
return err return err
} }
if state != machine.Running { if state != machine.Running {
return errors.Errorf("vm %q is not running.", v.Name) return errors.Errorf("vm %q is not running", v.Name)
} }
username := opts.Username username := opts.Username

View File

@ -11,7 +11,7 @@ import (
// KubeSeccompPaths holds information about a pod YAML's seccomp configuration // KubeSeccompPaths holds information about a pod YAML's seccomp configuration
// it holds both container and pod seccomp paths // it holds both container and pod seccomp paths
// nolint:golint //nolint:revive
type KubeSeccompPaths struct { type KubeSeccompPaths struct {
containerPaths map[string]string containerPaths map[string]string
podPath string podPath string

View File

@ -17,7 +17,7 @@ const (
kubeFilePermission = 0644 kubeFilePermission = 0644
) )
// nolint:golint //nolint:revive
type KubeVolumeType int type KubeVolumeType int
const ( const (
@ -26,7 +26,7 @@ const (
KubeVolumeTypeConfigMap KubeVolumeType = iota KubeVolumeTypeConfigMap KubeVolumeType = iota
) )
// nolint:golint //nolint:revive
type KubeVolume struct { type KubeVolume struct {
// Type of volume to create // Type of volume to create
Type KubeVolumeType Type KubeVolumeType

View File

@ -231,14 +231,14 @@ func ParseNamespace(ns string) (Namespace, error) {
case strings.HasPrefix(ns, "ns:"): case strings.HasPrefix(ns, "ns:"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, errors.Errorf("must provide a path to a namespace when specifying ns:") return toReturn, errors.Errorf("must provide a path to a namespace when specifying \"ns:\"")
} }
toReturn.NSMode = Path toReturn.NSMode = Path
toReturn.Value = split[1] toReturn.Value = split[1]
case strings.HasPrefix(ns, "container:"): case strings.HasPrefix(ns, "container:"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, errors.Errorf("must provide name or ID or a container when specifying container:") return toReturn, errors.Errorf("must provide name or ID or a container when specifying \"container:\"")
} }
toReturn.NSMode = FromContainer toReturn.NSMode = FromContainer
toReturn.Value = split[1] toReturn.Value = split[1]
@ -349,14 +349,14 @@ func ParseNetworkNamespace(ns string, rootlessDefaultCNI bool) (Namespace, map[s
case strings.HasPrefix(ns, "ns:"): case strings.HasPrefix(ns, "ns:"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, nil, errors.Errorf("must provide a path to a namespace when specifying ns:") return toReturn, nil, errors.Errorf("must provide a path to a namespace when specifying \"ns:\"")
} }
toReturn.NSMode = Path toReturn.NSMode = Path
toReturn.Value = split[1] toReturn.Value = split[1]
case strings.HasPrefix(ns, string(FromContainer)+":"): case strings.HasPrefix(ns, string(FromContainer)+":"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, nil, errors.Errorf("must provide name or ID or a container when specifying container:") return toReturn, nil, errors.Errorf("must provide name or ID or a container when specifying \"container:\"")
} }
toReturn.NSMode = FromContainer toReturn.NSMode = FromContainer
toReturn.Value = split[1] toReturn.Value = split[1]
@ -427,14 +427,14 @@ func ParseNetworkFlag(networks []string) (Namespace, map[string]types.PerNetwork
case strings.HasPrefix(ns, "ns:"): case strings.HasPrefix(ns, "ns:"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, nil, nil, errors.Errorf("must provide a path to a namespace when specifying ns:") return toReturn, nil, nil, errors.Errorf("must provide a path to a namespace when specifying \"ns:\"")
} }
toReturn.NSMode = Path toReturn.NSMode = Path
toReturn.Value = split[1] toReturn.Value = split[1]
case strings.HasPrefix(ns, string(FromContainer)+":"): case strings.HasPrefix(ns, string(FromContainer)+":"):
split := strings.SplitN(ns, ":", 2) split := strings.SplitN(ns, ":", 2)
if len(split) != 2 { if len(split) != 2 {
return toReturn, nil, nil, errors.Errorf("must provide name or ID or a container when specifying container:") return toReturn, nil, nil, errors.Errorf("must provide name or ID or a container when specifying \"container:\"")
} }
toReturn.NSMode = FromContainer toReturn.NSMode = FromContainer
toReturn.Value = split[1] toReturn.Value = split[1]

View File

@ -35,12 +35,12 @@ import (
var ( var (
//lint:ignore ST1003 //lint:ignore ST1003
PODMAN_BINARY string //nolint:golint,stylecheck PODMAN_BINARY string //nolint:revive,stylecheck
INTEGRATION_ROOT string //nolint:golint,stylecheck INTEGRATION_ROOT string //nolint:revive,stylecheck
CGROUP_MANAGER = "systemd" //nolint:golint,stylecheck CGROUP_MANAGER = "systemd" //nolint:revive,stylecheck
RESTORE_IMAGES = []string{ALPINE, BB, nginx} //nolint:golint,stylecheck RESTORE_IMAGES = []string{ALPINE, BB, nginx} //nolint:revive,stylecheck
defaultWaitTimeout = 90 defaultWaitTimeout = 90
CGROUPSV2, _ = cgroups.IsCgroup2UnifiedMode() //nolint:golint,stylecheck CGROUPSV2, _ = cgroups.IsCgroup2UnifiedMode() //nolint:revive,stylecheck
) )
// PodmanTestIntegration struct for command line options // PodmanTestIntegration struct for command line options

View File

@ -1,16 +1,16 @@
package integration package integration
var ( var (
STORAGE_FS = "vfs" //nolint:golint,stylecheck STORAGE_FS = "vfs" //nolint:revive,stylecheck
STORAGE_OPTIONS = "--storage-driver vfs" //nolint:golint,stylecheck STORAGE_OPTIONS = "--storage-driver vfs" //nolint:revive,stylecheck
ROOTLESS_STORAGE_FS = "vfs" //nolint:golint,stylecheck ROOTLESS_STORAGE_FS = "vfs" //nolint:revive,stylecheck
ROOTLESS_STORAGE_OPTIONS = "--storage-driver vfs" //nolint:golint,stylecheck ROOTLESS_STORAGE_OPTIONS = "--storage-driver vfs" //nolint:revive,stylecheck
CACHE_IMAGES = []string{ALPINE, BB, fedoraMinimal, nginx, redis, registry, infra, labels, healthcheck, UBI_INIT, UBI_MINIMAL, fedoraToolbox} //nolint:golint,stylecheck CACHE_IMAGES = []string{ALPINE, BB, fedoraMinimal, nginx, redis, registry, infra, labels, healthcheck, UBI_INIT, UBI_MINIMAL, fedoraToolbox} //nolint:revive,stylecheck
nginx = "quay.io/libpod/alpine_nginx:latest" nginx = "quay.io/libpod/alpine_nginx:latest"
BB_GLIBC = "docker.io/library/busybox:glibc" //nolint:golint,stylecheck BB_GLIBC = "docker.io/library/busybox:glibc" //nolint:revive,stylecheck
registry = "quay.io/libpod/registry:2.6" registry = "quay.io/libpod/registry:2.6"
labels = "quay.io/libpod/alpine_labels:latest" labels = "quay.io/libpod/alpine_labels:latest"
UBI_MINIMAL = "registry.access.redhat.com/ubi8-minimal" //nolint:golint,stylecheck UBI_MINIMAL = "registry.access.redhat.com/ubi8-minimal" //nolint:revive,stylecheck
UBI_INIT = "registry.access.redhat.com/ubi8-init" //nolint:golint,stylecheck UBI_INIT = "registry.access.redhat.com/ubi8-init" //nolint:revive,stylecheck
cirros = "quay.io/libpod/cirros:latest" cirros = "quay.io/libpod/cirros:latest"
) )

View File

@ -75,7 +75,7 @@ function teardown() {
@test "podman load - will not read from tty" { @test "podman load - will not read from tty" {
run_podman 125 load <$PODMAN_TEST_PTY run_podman 125 load <$PODMAN_TEST_PTY
is "$output" \ is "$output" \
"Error: cannot read from terminal. Use command-line redirection or the --input flag." \ "Error: cannot read from terminal, use command-line redirection or the --input flag" \
"Diagnostic from 'podman load' without redirection or -i" "Diagnostic from 'podman load' without redirection or -i"
} }

View File

@ -31,7 +31,7 @@ type cliConfig struct {
} }
// Default configuration is stored here. Will be overwritten by flags. // Default configuration is stored here. Will be overwritten by flags.
var config cliConfig = cliConfig{ var config = cliConfig{
logLevel: "error", logLevel: "error",
sockName: "test-volume-plugin", sockName: "test-volume-plugin",
} }

View File

@ -6,7 +6,7 @@ import (
"net/url" "net/url"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
. "github.com/onsi/gomega" //nolint:golint,stylecheck . "github.com/onsi/gomega" //nolint:revive,stylecheck
"github.com/onsi/gomega/format" "github.com/onsi/gomega/format"
"github.com/onsi/gomega/gexec" "github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/matchers" "github.com/onsi/gomega/matchers"

View File

@ -15,9 +15,9 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/containers/storage/pkg/parsers/kernel" "github.com/containers/storage/pkg/parsers/kernel"
. "github.com/onsi/ginkgo" //nolint:golint,stylecheck . "github.com/onsi/ginkgo" //nolint:revive,stylecheck
. "github.com/onsi/gomega" //nolint:golint,stylecheck . "github.com/onsi/gomega" //nolint:revive,stylecheck
. "github.com/onsi/gomega/gexec" //nolint:golint,stylecheck . "github.com/onsi/gomega/gexec" //nolint:revive,stylecheck
) )
type NetworkBackend int type NetworkBackend int