Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint round #3 #3562

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
run:
build-tags:
- apparmor
- ostree
- seccomp
- selinux
concurrency: 6
deadline: 5m
skip-dirs:
- dependencies/*
- contrib
- test/e2e
- docs
- test/
- tracing
skip-files:
- iopodman.go
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
# dupl really overdid it; disabling
# - dupl
- errcheck
- gofmt
- gosimple
- govet
- ineffassign
- nakedret
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
# - gochecknoglobals
# - gochecknoinits
# - goconst
# - gocritic
# - gocyclo
# - goimports
# - golint
# - gosec
- interfacer
# - lll
# - maligned
# - misspell
# - prealloc
- scopelint
- stylecheck
- unconvert
# I think we should uncomment this one and used it
# - unparam
2 changes: 1 addition & 1 deletion cmd/podman/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func buildCmd(c *cliconfig.BuildValues) error {
// the urfavecli Tail method for args
func Tail(a []string) []string {
if len(a) >= 2 {
return []string(a)[1:]
return a[1:]
}
return []string{}
}
Expand Down
7 changes: 2 additions & 5 deletions cmd/podman/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest strin
if errors.Cause(err) != define.ErrCtrStateInvalid {
return err
}
} else if err == nil {
} else {
// Only add the defer if we actually paused
defer func() {
if err := ctr.Unpause(); err != nil {
Expand Down Expand Up @@ -486,10 +486,7 @@ func matchVolumePath(path, target string) bool {
for len(pathStr) > len(target) && strings.Contains(pathStr, string(os.PathSeparator)) {
pathStr = pathStr[:strings.LastIndex(pathStr, string(os.PathSeparator))]
}
if pathStr == target {
return true
}
return false
return pathStr == target
}

func pathWithBindMountSource(m specs.Mount, path string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ func diffCmd(c *cliconfig.DiffValues) error {
} else {
out = stdoutStruct{output: diffOutput}
}
return formats.Writer(out).Out()
return out.Out()
}
13 changes: 7 additions & 6 deletions cmd/podman/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ func (h *historyTemplateParams) headerMap() map[string]string {
}

// getHistorytemplateOutput gets the modified history information to be printed in human readable format
func getHistoryTemplateOutput(history []*image.History, opts historyOptions) (historyOutput []historyTemplateParams) {
func getHistoryTemplateOutput(history []*image.History, opts historyOptions) []historyTemplateParams {
var (
outputSize string
createdTime string
createdBy string
outputSize string
createdTime string
createdBy string
historyOutput []historyTemplateParams
)
for _, hist := range history {
imageID := hist.ID
Expand Down Expand Up @@ -175,7 +176,7 @@ func getHistoryTemplateOutput(history []*image.History, opts historyOptions) (hi
}
historyOutput = append(historyOutput, params)
}
return
return historyOutput
}

// generateHistoryOutput generates the history based on the format given
Expand All @@ -194,5 +195,5 @@ func generateHistoryOutput(history []*image.History, opts historyOptions) error
out = formats.StdoutTemplateArray{Output: historyToGeneric(historyOutput, []*image.History{}), Template: opts.format, Fields: historyOutput[0].headerMap()}
}

return formats.Writer(out).Out()
return out.Out()
}
7 changes: 4 additions & 3 deletions cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ func sortImagesOutput(sortBy string, imagesOutput imagesSorted) imagesSorted {
}

// getImagesTemplateOutput returns the images information to be printed in human readable format
func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerImage, opts imagesOptions) (imagesOutput imagesSorted) {
func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerImage, opts imagesOptions) imagesSorted {
var imagesOutput imagesSorted
for _, img := range images {
// If all is false and the image doesn't have a name, check to see if the top layer of the image is a parent
// to another image's top layer. If it is, then it is an intermediate image so don't print out if the --all flag
Expand Down Expand Up @@ -305,7 +306,7 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma

// Sort images by created time
sortImagesOutput(opts.sort, imagesOutput)
return
return imagesOutput
}

// getImagesJSONOutput returns the images information in its raw form
Expand Down Expand Up @@ -346,7 +347,7 @@ func generateImagesOutput(ctx context.Context, images []*adapter.ContainerImage,
imagesOutput := getImagesTemplateOutput(ctx, images, opts)
out = formats.StdoutTemplateArray{Output: imagesToGeneric(imagesOutput, []imagesJSONParams{}), Template: opts.outputformat, Fields: templateMap}
}
return formats.Writer(out).Out()
return out.Out()
}

// GenImageOutputMap generates the map used for outputting the images header
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func infoCmd(c *cliconfig.InfoValues) error {
out = formats.StdoutTemplate{Output: info, Template: infoOutputFormat}
}

return formats.Writer(out).Out()
return out.Out()
}

// top-level "debug" info
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func inspectCmd(c *cliconfig.InspectValues) error {
out = formats.JSONStructArray{Output: inspectedObjects}
}

return formats.Writer(out).Out()
return out.Out()
}

// func iterateInput iterates the images|containers the user has requested and returns the inspect data and error
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func podPauseCmd(c *cliconfig.PodPauseValues) error {
for _, p := range pauseIDs {
fmt.Println(p)
}
if conErrors != nil && len(conErrors) > 0 {
if len(conErrors) > 0 {
for ctr, err := range conErrors {
if lastError != nil {
logrus.Errorf("%q", lastError)
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,5 +561,5 @@ func generatePodPsOutput(pods []*adapter.Pod, opts podPsOptions) error {
out = formats.StdoutTemplateArray{Output: podPsToGeneric(psOutput, []podPsJSONParams{}), Template: opts.Format, Fields: psOutput[0].podHeaderMap()}
}

return formats.Writer(out).Out()
return out.Out()
}
2 changes: 1 addition & 1 deletion cmd/podman/pod_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func podRestartCmd(c *cliconfig.PodRestartValues) error {
for _, p := range restartIDs {
fmt.Println(p)
}
if conErrors != nil && len(conErrors) > 0 {
if len(conErrors) > 0 {
for ctr, err := range conErrors {
if lastError != nil {
logrus.Errorf("%q", lastError)
Expand Down
18 changes: 0 additions & 18 deletions cmd/podman/pod_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,6 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
if err != nil {
return errors.Wrapf(err, "unable to get a list of pods")
}
// First we need to get an initial pass of pod/ctr stats (these are not printed)
var podStats []*adapter.PodContainerStats
for _, p := range pods {
cons, err := p.AllContainersByID()
if err != nil {
return err
}
emptyStats := make(map[string]*libpod.ContainerStats)
// Iterate the pods container ids and make blank stats for them
for _, c := range cons {
emptyStats[c] = &libpod.ContainerStats{}
}
ps := adapter.PodContainerStats{
Pod: p,
ContainerStats: emptyStats,
}
podStats = append(podStats, &ps)
}

// Create empty container stat results for our first pass
var previousPodStats []*adapter.PodContainerStats
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pod_unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func podUnpauseCmd(c *cliconfig.PodUnpauseValues) error {
for _, p := range unpauseIDs {
fmt.Println(p)
}
if conErrors != nil && len(conErrors) > 0 {
if len(conErrors) > 0 {
for ctr, err := range conErrors {
if lastError != nil {
logrus.Errorf("%q", lastError)
Expand Down
2 changes: 2 additions & 0 deletions cmd/podman/remoteclientconfig/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (r *RemoteConfig) GetDefault() (*RemoteConnection, error) {
return nil, ErrNoDefinedConnections
}
for _, v := range r.Connections {
v := v
if len(r.Connections) == 1 {
// if there is only one defined connection, we assume it is
// the default whether tagged as such or not
Expand All @@ -54,6 +55,7 @@ func (r *RemoteConfig) GetRemoteConnection(name string) (*RemoteConnection, erro
return nil, ErrNoDefinedConnections
}
for k, v := range r.Connections {
v := v
if k == name {
return &v, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func searchCmd(c *cliconfig.SearchValues) error {
return nil
}
out := formats.StdoutTemplateArray{Output: searchToGeneric(results), Template: format, Fields: searchHeaderMap()}
return formats.Writer(out).Out()
return out.Out()
}

// searchHeaderMap returns the headers of a SearchResult.
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/shared/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func parseSecurityOpt(config *cc.CreateConfig, securityOpts []string, runtime *l
} else {
con := strings.SplitN(opt, "=", 2)
if len(con) != 2 {
return fmt.Errorf("Invalid --security-opt 1: %q", opt)
return fmt.Errorf("invalid --security-opt 1: %q", opt)
}

switch con[0] {
Expand All @@ -228,7 +228,7 @@ func parseSecurityOpt(config *cc.CreateConfig, securityOpts []string, runtime *l
case "seccomp":
config.SeccompProfilePath = con[1]
default:
return fmt.Errorf("Invalid --security-opt 2: %q", opt)
return fmt.Errorf("invalid --security-opt 2: %q", opt)
}
}
}
Expand Down Expand Up @@ -841,7 +841,7 @@ func makeHealthCheckFromCli(c *GenericCLIResults) (*manifest.Schema2HealthConfig
if err != nil {
return nil, errors.Wrapf(err, "invalid healthcheck-timeout %s", inTimeout)
}
if timeoutDuration < time.Duration(time.Second*1) {
if timeoutDuration < time.Duration(1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the linter accept (time.Duration(1) * time.Second)? I hate to lose the units here.

return nil, errors.New("healthcheck-timeout must be at least 1 second")
}
hc.Timeout = timeoutDuration
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func outputStats(stats []*libpod.ContainerStats, format string) error {
}
out = formats.StdoutTemplateArray{Output: statsToGeneric(outputStats, []statsOutputParams{}), Template: format, Fields: mapOfHeaders}
}
return formats.Writer(out).Out()
return out.Out()
}

func genStatsFormat(format string) string {
Expand Down
8 changes: 4 additions & 4 deletions cmd/podman/system_df.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func generateSysDfOutput(systemDfDiskUsages []systemDfDiskUsage, format string)
"Reclaimable": "RECLAIMABLE",
}
out := formats.StdoutTemplateArray{Output: systemDfDiskUsageToGeneric(systemDfDiskUsages), Template: format, Fields: systemDfHeader}
return formats.Writer(out).Out()
return out.Out()
}

func getDiskUsage(ctx context.Context, runtime *libpod.Runtime, metaData dfMetaData) ([]systemDfDiskUsage, error) {
Expand Down Expand Up @@ -557,7 +557,7 @@ func imagesVerboseOutput(ctx context.Context, metaData dfMetaData) error {
return err
}
out := formats.StdoutTemplateArray{Output: systemDfImageVerboseDiskUsageToGeneric(imagesVerboseDiskUsage), Template: imageVerboseFormat, Fields: imageVerboseHeader}
return formats.Writer(out).Out()
return out.Out()
}

func containersVerboseOutput(ctx context.Context, metaData dfMetaData) error {
Expand All @@ -579,7 +579,7 @@ func containersVerboseOutput(ctx context.Context, metaData dfMetaData) error {
return err
}
out := formats.StdoutTemplateArray{Output: systemDfContainerVerboseDiskUsageToGeneric(containersVerboseDiskUsage), Template: containerVerboseFormat, Fields: containerVerboseHeader}
return formats.Writer(out).Out()
return out.Out()

}

Expand All @@ -597,7 +597,7 @@ func volumesVerboseOutput(ctx context.Context, metaData dfMetaData) error {
return err
}
out := formats.StdoutTemplateArray{Output: systemDfVolumeVerboseDiskUsageToGeneric(volumesVerboseDiskUsage), Template: volumeVerboseFormat, Fields: volumeVerboseHeader}
return formats.Writer(out).Out()
return out.Out()
}

func verboseOutput(ctx context.Context, metaData dfMetaData) error {
Expand Down
18 changes: 8 additions & 10 deletions cmd/podman/trust_set_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ func showTrustCmd(c *cliconfig.ShowTrustValues) error {
}
outjson = policyJSON
out := formats.JSONStruct{Output: outjson}
return formats.Writer(out).Out()
return out.Out()
}

showOutputMap, err := getPolicyShowOutput(policyContentStruct, systemRegistriesDirPath)
if err != nil {
return errors.Wrapf(err, "could not show trust policies")
}
out := formats.StdoutTemplateArray{Output: showOutputMap, Template: "{{.Repo}}\t{{.Trusttype}}\t{{.GPGid}}\t{{.Sigstore}}"}
return formats.Writer(out).Out()
return out.Out()
}

func setTrustCmd(c *cliconfig.SetTrustValues) error {
Expand Down Expand Up @@ -254,15 +254,12 @@ func getPolicyJSON(policyContentStruct trust.PolicyContent, systemRegistriesDirP
policyJSON[repo]["type"] = repoval[0].Type
policyJSON[repo]["transport"] = transname
keyarr := []string{}
uids := []string{}
for _, repoele := range repoval {
if len(repoele.KeyPath) > 0 {
keyarr = append(keyarr, repoele.KeyPath)
uids = append(uids, trust.GetGPGIdFromKeyPath(repoele.KeyPath)...)
}
if len(repoele.KeyData) > 0 {
keyarr = append(keyarr, string(repoele.KeyData))
uids = append(uids, trust.GetGPGIdFromKeyData(string(repoele.KeyData))...)
keyarr = append(keyarr, repoele.KeyData)
}
}
policyJSON[repo]["keys"] = keyarr
Expand Down Expand Up @@ -308,16 +305,17 @@ func getPolicyShowOutput(policyContentStruct trust.PolicyContent, systemRegistri
Repo: repo,
Trusttype: repoval[0].Type,
}
keyarr := []string{}
// TODO - keyarr is not used and I don't know its intent; commenting out for now for someone to fix later
//keyarr := []string{}
uids := []string{}
for _, repoele := range repoval {
if len(repoele.KeyPath) > 0 {
keyarr = append(keyarr, repoele.KeyPath)
//keyarr = append(keyarr, repoele.KeyPath)
uids = append(uids, trust.GetGPGIdFromKeyPath(repoele.KeyPath)...)
}
if len(repoele.KeyData) > 0 {
keyarr = append(keyarr, string(repoele.KeyData))
uids = append(uids, trust.GetGPGIdFromKeyData(string(repoele.KeyData))...)
//keyarr = append(keyarr, string(repoele.KeyData))
uids = append(uids, trust.GetGPGIdFromKeyData(repoele.KeyData)...)
}
}
tempTrustShowOutput.GPGid = strings.Join(uids, ", ")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func versionCmd(c *cliconfig.VersionValues) error {
default:
out = formats.StdoutTemplate{Output: clientVersion, Template: versionOutputFormat}
}
return formats.Writer(out).Out()
return out.Out()
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer w.Flush()
Expand Down
Loading