Merge pull request #34588 from dnephin/more-linters

Add deadcode and goimports linters
Upstream-commit: 6540d5581473c292ade46ee1b620172441943f4b
Component: engine
This commit is contained in:
Yong Tang
2017-08-22 05:12:50 -07:00
committed by GitHub
30 changed files with 38 additions and 137 deletions
@@ -13,14 +13,6 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
) )
// httpStatusError is an interface
// that errors with custom status codes
// implement to tell the api layer
// which response status to set.
type httpStatusError interface {
HTTPErrorStatusCode() int
}
type causer interface { type causer interface {
Cause() error Cause() error
} }
@@ -276,14 +276,6 @@ func (filters Args) Validate(accepted map[string]bool) error {
return nil return nil
} }
type invalidFilterError string
func (e invalidFilterError) Error() string {
return "Invalid filter: '" + string(e) + "'"
}
func (invalidFilterError) InvalidParameter() {}
// WalkValues iterates over the list of filtered values for a field. // WalkValues iterates over the list of filtered values for a field.
// It stops the iteration if it finds an error and it returns that error. // It stops the iteration if it finds an error and it returns that error.
func (filters Args) WalkValues(field string, op func(value string) error) error { func (filters Args) WalkValues(field string, op func(value string) error) error {
@@ -9,6 +9,14 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
) )
// transportFunc allows us to inject a mock transport for testing. We define it
// here so we can detect the tlsconfig and return nil for only this type.
type transportFunc func(*http.Request) (*http.Response, error)
func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return tf(req)
}
func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client { func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client {
return &http.Client{ return &http.Client{
Transport: transportFunc(doer), Transport: transportFunc(doer),
@@ -2,18 +2,17 @@ package client
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
"testing" "testing"
"golang.org/x/net/context"
"encoding/json"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/registry"
"golang.org/x/net/context"
) )
func TestImageSearchAnyError(t *testing.T) { func TestImageSearchAnyError(t *testing.T) {
-8
View File
@@ -5,14 +5,6 @@ import (
"net/http" "net/http"
) )
// transportFunc allows us to inject a mock transport for testing. We define it
// here so we can detect the tlsconfig and return nil for only this type.
type transportFunc func(*http.Request) (*http.Response, error)
func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return tf(req)
}
// resolveTLSConfig attempts to resolve the TLS configuration from the // resolveTLSConfig attempts to resolve the TLS configuration from the
// RoundTripper. // RoundTripper.
func resolveTLSConfig(transport http.RoundTripper) *tls.Config { func resolveTLSConfig(transport http.RoundTripper) *tls.Config {
@@ -2,8 +2,6 @@ package main
import ( import (
"github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/config"
runconfigopts "github.com/docker/docker/runconfig/opts"
units "github.com/docker/go-units"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@@ -5,27 +5,14 @@ package main
import ( import (
"fmt" "fmt"
"net" "net"
"os"
"path/filepath" "path/filepath"
"github.com/docker/docker/libcontainerd" "github.com/docker/docker/libcontainerd"
"github.com/docker/docker/pkg/system"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
const defaultDaemonConfigFile = "" const defaultDaemonConfigFile = ""
// currentUserIsOwner checks whether the current user is the owner of the given
// file.
func currentUserIsOwner(f string) bool {
if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil {
if int(fileInfo.UID()) == os.Getuid() {
return true
}
}
return false
}
// setDefaultUmask sets the umask to 0022 to avoid problems // setDefaultUmask sets the umask to 0022 to avoid problems
// caused by custom umask // caused by custom umask
func setDefaultUmask() error { func setDefaultUmask() error {
@@ -14,12 +14,6 @@ import (
var defaultDaemonConfigFile = "" var defaultDaemonConfigFile = ""
// currentUserIsOwner checks whether the current user is the owner of the given
// file.
func currentUserIsOwner(f string) bool {
return false
}
// setDefaultUmask doesn't do anything on windows // setDefaultUmask doesn't do anything on windows
func setDefaultUmask() error { func setDefaultUmask() error {
return nil return nil
@@ -1,9 +1,5 @@
package config package config
import (
"github.com/spf13/pflag"
)
// Config defines the configuration of a docker daemon. // Config defines the configuration of a docker daemon.
// These are the configuration settings that you pass // These are the configuration settings that you pass
// to the docker daemon when you launch it with say: `docker -d -e lxc` // to the docker daemon when you launch it with say: `docker -d -e lxc`
+4 -5
View File
@@ -22,7 +22,7 @@ import (
"github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/netutils" "github.com/docker/libnetwork/netutils"
lntypes "github.com/docker/libnetwork/types" lntypes "github.com/docker/libnetwork/types"
"github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux/label" "github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@@ -32,10 +32,9 @@ import (
import "C" import "C"
const ( const (
defaultVirtualSwitch = "Virtual Switch" platformSupported = true
platformSupported = true solarisMinCPUShares = 1
solarisMinCPUShares = 1 solarisMaxCPUShares = 65535
solarisMaxCPUShares = 65535
) )
func getMemoryResources(config containertypes.Resources) specs.CappedMemory { func getMemoryResources(config containertypes.Resources) specs.CappedMemory {
@@ -5,7 +5,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"github.com/Microsoft/hcsshim" "github.com/Microsoft/hcsshim"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
@@ -38,9 +37,6 @@ const (
windowsMaxCPUShares = 10000 windowsMaxCPUShares = 10000
windowsMinCPUPercent = 1 windowsMinCPUPercent = 1
windowsMaxCPUPercent = 100 windowsMaxCPUPercent = 100
windowsMinCPUCount = 1
errInvalidState = syscall.Errno(0x139F)
) )
// Windows has no concept of an execution state directory. So use config.Root here. // Windows has no concept of an execution state directory. So use config.Root here.
@@ -60,22 +56,6 @@ func parseSecurityOpt(container *container.Container, config *containertypes.Hos
return nil return nil
} }
func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
return nil, nil
}
func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
return nil, nil
}
func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
return nil, nil
}
func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) {
return nil, nil
}
func (daemon *Daemon) getLayerInit() func(string) error { func (daemon *Daemon) getLayerInit() func(string) error {
return nil return nil
} }
@@ -1,6 +1,10 @@
package graphdriver package graphdriver
import "golang.org/x/sys/unix" import (
"syscall"
"golang.org/x/sys/unix"
)
var ( var (
// Slice of drivers that should be used in an order // Slice of drivers that should be used in an order
@@ -2,22 +2,12 @@ package graphdriver
import ( import (
"fmt" "fmt"
"io"
"path/filepath" "path/filepath"
"github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugingetter"
"github.com/docker/docker/plugin/v2" "github.com/docker/docker/plugin/v2"
) )
type pluginClient interface {
// Call calls the specified method with the specified arguments for the plugin.
Call(string, interface{}, interface{}) error
// Stream calls the specified method with the specified arguments for the plugin and returns the response IO stream
Stream(string, interface{}) (io.ReadCloser, error)
// SendFile calls the specified method, and passes through the IO stream
SendFile(string, io.Reader, interface{}) error
}
func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) { func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
if !config.ExperimentalEnabled { if !config.ExperimentalEnabled {
return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode") return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode")
+1 -2
View File
@@ -45,8 +45,7 @@ const (
const ( const (
// Exit status codes that can be returned by the probe command. // Exit status codes that can be returned by the probe command.
exitStatusHealthy = 0 // Container is healthy exitStatusHealthy = 0 // Container is healthy
exitStatusUnhealthy = 1 // Container is unhealthy
) )
// probe implementations know how to run a particular type of probe. // probe implementations know how to run a particular type of probe.
+1 -2
View File
@@ -6,7 +6,7 @@ import (
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugingetter"
"github.com/docker/go-metrics" metrics "github.com/docker/go-metrics"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@@ -16,7 +16,6 @@ const metricsPluginType = "MetricsCollector"
var ( var (
containerActions metrics.LabeledTimer containerActions metrics.LabeledTimer
containerStates metrics.LabeledGauge
imageActions metrics.LabeledTimer imageActions metrics.LabeledTimer
networkActions metrics.LabeledTimer networkActions metrics.LabeledTimer
engineInfo metrics.LabeledGauge engineInfo metrics.LabeledGauge
@@ -60,11 +60,7 @@ install_gometalinter() {
cd "$GOPATH/src/github.com/alecthomas/gometalinter" cd "$GOPATH/src/github.com/alecthomas/gometalinter"
git checkout -q "$GOMETALINTER_COMMIT" git checkout -q "$GOMETALINTER_COMMIT"
go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
( GOBIN=/usr/local/bin gometalinter --install
export GOBIN=/usr/local/bin
export GOPATH="$PWD/_linters/"
go install github.com/golang/lint/golint
)
} }
for prog in "$@" for prog in "$@"
@@ -10,7 +10,9 @@
], ],
"Enable": [ "Enable": [
"deadcode",
"gofmt", "gofmt",
"goimports",
"golint", "golint",
"vet" "vet"
], ],
@@ -1,6 +1,9 @@
package libcontainerd package libcontainerd
import "golang.org/x/net/context" import (
containerd "github.com/containerd/containerd/api/grpc/types"
"golang.org/x/net/context"
)
type client struct { type client struct {
clientCommon clientCommon
@@ -14,6 +14,7 @@ import (
) )
// Same as DM_DEVICE_* enum values from libdevmapper.h // Same as DM_DEVICE_* enum values from libdevmapper.h
// nolint: deadcode
const ( const (
deviceCreate TaskType = iota deviceCreate TaskType = iota
deviceReload deviceReload
@@ -1,6 +1,7 @@
package fileutils package fileutils
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@@ -9,7 +10,6 @@ import (
"strings" "strings"
"testing" "testing"
"fmt"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -3,8 +3,9 @@
package mount package mount
import ( import (
"golang.org/x/sys/unix"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
) )
// #include <stdlib.h> // #include <stdlib.h>
@@ -1,17 +1,11 @@
package foo package foo
import ( import (
"fmt"
aliasedio "io" aliasedio "io"
"github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture" "github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture"
) )
var (
errFakeImport = fmt.Errorf("just to import fmt for imports tests")
)
type wobble struct { type wobble struct {
Some string Some string
Val string Val string
@@ -1,9 +1,9 @@
package streamformatter package streamformatter
import ( import (
"bytes"
"testing" "testing"
"bytes"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
+1 -17
View File
@@ -32,7 +32,7 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/docker/docker/plugin/v2" "github.com/docker/docker/plugin/v2"
refstore "github.com/docker/docker/reference" refstore "github.com/docker/docker/reference"
"github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/net/context" "golang.org/x/net/context"
@@ -652,22 +652,6 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
return nil return nil
} }
func getMounts(root string) ([]string, error) {
infos, err := mount.GetMounts()
if err != nil {
return nil, errors.Wrap(err, "failed to read mount table")
}
var mounts []string
for _, m := range infos {
if strings.HasPrefix(m.Mountpoint, root) {
mounts = append(mounts, m.Mountpoint)
}
}
return mounts, nil
}
// Set sets plugin args // Set sets plugin args
func (pm *Manager) Set(name string, args []string) error { func (pm *Manager) Set(name string, args []string) error {
p, err := pm.config.Store.GetV2Plugin(name) p, err := pm.config.Store.GetV2Plugin(name)
@@ -2,8 +2,6 @@ package resumable
import ( import (
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@@ -11,6 +9,9 @@ import (
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestResumableRequestHeaderSimpleErrors(t *testing.T) { func TestResumableRequestHeaderSimpleErrors(t *testing.T) {
@@ -32,6 +32,7 @@ func NewVolumeDriver(name string, baseHostPath string, c client) volume.Driver {
// volumeDriver defines the available functions that volume plugins must implement. // volumeDriver defines the available functions that volume plugins must implement.
// This interface is only defined to generate the proxy objects. // This interface is only defined to generate the proxy objects.
// It's not intended to be public or reused. // It's not intended to be public or reused.
// nolint: deadcode
type volumeDriver interface { type volumeDriver interface {
// Create a volume with the given name // Create a volume with the given name
Create(name string, opts map[string]string) (err error) Create(name string, opts map[string]string) (err error)
-4
View File
@@ -119,10 +119,6 @@ func validateNotRoot(p string) error {
return nil return nil
} }
func validateCopyMode(mode bool) error {
return nil
}
func convertSlash(p string) string { func convertSlash(p string) string {
return p return p
} }
@@ -183,13 +183,6 @@ func validateNotRoot(p string) error {
return nil return nil
} }
func validateCopyMode(mode bool) error {
if mode {
return fmt.Errorf("Windows does not support copying image path content")
}
return nil
}
func convertSlash(p string) string { func convertSlash(p string) string {
return filepath.FromSlash(p) return filepath.FromSlash(p)
} }