Skip to content

Commit

Permalink
Merge pull request #14585 from Luap99/nolint
Browse files Browse the repository at this point in the history
golangci-lint: enable nolintlint
  • Loading branch information
openshift-ci[bot] authored Jun 14, 2022
2 parents 4018a95 + 4152873 commit e084f0e
Show file tree
Hide file tree
Showing 54 changed files with 121 additions and 142 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ linters:
enable-all: true
disable:
# All these break for one reason or another
- nolintlint # some linter must be disabled (see `nolint` in the code)
- tagliatelle # too many JSON keys cannot be changed due to compat
- gocognit
- testpackage
Expand Down Expand Up @@ -64,3 +63,6 @@ linters-settings:
errcheck:
check-blank: false
ignore: fmt:.*
nolintlint:
allow-leading-space: false
require-specific: true
2 changes: 1 addition & 1 deletion cmd/podman/common/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Car) Color() string {
}

// This is for reflect testing required.
// nolint:unused
//nolint:unused
func (c Car) internal() int {
return 0
}
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 @@ -454,7 +454,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 // nolint: nilerr
return //nolint: nilerr
}

if strings.HasSuffix(containerPath, "/") {
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ func combineBytesValues(a, b uint64) string {

func outputJSON(stats []containerStats) error {
type jstat struct {
Id string `json:"id"` // nolint
Id string `json:"id"` //nolint:revive,stylecheck
Name string `json:"name"`
CPUTime string `json:"cpu_time"`
CpuPercent string `json:"cpu_percent"` // nolint
CpuPercent string `json:"cpu_percent"` //nolint:revive,stylecheck
AverageCPU string `json:"avg_cpu"`
MemUsage string `json:"mem_usage"`
MemPerc string `json:"mem_percent"`
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newInspector(options entities.InspectOptions) (*inspector, error) {
// inspect inspects the specified container/image names or IDs.
func (i *inspector) inspect(namesOrIDs []string) error {
// data - dumping place for inspection results.
var data []interface{} // nolint
var data []interface{}
var errs []error
ctx := context.Background()

Expand Down Expand Up @@ -249,7 +249,7 @@ func printTmpl(typ, row string, data []interface{}) error {
}

func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]interface{}, []error, error) {
var data []interface{} // nolint
var data []interface{}
allErrs := []error{}
for _, name := range namesOrIDs {
ctrData, errs, err := i.containerEngine.ContainerInspect(ctx, []string{name}, i.options)
Expand Down
23 changes: 3 additions & 20 deletions cmd/podman/parse/net.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint
// most of these validate and parse functions have been taken from projectatomic/docker
// and modified for cri-o
package parse
Expand All @@ -16,26 +15,10 @@ import (
)

const (
Protocol_TCP Protocol = 0
Protocol_UDP Protocol = 1
LabelType string = "label"
ENVType string = "env"
LabelType string = "label"
ENVType string = "env"
)

type Protocol int32

// PortMapping specifies the port mapping configurations of a sandbox.
type PortMapping struct {
// Protocol of the port mapping.
Protocol Protocol `protobuf:"varint,1,opt,name=protocol,proto3,enum=runtime.Protocol" json:"protocol,omitempty"`
// Port number within the container. Default: 0 (not specified).
ContainerPort int32 `protobuf:"varint,2,opt,name=container_port,json=containerPort,proto3" json:"container_port,omitempty"`
// Port number on the host. Default: 0 (not specified).
HostPort int32 `protobuf:"varint,3,opt,name=host_port,json=hostPort,proto3" json:"host_port,omitempty"`
// Host IP.
HostIp string `protobuf:"bytes,4,opt,name=host_ip,json=hostIp,proto3" json:"host_ip,omitempty"`
}

// Note: for flags that are in the form <number><unit>, use the RAMInBytes function
// from the units package in docker/go-units/size.go

Expand All @@ -48,7 +31,7 @@ var (
// validateExtraHost validates that the specified string is a valid extrahost and returns it.
// ExtraHost is in the form of name:ip where the ip has to be a valid ip (ipv4 or ipv6).
// for add-host flag
func ValidateExtraHost(val string) (string, error) { // nolint
func ValidateExtraHost(val string) (string, error) {
// allow for IPv6 addresses in extra hosts by only splitting on first ":"
arr := strings.SplitN(val, ":", 2)
if len(arr) != 2 || len(arr[0]) == 0 {
Expand Down
2 changes: 0 additions & 2 deletions cmd/podman/parse/net_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint
// most of these validate and parse functions have been taken from projectatomic/docker
// and modified for cri-o
package parse
Expand All @@ -23,7 +22,6 @@ func createTmpFile(content []byte) (string, error) {

if _, err := tmpfile.Write(content); err != nil {
return "", err

}
if err := tmpfile.Close(); err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (l ListPodReporter) ID() string {
}

// Id returns the Pod id
func (l ListPodReporter) Id() string { // nolint
func (l ListPodReporter) Id() string { //nolint:revive,stylecheck
if noTrunc {
return l.ListPodsReport.Id
}
Expand All @@ -225,7 +225,7 @@ func (l ListPodReporter) InfraID() string {

// InfraId returns the infra container id for the pod
// depending on trunc
func (l ListPodReporter) InfraId() string { // nolint
func (l ListPodReporter) InfraId() string { //nolint:revive,stylecheck
if len(l.ListPodsReport.InfraId) == 0 {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func printSummary(cmd *cobra.Command, reports *entities.SystemDfReport) error {
return writeTemplate(rpt, hdrs, dfSummaries)
}

func printVerbose(cmd *cobra.Command, reports *entities.SystemDfReport) error { // nolint:interfacer
func printVerbose(cmd *cobra.Command, reports *entities.SystemDfReport) error { //nolint:interfacer
rpt := report.New(os.Stdout, cmd.Name())
defer rpt.Flush()

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() // nolint: errcheck
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 @@ -226,8 +226,8 @@ outer:
// https://github.com/containers/podman/issues/11248
// Copy /dev/null to stdout and stderr to prevent SIGPIPE errors
if f, err := os.OpenFile("/dev/null", os.O_WRONLY, 0755); err == nil {
unix.Dup2(int(f.Fd()), 1) // nolint:errcheck
unix.Dup2(int(f.Fd()), 2) // nolint:errcheck
unix.Dup2(int(f.Fd()), 1) //nolint:errcheck
unix.Dup2(int(f.Fd()), 2) //nolint:errcheck
f.Close()
}
// write and close ReadyFD (convention is same as slirp4netns --ready-fd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rootlessport/wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SpecData struct {
}

func TestDualStackSplit(t *testing.T) {
//nolint
//nolint:revive,stylecheck
const (
IP4_ALL = "0.0.0.0"
IP4__LO = "127.0.0.1"
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ type ExecConfig struct {
type ExecSession struct {
// Id is the ID of the exec session.
// Named somewhat strangely to not conflict with ID().
// nolint:stylecheck,revive
//nolint:stylecheck,revive
Id string `json:"id"`
// ContainerId is the ID of the container this exec session belongs to.
// Named somewhat strangely to not conflict with ContainerID().
// nolint:stylecheck,revive
//nolint:stylecheck,revive
ContainerId string `json:"containerId"`

// State is the state of the exec session.
Expand Down
6 changes: 3 additions & 3 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ func (c *Container) generateUserGroupEntry(addedGID int) (string, error) {

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

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

if addedUID != 0 && int(uid) == addedUID {
Expand Down Expand Up @@ -3224,7 +3224,7 @@ func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
return err
}
stat := st.Sys().(*syscall.Stat_t)
atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) // nolint: unconvert
atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ type HealthCheckLog struct {
// as possible from the spec and container config.
// Some things cannot be inferred. These will be populated by spec annotations
// (if available).
// Field names are fixed for compatibility and cannot be changed.
// As such, silence lint warnings about them.
//nolint
//nolint:revive,stylecheck // Field names are fixed for compatibility and cannot be changed.
type InspectContainerHostConfig struct {
// Binds contains an array of user-added mounts.
// Both volume mounts and named volumes are included.
Expand Down
4 changes: 2 additions & 2 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func GenerateForKube(ctx context.Context, ctrs []*Container) (*v1.Pod, error) {
func (p *Pod) GenerateForKube(ctx context.Context) (*v1.Pod, []v1.ServicePort, error) {
// Generate the v1.Pod yaml description
var (
ports []v1.ContainerPort //nolint
servicePorts []v1.ServicePort //nolint
ports []v1.ContainerPort
servicePorts []v1.ServicePort
)

allContainers, err := p.allContainers()
Expand Down
2 changes: 1 addition & 1 deletion libpod/lock/file/file_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// FileLocks is a struct enabling POSIX lock locking in a shared memory
// segment.
type FileLocks struct { // nolint
type FileLocks struct { //nolint:revive // struct name stutters
lockPath string
valid bool
}
Expand Down
2 changes: 1 addition & 1 deletion libpod/lock/shm/shm_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (

// SHMLocks is a struct enabling POSIX semaphore locking in a shared memory
// segment.
type SHMLocks struct { // nolint
type SHMLocks struct {
lockStruct *C.shm_struct_t
maxLocks uint32
valid bool
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ func (r *ConmonOCIRuntime) getLogTag(ctr *Container) (string, error) {
data, err := ctr.inspectLocked(false)
if err != nil {
// FIXME: this error should probably be returned
return "", nil // nolint: nilerr
return "", nil //nolint: nilerr
}
tmpl, err := template.New("container").Parse(logTag)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions libpod/plugin/volume_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ var (
hostVirtualPath = "/VolumeDriver.Path"
mountPath = "/VolumeDriver.Mount"
unmountPath = "/VolumeDriver.Unmount"
// nolint
capabilitiesPath = "/VolumeDriver.Capabilities"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "CommitFailure"))
return
}
utils.WriteResponse(w, http.StatusCreated, entities.IDResponse{ID: commitImage.ID()}) // nolint
utils.WriteResponse(w, http.StatusCreated, entities.IDResponse{ID: commitImage.ID()})
}

func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -237,7 +237,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
Status string `json:"status"`
Progress string `json:"progress"`
ProgressDetail map[string]string `json:"progressDetail"`
Id string `json:"id"` // nolint
Id string `json:"id"` //nolint:revive,stylecheck
}{
Status: report.Id,
ProgressDetail: map[string]string{},
Expand Down Expand Up @@ -333,7 +333,7 @@ loop: // break out of for/select infinite loop
Total int64 `json:"total,omitempty"`
} `json:"progressDetail,omitempty"`
Error string `json:"error,omitempty"`
Id string `json:"id,omitempty"` // nolint
Id string `json:"id,omitempty"` //nolint:revive,stylecheck
}
select {
case e := <-progress:
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
AppArmor string `schema:"apparmor"`
BuildArgs string `schema:"buildargs"`
CacheFrom string `schema:"cachefrom"`
CgroupParent string `schema:"cgroupparent"` // nolint
CgroupParent string `schema:"cgroupparent"`
Compression uint64 `schema:"compression"`
ConfigureNetwork string `schema:"networkmode"`
CPPFlags string `schema:"cppflags"`
CpuPeriod uint64 `schema:"cpuperiod"` // nolint
CpuQuota int64 `schema:"cpuquota"` // nolint
CpuSetCpus string `schema:"cpusetcpus"` // nolint
CpuSetMems string `schema:"cpusetmems"` // nolint
CpuShares uint64 `schema:"cpushares"` // nolint
CpuPeriod uint64 `schema:"cpuperiod"` //nolint:revive,stylecheck
CpuQuota int64 `schema:"cpuquota"` //nolint:revive,stylecheck
CpuSetCpus string `schema:"cpusetcpus"` //nolint:revive,stylecheck
CpuSetMems string `schema:"cpusetmems"` //nolint:revive,stylecheck
CpuShares uint64 `schema:"cpushares"` //nolint:revive,stylecheck
DNSOptions string `schema:"dnsoptions"`
DNSSearch string `schema:"dnssearch"`
DNSServers string `schema:"dnsservers"`
Expand All @@ -101,7 +101,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
IdentityLabel bool `schema:"identitylabel"`
Ignore bool `schema:"ignore"`
Isolation string `schema:"isolation"`
Jobs int `schema:"jobs"` // nolint
Jobs int `schema:"jobs"`
LabelOpts string `schema:"labelopts"`
Labels string `schema:"labels"`
Layers bool `schema:"layers"`
Expand Down Expand Up @@ -367,7 +367,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
}
}
}
var additionalTags []string // nolint
var additionalTags []string
for i := 1; i < len(tags); i++ {
possiblyNormalizedTag, err := utils.NormalizeToDockerHub(r, tags[i])
if err != nil {
Expand Down Expand Up @@ -801,7 +801,7 @@ func parseNetworkConfigurationPolicy(network string) buildah.NetworkConfiguratio
}
}

func parseLibPodIsolation(isolation string) (buildah.Isolation, error) { // nolint
func parseLibPodIsolation(isolation string) (buildah.Isolation, error) {
if val, err := strconv.Atoi(isolation); err == nil {
return buildah.Isolation(val), nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/images_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
)

func SaveFromBody(f *os.File, r *http.Request) error { // nolint
func SaveFromBody(f *os.File, r *http.Request) error {
if _, err := io.Copy(f, r.Body); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/libpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
utils.Error(w, http.StatusInternalServerError, errors.Wrapf(err, "CommitFailure"))
return
}
utils.WriteResponse(w, http.StatusOK, entities.IDResponse{ID: commitImage.ID()}) // nolint
utils.WriteResponse(w, http.StatusOK, entities.IDResponse{ID: commitImage.ID()})
}

func UntagImage(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/utils/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func IsRegistryReference(name string) error {
imageRef, err := alltransports.ParseImageName(name)
if err != nil {
// No supported transport -> assume a docker-stype reference.
return nil // nolint: nilerr
return nil //nolint: nilerr
}
if imageRef.Transport().Name() == docker.Transport.Name() {
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser
if logrus.IsLevelEnabled(logrus.TraceLevel) {
// If in trace mode log request and response bodies
router.Use(loggingHandler())
router.Walk(func(route *mux.Route, r *mux.Router, ancestors []*mux.Route) error { // nolint
_ = router.Walk(func(route *mux.Route, r *mux.Router, ancestors []*mux.Route) error {
path, err := route.GetPathTemplate()
if err != nil {
path = "<N/A>"
Expand Down
Loading

0 comments on commit e084f0e

Please sign in to comment.