Add nakedret linter.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
master
Daniel Nephin 2017-10-12 11:44:03 -04:00
parent 6ef0ea82ea
commit dbd96badb6
13 changed files with 57 additions and 48 deletions

View File

@ -207,7 +207,8 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
return client.NewClient(host, verStr, httpClient, customHeaders)
}
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string, err error) {
func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error) {
var host string
switch len(hosts) {
case 0:
host = os.Getenv("DOCKER_HOST")
@ -217,8 +218,7 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string,
return "", errors.New("Please specify only one -H")
}
host, err = dopts.ParseHost(tlsOptions != nil, host)
return
return dopts.ParseHost(tlsOptions != nil, host)
}
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {

View File

@ -52,12 +52,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return
return 0, "", nil
}
report, err := dockerCli.Client().ContainersPrune(context.Background(), pruneFilters)
if err != nil {
return
return 0, "", err
}
if len(report.ContainersDeleted) > 0 {
@ -68,7 +68,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
spaceReclaimed = report.SpaceReclaimed
}
return
return spaceReclaimed, output, nil
}
// RunPrune calls the Container Prune API

View File

@ -200,7 +200,8 @@ func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
return 0.00
}
func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64) {
func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) {
var blkRead, blkWrite uint64
for _, bioEntry := range blkio.IoServiceBytesRecursive {
switch strings.ToLower(bioEntry.Op) {
case "read":
@ -209,7 +210,7 @@ func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64)
blkWrite = blkWrite + bioEntry.Value
}
}
return
return blkRead, blkWrite
}
func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) {

View File

@ -118,11 +118,11 @@ func (ctx *DiskUsageContext) Write() (err error) {
return err
}
func (ctx *DiskUsageContext) verboseWrite() (err error) {
func (ctx *DiskUsageContext) verboseWrite() error {
// First images
tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat)
if err != nil {
return
return err
}
ctx.Output.Write([]byte("Images space usage:\n\n"))
@ -141,14 +141,14 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
}
}
err = ctx.contextFormat(tmpl, &imageContext{
err := ctx.contextFormat(tmpl, &imageContext{
repo: repo,
tag: tag,
trunc: true,
i: *i,
})
if err != nil {
return
return err
}
}
ctx.postFormat(tmpl, newImageContext())
@ -157,17 +157,14 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
ctx.Output.Write([]byte("\nContainers space usage:\n\n"))
tmpl, err = ctx.startSubsection(defaultDiskUsageContainerTableFormat)
if err != nil {
return
return err
}
for _, c := range ctx.Containers {
// Don't display the virtual size
c.SizeRootFs = 0
err = ctx.contextFormat(tmpl, &containerContext{
trunc: true,
c: *c,
})
err := ctx.contextFormat(tmpl, &containerContext{trunc: true, c: *c})
if err != nil {
return
return err
}
}
ctx.postFormat(tmpl, newContainerContext())
@ -176,21 +173,18 @@ func (ctx *DiskUsageContext) verboseWrite() (err error) {
ctx.Output.Write([]byte("\nLocal Volumes space usage:\n\n"))
tmpl, err = ctx.startSubsection(defaultDiskUsageVolumeTableFormat)
if err != nil {
return
return err
}
for _, v := range ctx.Volumes {
err = ctx.contextFormat(tmpl, &volumeContext{
v: *v,
})
if err != nil {
return
if err := ctx.contextFormat(tmpl, &volumeContext{v: *v}); err != nil {
return err
}
}
ctx.postFormat(tmpl, newVolumeContext())
// And build cache
fmt.Fprintf(ctx.Output, "\nBuild cache usage: %s\n\n", units.HumanSize(float64(ctx.BuilderSize)))
return
return nil
}
type diskUsageImagesContext struct {

View File

@ -128,18 +128,18 @@ func getBuildSharedKey(dir string) (string, error) {
return hex.EncodeToString(s[:]), nil
}
func tryNodeIdentifier() (out string) {
out = cliconfig.Dir() // return config dir as default on permission error
func tryNodeIdentifier() string {
out := cliconfig.Dir() // return config dir as default on permission error
if err := os.MkdirAll(cliconfig.Dir(), 0700); err == nil {
sessionFile := filepath.Join(cliconfig.Dir(), ".buildNodeID")
if _, err := os.Lstat(sessionFile); err != nil {
if os.IsNotExist(err) { // create a new file with stored randomness
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
return
return out
}
if err := ioutil.WriteFile(sessionFile, []byte(hex.EncodeToString(b)), 0600); err != nil {
return
return out
}
}
}
@ -149,5 +149,5 @@ func tryNodeIdentifier() (out string) {
return string(dt)
}
}
return
return out
}

View File

@ -65,12 +65,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
warning = allImageWarning
}
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return
return 0, "", nil
}
report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters)
if err != nil {
return
return 0, "", err
}
if len(report.ImagesDeleted) > 0 {
@ -85,7 +85,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
spaceReclaimed = report.SpaceReclaimed
}
return
return spaceReclaimed, output, nil
}
// RunPrune calls the Image Prune API

