Skip to content

Commit

Permalink
Merge pull request #13580 from vrothberg/enable-linters
Browse files Browse the repository at this point in the history
enable linters
  • Loading branch information
openshift-merge-robot authored Mar 22, 2022
2 parents fc96315 + 06dd913 commit 901066a
Show file tree
Hide file tree
Showing 74 changed files with 218 additions and 182 deletions.
10 changes: 2 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ linters:
enable-all: true
disable:
# All these break for one reason or another
- nolintlint
- nolintlint # some linter must be disabled (see `nolint` in the code)
- tagliatelle # too many JSON keys cannot be changed due to compat
- gocognit
- testpackage
- goerr113
Expand All @@ -38,7 +39,6 @@ linters:
- gofumpt
- gci
- godot
- makezero
- dupl
- funlen
- gochecknoglobals
Expand All @@ -58,16 +58,10 @@ linters:
- cyclop
- errname
- forcetypeassert
- ineffassign
- ireturn
- tagliatelle
- varnamelen
- errchkjson
- maintidx
- nilerr
- wastedassign
- nilnil
- interfacer
linters-settings:
errcheck:
check-blank: false
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
"Optional parent cgroup for the container",
)
_ = cmd.RegisterFlagCompletionFunc(cgroupParentFlagName, completion.AutocompleteDefault)
conmonPidfileFlagName := ""
var conmonPidfileFlagName string
if !isInfra {
conmonPidfileFlagName = "conmon-pidfile"
} else {
Expand All @@ -734,7 +734,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
)
_ = cmd.RegisterFlagCompletionFunc(conmonPidfileFlagName, completion.AutocompleteDefault)