View File

@ -50,12 +50,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err e
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return
return "", nil
}
report, err := dockerCli.Client().NetworksPrune(context.Background(), pruneFilters)
if err != nil {
return
return "", err
}
if len(report.NetworksDeleted) > 0 {
@ -65,7 +65,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (output string, err e
}
}
return
return output, nil
}
// RunPrune calls the Network Prune API

View File

@ -57,12 +57,12 @@ type pluginRegistryService struct {
registry.Service
}
func (s pluginRegistryService) ResolveRepository(name reference.Named) (repoInfo *registry.RepositoryInfo, err error) {
repoInfo, err = s.Service.ResolveRepository(name)
func (s pluginRegistryService) ResolveRepository(name reference.Named) (*registry.RepositoryInfo, error) {
repoInfo, err := s.Service.ResolveRepository(name)
if repoInfo != nil {
repoInfo.Class = "plugin"
}
return
return repoInfo, err
}
func newRegistryService() (registry.Service, error) {

View File

@ -52,12 +52,12 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
return
return 0, "", nil
}
report, err := dockerCli.Client().VolumesPrune(context.Background(), pruneFilters)
if err != nil {
return
return 0, "", err
}
if len(report.VolumesDeleted) > 0 {
@ -68,7 +68,7 @@ func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint6
spaceReclaimed = report.SpaceReclaimed
}
return
return spaceReclaimed, output, nil
}
// RunPrune calls the Volume Prune API

View File

@ -10,6 +10,13 @@ RUN go get -d github.com/alecthomas/gometalinter && \
gometalinter --install && \
rm -rf /go/src/* /go/pkg/*
ARG NAKEDRET_SHA=3ddb495a6d63bc9041ba843e7d651cf92639d8cb
RUN go get -d github.com/alexkohler/nakedret && \
cd /go/src/github.com/alexkohler/nakedret && \
git checkout -q "$NAKEDRET_SHA" && \
go build -v -o /usr/local/bin/nakedret . && \
rm -rf /go/src/* /go/pkg/*
WORKDIR /go/src/github.com/docker/cli
ENV CGO_ENABLED=0
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1

View File

@ -225,7 +225,7 @@ func parseMDContent(mdString string) (description string, examples string) {
examples = strings.Trim(s, "Examples\n")
}
}
return
return description, examples
}
type byName []*cobra.Command

View File

@ -7,6 +7,12 @@
"parameter .* always receives"
],
"EnableGC": true,
"Linters": {
"nakedret": {
"Command": "nakedret",
"Pattern": "^(?P<path>.*?\\.go):(?P<line>\\d+)\\s*(?P<message>.*)$"
}
},
"DisableAll": true,
"Enable": [
@ -20,6 +26,7 @@
"interfacer",
"lll",
"misspell",
"nakedret",
"unconvert",
"unparam",
"unused",

View File

@ -95,12 +95,12 @@ func (n *NetworkOpt) String() string {
return ""
}
func parseDriverOpt(driverOpt string) (key string, value string, err error) {
func parseDriverOpt(driverOpt string) (string, string, error) {
parts := strings.SplitN(driverOpt, "=", 2)
if len(parts) != 2 {
err = fmt.Errorf("invalid key value pair format in driver options")
return "", "", fmt.Errorf("invalid key value pair format in driver options")
}
key = strings.TrimSpace(strings.ToLower(parts[0]))
value = strings.TrimSpace(strings.ToLower(parts[1]))
return
key := strings.TrimSpace(strings.ToLower(parts[0]))
value := strings.TrimSpace(strings.ToLower(parts[1]))
return key, value, nil
}