entrypointFlagName := ""
var entrypointFlagName string
if !isInfra {
entrypointFlagName = "entrypoint"
} else {
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/containers/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ func clone(cmd *cobra.Command, args []string) error {
case 3:
ctrClone.CreateOpts.Name = args[1]
ctrClone.Image = args[2]
rawImageName := ""
if !cliVals.RootFS {
rawImageName = args[0]
rawImageName := args[0]
name, err := PullImage(ctrClone.Image, ctrClone.CreateOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func resolvePathOnDestinationContainer(container string, containerPath string, i
containerInfo, err = registry.ContainerEngine().ContainerStat(registry.GetContext(), container, containerPath)
if err == nil {
baseName = filepath.Base(containerInfo.LinkTarget)
return
return // nolint: nilerr
}

if strings.HasSuffix(containerPath, "/") {
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
}
}

cleanTmpFile := false
var cleanTmpFile bool
flags.Authfile, cleanTmpFile = buildahUtil.MirrorToTempFileIfPathIsDescriptor(flags.Authfile)
if cleanTmpFile {
defer os.Remove(flags.Authfile)
Expand Down Expand Up @@ -474,7 +474,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
return nil, err
}

format := ""
var format string
flags.Format = strings.ToLower(flags.Format)
switch {
case strings.HasPrefix(flags.Format, buildahDefine.OCI):
Expand Down
10 changes: 6 additions & 4 deletions cmd/podman/images/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func scp(cmd *cobra.Command, args []string) (finalErr error) {
}
locations := []*entities.ImageScpOptions{}
cliConnections := []string{}
flipConnections := false
var flipConnections bool
for _, arg := range args {
loc, connect, err := parseImageSCPArg(arg)
if err != nil {
Expand Down Expand Up @@ -233,7 +233,7 @@ func loadToRemote(localFile string, tag string, url *urlP.URL, iden string) (str
errOut := strconv.Itoa(int(n)) + " Bytes copied before error"
return " ", errors.Wrapf(err, errOut)
}
run := ""
var run string
if tag != "" {
return "", errors.Wrapf(define.ErrInvalidArg, "Renaming of an image is currently not supported")
}
Expand Down Expand Up @@ -264,10 +264,12 @@ func saveToRemote(image, localFile string, tag string, uri *urlP.URL, iden strin
run := podman + " image save " + image + " --format=oci-archive --output=" + remoteFile // run ssh image load of the file copied via scp. Files are reverse in this case...
_, err = connection.ExecRemoteCommand(dial, run)
if err != nil {
return nil
return err
}
n, err := scpD.CopyFrom(dial, remoteFile, localFile)
connection.ExecRemoteCommand(dial, "rm "+remoteFile)
if _, conErr := connection.ExecRemoteCommand(dial, "rm "+remoteFile); conErr != nil {
logrus.Errorf("Error removing file on endpoint: %v", conErr)
}
if err != nil {
errOut := strconv.Itoa(int(n)) + " Bytes copied before error"
return errors.Wrapf(err, errOut)
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func searchFlags(cmd *cobra.Command) {

// imageSearch implements the command for searching images.
func imageSearch(cmd *cobra.Command, args []string) error {
searchTerm := ""
var searchTerm string
switch len(args) {
case 1:
searchTerm = args[0]
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/machine/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func init() {
"reexec", false,
"process was rexeced",
)
flags.MarkHidden("reexec")
_ = flags.MarkHidden("reexec")

ImagePathFlagName := "image-path"
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/networks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func networkCreateFlags(cmd *cobra.Command) {
macvlanFlagName := "macvlan"
flags.StringVar(&networkCreateOptions.MacVLAN, macvlanFlagName, "", "create a Macvlan connection based on this device")
// This option is deprecated
flags.MarkHidden(macvlanFlagName)
_ = flags.MarkHidden(macvlanFlagName)

labelFlagName := "label"
flags.StringArrayVar(&labels, labelFlagName, nil, "set metadata on a network")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/parse/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "regexp"

var jsonFormatRegex = regexp.MustCompile(`^\s*(json|{{\s*json\s*(\.)?\s*}})\s*$`)

// MatchesJSONFormat test CLI --format string to be a JSON request
// MatchesJSONFormat test CLI --format string to be a JSON request.
func MatchesJSONFormat(s string) bool {
return jsonFormatRegex.Match([]byte(s))
}
2 changes: 1 addition & 1 deletion cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
networkBackendFlagName := "network-backend"
pFlags.StringVar(&cfg.Network.NetworkBackend, networkBackendFlagName, cfg.Network.NetworkBackend, `Network backend to use ("cni"|"netavark")`)
_ = cmd.RegisterFlagCompletionFunc(networkBackendFlagName, common.AutocompleteNetworkBackend)
pFlags.MarkHidden(networkBackendFlagName)
_ = pFlags.MarkHidden(networkBackendFlagName)

rootFlagName := "root"
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, "", "Path to the root directory in which data, including images, is stored")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/connection/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func getUDS(cmd *cobra.Command, uri *url.URL, iden string) (string, error) {

// ValidateAndConfigure will take a ssh url and an identity key (rsa and the like) and ensure the information given is valid
// iden iden can be blank to mean no identity key
// once the function validates the information it creates and returns an ssh.ClientConfig
// once the function validates the information it creates and returns an ssh.ClientConfig.
func ValidateAndConfigure(uri *url.URL, iden string) (*ssh.ClientConfig, error) {
var signers []ssh.Signer
passwd, passwdSet := uri.User.Password()
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/connection/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var (
// Skip creating engines since this command will obtain connection information to said engines
// Skip creating engines since this command will obtain connection information to said engines.
dfltCmd = &cobra.Command{
Use: "default NAME",
Args: cobra.ExactArgs(1),
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/connection/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
// Skip creating engines since this command will obtain connection information to said engines
// Skip creating engines since this command will obtain connection information to said engines.
rmCmd = &cobra.Command{
Use: "remove [options] NAME",
Aliases: []string{"rm"},
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/system/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func printVerbose(cmd *cobra.Command, reports *entities.SystemDfReport) error {
return err
}
if err := writeTemplate(rpt, hdrs, dfImages); err != nil {
return nil
return err
}

fmt.Fprint(rpt.Writer(), "\nContainers space usage:\n\n")
Expand All @@ -191,7 +191,7 @@ func printVerbose(cmd *cobra.Command, reports *entities.SystemDfReport) error {
return err
}
if err := writeTemplate(rpt, hdrs, dfContainers); err != nil {
return nil
return err
}

fmt.Fprint(rpt.Writer(), "\nLocal Volumes space usage:\n\n")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {

flags.StringVarP(&srvArgs.PProfAddr, "pprof-address", "", "",
"Binding network address for pprof profile endpoints, default: do not expose endpoints")
flags.MarkHidden("pprof-address")
_ = flags.MarkHidden("pprof-address")
}

func aliasTimeoutFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/validate/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func SubCommandExists(cmd *cobra.Command, args []string) error {
}
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()
cmd.Help() // nolint: errcheck
return errors.Errorf("missing command '%[1]s COMMAND'", cmd.CommandPath())
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/rootlessport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ func serve(listener net.Listener, pm rkport.Manager) {
ctx := context.TODO()
err = handler(ctx, conn, pm)
if err != nil {
conn.Write([]byte(err.Error()))
_, _ = conn.Write([]byte(err.Error()))
} else {
conn.Write([]byte("OK"))
_, _ = conn.Write([]byte("OK"))
}
conn.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion libpod/boltdb_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (s *BoltState) GetDBConfig() (*DBConfig, error) {
err = db.View(func(tx *bolt.Tx) error {
configBucket, err := getRuntimeConfigBucket(tx)
if err != nil {
return nil
return err
}

// Some of these may be nil
Expand Down
6 changes: 3 additions & 3 deletions libpod/common/common.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package common

// IsTrue determines whether the given string equals "true"
// IsTrue determines whether the given string equals "true".
func IsTrue(str string) bool {
return str == "true"
}

// IsFalse determines whether the given string equals "false"
// IsFalse determines whether the given string equals "false".
func IsFalse(str string) bool {
return str == "false"
}

// IsValidBool determines whether the given string equals "true" or "false"
// IsValidBool determines whether the given string equals "true" or "false".
func IsValidBool(str string) bool {
return IsTrue(str) || IsFalse(str)
}
6 changes: 5 additions & 1 deletion libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,11 @@ func (c *Container) Stat(ctx context.Context, containerPath string) (*define.Fil
if err != nil {
return nil, err
}
defer c.unmount(false)
defer func() {
if err := c.unmount(false); err != nil {
logrus.Errorf("Unmounting container %s: %v", c.ID(), err)
}
}()
}

info, _, _, err := c.stat(ctx, mountPoint, containerPath)
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ func (c *Container) generateUserGroupEntry(addedGID int) (string, int, error) {

gid, err := strconv.ParseUint(group, 10, 32)
if err != nil {
return "", 0, nil
return "", 0, nil // nolint: nilerr
}

if addedGID != 0 && addedGID == int(gid) {
Expand Down Expand Up @@ -2740,7 +2740,7 @@ func (c *Container) generateUserPasswdEntry(addedUID int) (string, int, int, err
// If a non numeric User, then don't generate passwd
uid, err := strconv.ParseUint(userspec, 10, 32)
if err != nil {
return "", 0, 0, nil
return "", 0, 0, nil // nolint: nilerr
}

if addedUID != 0 && int(uid) == addedUID {
Expand Down
5 changes: 4 additions & 1 deletion libpod/events/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage/pkg/lockfile"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// EventLogFile is the structure for event writing to a logfile. It contains the eventer
Expand Down Expand Up @@ -59,7 +60,9 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
}
go func() {
time.Sleep(time.Until(untilTime))
t.Stop()
if err := t.Stop(); err != nil {
logrus.Errorf("Stopping logger: %v", err)
}
}()
}
funcDone := make(chan bool)
Expand Down
2 changes: 1 addition & 1 deletion libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ func (c *Container) inspectJoinedNetworkNS(networkns string) (q types.StatusBloc
// result
func resultToBasicNetworkConfig(result types.StatusBlock) (define.InspectBasicNetworkConfig, error) {
config := define.InspectBasicNetworkConfig{}
interfaceNames := make([]string, len(result.Interfaces))
interfaceNames := make([]string, 0, len(result.Interfaces))
for interfaceName := range result.Interfaces {
interfaceNames = append(interfaceNames, interfaceName)
}
Expand Down
7 changes: 4 additions & 3 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func openControlFile(ctr *Container, parentDir string) (*os.File, error) {
for i := 0; i < 600; i++ {
controlFile, err := os.OpenFile(controlPath, unix.O_WRONLY|unix.O_NONBLOCK, 0)
if err == nil {
return controlFile, err
return controlFile, nil
}
if !isRetryable(err) {
return nil, errors.Wrapf(err, "could not open ctl file for terminal resize for container %s", ctr.ID())
Expand Down Expand Up @@ -1015,7 +1015,8 @@ func (r *ConmonOCIRuntime) getLogTag(ctr *Container) (string, error) {
}
data, err := ctr.inspectLocked(false)
if err != nil {
return "", nil
// FIXME: this error should probably be returned
return "", nil // nolint: nilerr
}
tmpl, err := template.New("container").Parse(logTag)
if err != nil {
Expand Down Expand Up @@ -1596,7 +1597,7 @@ func readConmonPipeData(runtimeName string, pipe *os.File, ociLog string) (int,
ch <- syncStruct{si: si}
}()

data := -1
data := -1 //nolint: wastedassign
select {
case ss := <-ch:
if ss.err != nil {
Expand Down
Loading

0 comments on commit 901066a

Please sign in to comment.