diff --git a/.golangci.yml b/.golangci.yml index fc4d8b48df..3a1385998f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,7 +15,6 @@ linters: - gosimple - govet - ineffassign - - lll - misspell # Detects commonly misspelled English words in comments. - nakedret - nilerr # Detects code that returns nil even if it checks that the error is not nil. @@ -86,10 +85,6 @@ linters-settings: revive: rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing - - name: import-shadowing - severity: warning - disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block - name: empty-block severity: warning @@ -98,6 +93,19 @@ linters-settings: - name: empty-lines severity: warning disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing + - name: import-shadowing + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit + - name: line-length-limit + severity: warning + disabled: false + arguments: [200] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver + - name: unused-receiver + severity: warning + disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any - name: use-any severity: warning diff --git a/cli-plugins/manager/manager.go b/cli-plugins/manager/manager.go index 223f3ae0a7..9f795bc498 100644 --- a/cli-plugins/manager/manager.go +++ b/cli-plugins/manager/manager.go @@ -32,7 +32,7 @@ const ( // errPluginNotFound is the error returned when a plugin could not be found. type errPluginNotFound string -func (e errPluginNotFound) NotFound() {} +func (errPluginNotFound) NotFound() {} func (e errPluginNotFound) Error() string { return "Error: No such CLI plugin: " + string(e) diff --git a/cli/cobra.go b/cli/cobra.go index e6bcc90fa1..aa7dbef44c 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -337,8 +337,10 @@ func operationSubCommands(cmd *cobra.Command) []*cobra.Command { return cmds } +const defaultTermWidth = 80 + func wrappedFlagUsages(cmd *cobra.Command) string { - width := 80 + width := defaultTermWidth if ws, err := term.GetWinsize(0); err == nil { width = int(ws.Width) } diff --git a/cli/command/cli.go b/cli/command/cli.go index a8cfd58e4d..227720fa07 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -97,7 +97,7 @@ type DockerCli struct { } // DefaultVersion returns api.defaultVersion. -func (cli *DockerCli) DefaultVersion() string { +func (*DockerCli) DefaultVersion() string { return api.DefaultVersion } @@ -231,7 +231,7 @@ func (cli *DockerCli) HooksEnabled() bool { } // ManifestStore returns a store for local manifests -func (cli *DockerCli) ManifestStore() manifeststore.Store { +func (*DockerCli) ManifestStore() manifeststore.Store { // TODO: support override default location from config file return manifeststore.NewStore(filepath.Join(config.Dir(), "manifests")) } diff --git a/cli/command/cli_options.go b/cli/command/cli_options.go index 84b121f34a..ef133d6a9a 100644 --- a/cli/command/cli_options.go +++ b/cli/command/cli_options.go @@ -177,7 +177,10 @@ func withCustomHeadersFromEnv() client.Opt { csvReader := csv.NewReader(strings.NewReader(value)) fields, err := csvReader.Read() if err != nil { - return errdefs.InvalidParameter(errors.Errorf("failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", envOverrideHTTPHeaders)) + return errdefs.InvalidParameter(errors.Errorf( + "failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", + envOverrideHTTPHeaders, + )) } if len(fields) == 0 { return nil @@ -191,7 +194,10 @@ func withCustomHeadersFromEnv() client.Opt { k = strings.TrimSpace(k) if k == "" { - return errdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, envOverrideHTTPHeaders, kv)) + return errdefs.InvalidParameter(errors.Errorf( + `failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, + envOverrideHTTPHeaders, kv, + )) } // We don't currently allow empty key=value pairs, and produce an error. @@ -199,7 +205,10 @@ func withCustomHeadersFromEnv() client.Opt { // from an environment variable with the same name). In the meantime, // produce an error to prevent users from depending on this. if !hasValue { - return errdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, envOverrideHTTPHeaders, kv)) + return errdefs.InvalidParameter(errors.Errorf( + `failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, + envOverrideHTTPHeaders, kv, + )) } env[http.CanonicalHeaderKey(k)] = v diff --git a/cli/command/container/client_test.go b/cli/command/container/client_test.go index 6da7b4e105..61bf4c9ec8 100644 --- a/cli/command/container/client_test.go +++ b/cli/command/container/client_test.go @@ -75,7 +75,7 @@ func (f *fakeClient) ContainerExecInspect(_ context.Context, execID string) (con return container.ExecInspect{}, nil } -func (f *fakeClient) ContainerExecStart(context.Context, string, container.ExecStartOptions) error { +func (*fakeClient) ContainerExecStart(context.Context, string, container.ExecStartOptions) error { return nil } diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index c02ed14fb5..a5a09ce54a 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -380,5 +380,5 @@ func TestCreateContainerWithProxyConfig(t *testing.T) { type fakeNotFound struct{} -func (f fakeNotFound) NotFound() {} -func (f fakeNotFound) Error() string { return "error fake not found" } +func (fakeNotFound) NotFound() {} +func (fakeNotFound) Error() string { return "error fake not found" } diff --git a/cli/command/container/formatter_stats.go b/cli/command/container/formatter_stats.go index dafcb4303b..b7fdf47333 100644 --- a/cli/command/container/formatter_stats.go +++ b/cli/command/container/formatter_stats.go @@ -22,6 +22,8 @@ const ( winMemUseHeader = "PRIV WORKING SET" // Used only on Windows memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux pidsHeader = "PIDS" // Used only on Linux + + noValue = "--" ) // StatsEntry represents the statistics data collected from a container @@ -169,7 +171,7 @@ func (c *statsContext) Name() string { if len(c.s.Name) > 1 { return c.s.Name[1:] } - return "--" + return noValue } func (c *statsContext) ID() string { @@ -181,7 +183,7 @@ func (c *statsContext) ID() string { func (c *statsContext) CPUPerc() string { if c.s.IsInvalid { - return "--" + return noValue } return formatPercentage(c.s.CPUPercentage) } @@ -198,28 +200,28 @@ func (c *statsContext) MemUsage() string { func (c *statsContext) MemPerc() string { if c.s.IsInvalid || c.os == winOSType { - return "--" + return noValue } return formatPercentage(c.s.MemoryPercentage) } func (c *statsContext) NetIO() string { if c.s.IsInvalid { - return "--" + return noValue } return units.HumanSizeWithPrecision(c.s.NetworkRx, 3) + " / " + units.HumanSizeWithPrecision(c.s.NetworkTx, 3) } func (c *statsContext) BlockIO() string { if c.s.IsInvalid { - return "--" + return noValue } return units.HumanSizeWithPrecision(c.s.BlockRead, 3) + " / " + units.HumanSizeWithPrecision(c.s.BlockWrite, 3) } func (c *statsContext) PIDs() string { if c.s.IsInvalid || c.os == winOSType { - return "--" + return noValue } return strconv.FormatUint(c.s.PidsCurrent, 10) } diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index df2639bf00..fc57493830 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -331,7 +331,12 @@ size: 0B }, // Special headers for customized table format { - context: Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)}, + context: Context{ + Format: NewContainerFormat( + `table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, + false, true, + ), + }, expected: string(golden.Get(t, "container-context-write-special-headers.golden")), }, { @@ -525,7 +530,6 @@ type ports struct { expected string } -//nolint:lll func TestDisplayablePorts(t *testing.T) { cases := []ports{ { @@ -828,7 +832,7 @@ func TestDisplayablePorts(t *testing.T) { Type: "sctp", }, }, - expected: "80/tcp, 80/udp, 1024/tcp, 1024/udp, 12345/sctp, 1.1.1.1:1024->80/tcp, 1.1.1.1:1024->80/udp, 2.1.1.1:1024->80/tcp, 2.1.1.1:1024->80/udp, 1.1.1.1:80->1024/tcp, 1.1.1.1:80->1024/udp, 2.1.1.1:80->1024/tcp, 2.1.1.1:80->1024/udp", + expected: "80/tcp, 80/udp, 1024/tcp, 1024/udp, 12345/sctp, 1.1.1.1:1024->80/tcp, 1.1.1.1:1024->80/udp, 2.1.1.1:1024->80/tcp, 2.1.1.1:1024->80/udp, 1.1.1.1:80->1024/tcp, 1.1.1.1:80->1024/udp, 2.1.1.1:80->1024/tcp, 2.1.1.1:80->1024/udp", //nolint:revive // ignore line-length-limit (revive) }, } diff --git a/cli/command/formatter/custom.go b/cli/command/formatter/custom.go index 043e268dbe..6910a261e1 100644 --- a/cli/command/formatter/custom.go +++ b/cli/command/formatter/custom.go @@ -32,7 +32,7 @@ type SubContext interface { type SubHeaderContext map[string]string // Label returns the header label for the specified string -func (c SubHeaderContext) Label(name string) string { +func (SubHeaderContext) Label(name string) string { n := strings.Split(name, ".") r := strings.NewReplacer("-", " ", "_", " ") h := r.Replace(n[len(n)-1]) diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index 18d79d08e6..1199d571f3 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -270,7 +270,7 @@ func (c *diskUsageImagesContext) MarshalJSON() ([]byte, error) { return MarshalJSON(c) } -func (c *diskUsageImagesContext) Type() string { +func (*diskUsageImagesContext) Type() string { return "Images" } @@ -321,7 +321,7 @@ func (c *diskUsageContainersContext) MarshalJSON() ([]byte, error) { return MarshalJSON(c) } -func (c *diskUsageContainersContext) Type() string { +func (*diskUsageContainersContext) Type() string { return "Containers" } @@ -329,7 +329,7 @@ func (c *diskUsageContainersContext) TotalCount() string { return strconv.Itoa(len(c.containers)) } -func (c *diskUsageContainersContext) isActive(ctr container.Summary) bool { +func (*diskUsageContainersContext) isActive(ctr container.Summary) bool { return strings.Contains(ctr.State, "running") || strings.Contains(ctr.State, "paused") || strings.Contains(ctr.State, "restarting") @@ -382,7 +382,7 @@ func (c *diskUsageVolumesContext) MarshalJSON() ([]byte, error) { return MarshalJSON(c) } -func (c *diskUsageVolumesContext) Type() string { +func (*diskUsageVolumesContext) Type() string { return "Local Volumes" } @@ -443,7 +443,7 @@ func (c *diskUsageBuilderContext) MarshalJSON() ([]byte, error) { return MarshalJSON(c) } -func (c *diskUsageBuilderContext) Type() string { +func (*diskUsageBuilderContext) Type() string { return "Build Cache" } diff --git a/cli/command/formatter/formatter_test.go b/cli/command/formatter/formatter_test.go index 7a95f2112e..4deb5e7f90 100644 --- a/cli/command/formatter/formatter_test.go +++ b/cli/command/formatter/formatter_test.go @@ -28,7 +28,7 @@ type fakeSubContext struct { Name string } -func (f fakeSubContext) FullHeader() any { +func (fakeSubContext) FullHeader() any { return map[string]string{"Name": "NAME"} } diff --git a/cli/command/formatter/reflect_test.go b/cli/command/formatter/reflect_test.go index 79737ec5f7..4b736eb74c 100644 --- a/cli/command/formatter/reflect_test.go +++ b/cli/command/formatter/reflect_test.go @@ -10,29 +10,29 @@ import ( type dummy struct{} -func (d *dummy) Func1() string { +func (*dummy) Func1() string { return "Func1" } -func (d *dummy) func2() string { //nolint:unused +func (*dummy) func2() string { //nolint:unused return "func2(should not be marshalled)" } -func (d *dummy) Func3() (string, int) { +func (*dummy) Func3() (string, int) { return "Func3(should not be marshalled)", -42 } -func (d *dummy) Func4() int { +func (*dummy) Func4() int { return 4 } type dummyType string -func (d *dummy) Func5() dummyType { - return dummyType("Func5") +func (*dummy) Func5() dummyType { + return "Func5" } -func (d *dummy) FullHeader() string { +func (*dummy) FullHeader() string { return "FullHeader(should not be marshalled)" } diff --git a/cli/command/image/formatter_history_test.go b/cli/command/image/formatter_history_test.go index cff2f7f612..e67fa946f0 100644 --- a/cli/command/image/formatter_history_test.go +++ b/cli/command/image/formatter_history_test.go @@ -107,8 +107,8 @@ func TestHistoryContext_CreatedSince(t *testing.T) { } func TestHistoryContext_CreatedBy(t *testing.T) { - withTabs := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` //nolint:lll - expected := `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` //nolint:lll + const withTabs = `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` //nolint:revive // ignore line-length-limit + const expected = `/bin/sh -c apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list && apt-get update && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates nginx=${NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx-module-njs gettext-base && rm -rf /var/lib/apt/lists/*` //nolint:revive // ignore line-length-limit var ctx historyContext cases := []historyCase{ @@ -138,8 +138,8 @@ func TestHistoryContext_CreatedBy(t *testing.T) { } func TestHistoryContext_Size(t *testing.T) { - size := int64(182964289) - expected := "183MB" + const size = int64(182964289) + const expected = "183MB" var ctx historyContext cases := []historyCase{ @@ -170,7 +170,7 @@ func TestHistoryContext_Size(t *testing.T) { } func TestHistoryContext_Comment(t *testing.T) { - comment := "Some comment" + const comment = "Some comment" var ctx historyContext cases := []historyCase{ diff --git a/cli/command/image/remove_test.go b/cli/command/image/remove_test.go index dc9af57f38..16c0a3c4a1 100644 --- a/cli/command/image/remove_test.go +++ b/cli/command/image/remove_test.go @@ -21,7 +21,7 @@ func (n notFound) Error() string { return "Error: No such image: " + n.imageID } -func (n notFound) NotFound() {} +func (notFound) NotFound() {} func TestNewRemoveCommandAlias(t *testing.T) { cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{})) diff --git a/cli/command/node/formatter.go b/cli/command/node/formatter.go index cc82e6d037..d625b485e1 100644 --- a/cli/command/node/formatter.go +++ b/cli/command/node/formatter.go @@ -281,7 +281,8 @@ func (ctx *nodeInspectContext) ResourceNanoCPUs() int { if ctx.Node.Description.Resources.NanoCPUs == 0 { return int(0) } - return int(ctx.Node.Description.Resources.NanoCPUs) / 1e9 + const nano = 1e9 + return int(ctx.Node.Description.Resources.NanoCPUs) / nano } func (ctx *nodeInspectContext) ResourceMemory() string { diff --git a/cli/command/plugin/client_test.go b/cli/command/plugin/client_test.go index 8eaf06896d..4b6901b145 100644 --- a/cli/command/plugin/client_test.go +++ b/cli/command/plugin/client_test.go @@ -73,11 +73,11 @@ func (c *fakeClient) PluginInspectWithRaw(_ context.Context, name string) (*type return nil, nil, nil } -func (c *fakeClient) Info(context.Context) (system.Info, error) { +func (*fakeClient) Info(context.Context) (system.Info, error) { return system.Info{}, nil } -func (c *fakeClient) PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) { +func (c *fakeClient) PluginUpgrade(_ context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) { if c.pluginUpgradeFunc != nil { return c.pluginUpgradeFunc(name, options) } diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index dc07f7413e..75bd6a3164 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -33,11 +33,11 @@ type fakeClient struct { client.Client } -func (c *fakeClient) Info(context.Context) (system.Info, error) { +func (*fakeClient) Info(context.Context) (system.Info, error) { return system.Info{}, nil } -func (c *fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { +func (*fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { if auth.Password == expiredPassword { return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password") } diff --git a/cli/command/service/create_test.go b/cli/command/service/create_test.go index e37af4bbf6..169a9e2fed 100644 --- a/cli/command/service/create_test.go +++ b/cli/command/service/create_test.go @@ -21,19 +21,19 @@ func (f fakeConfigAPIClientList) ConfigList(ctx context.Context, opts types.Conf return f(ctx, opts) } -func (f fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (types.ConfigCreateResponse, error) { +func (fakeConfigAPIClientList) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (types.ConfigCreateResponse, error) { return types.ConfigCreateResponse{}, nil } -func (f fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error { +func (fakeConfigAPIClientList) ConfigRemove(_ context.Context, _ string) error { return nil } -func (f fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) { +func (fakeConfigAPIClientList) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) { return swarm.Config{}, nil, nil } -func (f fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error { +func (fakeConfigAPIClientList) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error { return nil } diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 9e043713be..499217ec11 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -503,7 +503,8 @@ func (ctx *serviceInspectContext) ResourceReservationNanoCPUs() float64 { if ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs == 0 { return float64(0) } - return float64(ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs) / 1e9 + const nano = 1e9 + return float64(ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs) / nano } func (ctx *serviceInspectContext) ResourceReservationMemory() string { @@ -521,7 +522,8 @@ func (ctx *serviceInspectContext) HasResourceLimits() bool { } func (ctx *serviceInspectContext) ResourceLimitsNanoCPUs() float64 { - return float64(ctx.Service.Spec.TaskTemplate.Resources.Limits.NanoCPUs) / 1e9 + const nano = 1e9 + return float64(ctx.Service.Spec.TaskTemplate.Resources.Limits.NanoCPUs) / nano } func (ctx *serviceInspectContext) ResourceLimitMemory() string { diff --git a/cli/command/service/generic_resource_opts.go b/cli/command/service/generic_resource_opts.go index 613c255749..ba5cf6aa5b 100644 --- a/cli/command/service/generic_resource_opts.go +++ b/cli/command/service/generic_resource_opts.go @@ -43,7 +43,9 @@ func ParseGenericResources(value []string) ([]swarm.GenericResource, error) { swarmResources := genericResourcesFromGRPC(resources) for _, res := range swarmResources { if res.NamedResourceSpec != nil { - return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update", res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value) + return nil, fmt.Errorf("invalid generic-resource request `%s=%s`, Named Generic Resources is not supported for service create or update", + res.NamedResourceSpec.Kind, res.NamedResourceSpec.Value, + ) } } diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index b9f964aec9..dd56f828f9 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -265,7 +265,7 @@ func (lw *logWriter) Write(buf []byte) (int, error) { // and then create a context from the details // this removes the context-specific details from the details map, so we // can more easily print the details later - logCtx, err := lw.parseContext(details) + logCtx, err := parseContext(details) if err != nil { return 0, err } @@ -317,7 +317,7 @@ func (lw *logWriter) Write(buf []byte) (int, error) { } // parseContext returns a log context and REMOVES the context from the details map -func (lw *logWriter) parseContext(details map[string]string) (logContext, error) { +func parseContext(details map[string]string) (logContext, error) { nodeID, ok := details["com.docker.swarm.node.id"] if !ok { return logContext{}, errors.Errorf("missing node id in details: %v", details) diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 9298cfb131..983e2233be 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -42,7 +42,7 @@ func (i *Uint64Opt) Set(s string) error { } // Type returns the type of this option, which will be displayed in `--help` output -func (i *Uint64Opt) Type() string { +func (*Uint64Opt) Type() string { return "uint" } @@ -67,7 +67,7 @@ func (f *floatValue) Set(s string) error { return err } -func (f *floatValue) Type() string { +func (*floatValue) Type() string { return "float" } @@ -114,7 +114,7 @@ func (o *placementPrefOpts) Set(value string) error { } // Type returns a string name for this Option type -func (o *placementPrefOpts) Type() string { +func (*placementPrefOpts) Type() string { return "pref" } @@ -132,7 +132,7 @@ func (s *ShlexOpt) Set(value string) error { } // Type returns the type of the value -func (s *ShlexOpt) Type() string { +func (*ShlexOpt) Type() string { return "command" } @@ -363,7 +363,7 @@ func (c *credentialSpecOpt) Set(value string) error { return nil } -func (c *credentialSpecOpt) Type() string { +func (*credentialSpecOpt) Type() string { return "credential-spec" } diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index edfabbd40d..09da18774c 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -273,8 +273,9 @@ func truncError(errMsg string) string { // Limit the length to 75 characters, so that even on narrow terminals // this will not overflow to the next line. - if len(errMsg) > 75 { - errMsg = errMsg[:74] + "…" + const maxWidth = 75 + if len(errMsg) > maxWidth { + errMsg = errMsg[:maxWidth-1] + "…" } return errMsg } @@ -349,7 +350,7 @@ func (u *replicatedProgressUpdater) update(service swarm.Service, tasks []swarm. return running == replicas, nil } -func (u *replicatedProgressUpdater) tasksBySlot(tasks []swarm.Task, activeNodes map[string]struct{}) map[int]swarm.Task { +func (*replicatedProgressUpdater) tasksBySlot(tasks []swarm.Task, activeNodes map[string]struct{}) map[int]swarm.Task { // If there are multiple tasks with the same slot number, favor the one // with the *lowest* desired state. This can happen in restart // scenarios. @@ -470,7 +471,7 @@ func (u *globalProgressUpdater) update(_ swarm.Service, tasks []swarm.Task, acti return running == nodeCount, nil } -func (u *globalProgressUpdater) tasksByNode(tasks []swarm.Task) map[string]swarm.Task { +func (*globalProgressUpdater) tasksByNode(tasks []swarm.Task) map[string]swarm.Task { // If there are multiple tasks with the same node ID, favor the one // with the *lowest* desired state. This can happen in restart // scenarios. diff --git a/cli/command/service/update_test.go b/cli/command/service/update_test.go index 136f655122..2ace1e2c24 100644 --- a/cli/command/service/update_test.go +++ b/cli/command/service/update_test.go @@ -508,19 +508,19 @@ func (s secretAPIClientMock) SecretList(context.Context, types.SecretListOptions return s.listResult, nil } -func (s secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) { +func (secretAPIClientMock) SecretCreate(context.Context, swarm.SecretSpec) (types.SecretCreateResponse, error) { return types.SecretCreateResponse{}, nil } -func (s secretAPIClientMock) SecretRemove(context.Context, string) error { +func (secretAPIClientMock) SecretRemove(context.Context, string) error { return nil } -func (s secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) { +func (secretAPIClientMock) SecretInspectWithRaw(context.Context, string) (swarm.Secret, []byte, error) { return swarm.Secret{}, []byte{}, nil } -func (s secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error { +func (secretAPIClientMock) SecretUpdate(context.Context, string, swarm.Version, swarm.SecretSpec) error { return nil } diff --git a/cli/command/stack/client_test.go b/cli/command/stack/client_test.go index 7d9072d2de..ea1ed02a4d 100644 --- a/cli/command/stack/client_test.go +++ b/cli/command/stack/client_test.go @@ -44,7 +44,7 @@ type fakeClient struct { configRemoveFunc func(configID string) error } -func (cli *fakeClient) ServerVersion(context.Context) (types.Version, error) { +func (*fakeClient) ServerVersion(context.Context) (types.Version, error) { return types.Version{ Version: "docker-dev", APIVersion: api.DefaultVersion, @@ -180,7 +180,7 @@ func (cli *fakeClient) ConfigRemove(_ context.Context, configID string) error { return nil } -func (cli *fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ types.ServiceInspectOptions) (swarm.Service, []byte, error) { +func (*fakeClient) ServiceInspectWithRaw(_ context.Context, serviceID string, _ types.ServiceInspectOptions) (swarm.Service, []byte, error) { return swarm.Service{ ID: serviceID, Spec: swarm.ServiceSpec{ diff --git a/cli/command/stack/swarm/client_test.go b/cli/command/stack/swarm/client_test.go index 78f4997c6a..28f6aac35c 100644 --- a/cli/command/stack/swarm/client_test.go +++ b/cli/command/stack/swarm/client_test.go @@ -44,7 +44,7 @@ type fakeClient struct { configRemoveFunc func(configID string) error } -func (cli *fakeClient) ServerVersion(context.Context) (types.Version, error) { +func (*fakeClient) ServerVersion(context.Context) (types.Version, error) { return types.Version{ Version: "docker-dev", APIVersion: api.DefaultVersion, diff --git a/cli/command/stack/swarm/deploy_composefile_test.go b/cli/command/stack/swarm/deploy_composefile_test.go index 0df678a84f..7df4b4551c 100644 --- a/cli/command/stack/swarm/deploy_composefile_test.go +++ b/cli/command/stack/swarm/deploy_composefile_test.go @@ -14,7 +14,7 @@ type notFound struct { error } -func (n notFound) NotFound() {} +func (notFound) NotFound() {} func TestValidateExternalNetworks(t *testing.T) { testcases := []struct { diff --git a/cli/command/swarm/opts.go b/cli/command/swarm/opts.go index f8ebc900e8..a29a67147c 100644 --- a/cli/command/swarm/opts.go +++ b/cli/command/swarm/opts.go @@ -68,7 +68,7 @@ func (a *NodeAddrOption) Set(value string) error { } // Type returns the type of this flag -func (a *NodeAddrOption) Type() string { +func (*NodeAddrOption) Type() string { return "node-addr" } @@ -104,7 +104,7 @@ func (m *ExternalCAOption) Set(value string) error { } // Type returns the type of this option. -func (m *ExternalCAOption) Type() string { +func (*ExternalCAOption) Type() string { return "external-ca" } @@ -129,7 +129,7 @@ type PEMFile struct { } // Type returns the type of this option. -func (p *PEMFile) Type() string { +func (*PEMFile) Type() string { return "pem-file" } diff --git a/cli/command/system/dial_stdio.go b/cli/command/system/dial_stdio.go index d4193ce8af..c8ccd181c7 100644 --- a/cli/command/system/dial_stdio.go +++ b/cli/command/system/dial_stdio.go @@ -110,7 +110,7 @@ type nopCloseReader struct { halfReadWriteCloser } -func (x *nopCloseReader) CloseRead() error { +func (*nopCloseReader) CloseRead() error { return nil } diff --git a/cli/command/telemetry.go b/cli/command/telemetry.go index d8985234a7..2ee8adfb46 100644 --- a/cli/command/telemetry.go +++ b/cli/command/telemetry.go @@ -54,11 +54,11 @@ func (cli *DockerCli) Resource() *resource.Resource { return cli.res.Get() } -func (cli *DockerCli) TracerProvider() trace.TracerProvider { +func (*DockerCli) TracerProvider() trace.TracerProvider { return otel.GetTracerProvider() } -func (cli *DockerCli) MeterProvider() metric.MeterProvider { +func (*DockerCli) MeterProvider() metric.MeterProvider { return otel.GetMeterProvider() } diff --git a/cli/command/trust/inspect_pretty_test.go b/cli/command/trust/inspect_pretty_test.go index b535c7a9f3..07e4edba41 100644 --- a/cli/command/trust/inspect_pretty_test.go +++ b/cli/command/trust/inspect_pretty_test.go @@ -28,15 +28,15 @@ type fakeClient struct { client.Client } -func (c *fakeClient) Info(context.Context) (system.Info, error) { +func (*fakeClient) Info(context.Context) (system.Info, error) { return system.Info{}, nil } -func (c *fakeClient) ImageInspect(context.Context, string, ...client.ImageInspectOption) (image.InspectResponse, error) { +func (*fakeClient) ImageInspect(context.Context, string, ...client.ImageInspectOption) (image.InspectResponse, error) { return image.InspectResponse{}, nil } -func (c *fakeClient) ImagePush(context.Context, string, image.PushOptions) (io.ReadCloser, error) { +func (*fakeClient) ImagePush(context.Context, string, image.PushOptions) (io.ReadCloser, error) { return &utils.NoopCloser{Reader: bytes.NewBuffer([]byte{})}, nil } diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index 564eb70a98..6cd2d2031d 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -269,7 +269,7 @@ type ForbiddenPropertiesError struct { Properties map[string]string } -func (e *ForbiddenPropertiesError) Error() string { +func (*ForbiddenPropertiesError) Error() string { return "Configuration contains forbidden properties" } diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 379015b6fd..aca348a01f 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -971,7 +971,7 @@ func uint32Ptr(value uint32) *uint32 { } func TestFullExample(t *testing.T) { - skip.If(t, runtime.GOOS == "windows", "FIXME: TestFullExample substitutes platform-specific HOME-directories and requires platform-specific golden files; see https://github.com/docker/cli/pull/4610") + skip.If(t, runtime.GOOS == "windows", "FIXME: substitutes platform-specific HOME-dirs and requires platform-specific golden files; see https://github.com/docker/cli/pull/4610") data, err := os.ReadFile("full-example.yml") assert.NilError(t, err) diff --git a/cli/compose/schema/schema.go b/cli/compose/schema/schema.go index 9c68166e37..b636ea5bbf 100644 --- a/cli/compose/schema/schema.go +++ b/cli/compose/schema/schema.go @@ -22,7 +22,7 @@ const ( type portsFormatChecker struct{} -func (checker portsFormatChecker) IsFormat(input any) bool { +func (portsFormatChecker) IsFormat(input any) bool { var portSpec string switch p := input.(type) { @@ -38,7 +38,7 @@ func (checker portsFormatChecker) IsFormat(input any) bool { type durationFormatChecker struct{} -func (checker durationFormatChecker) IsFormat(input any) bool { +func (durationFormatChecker) IsFormat(input any) bool { value, ok := input.(string) if !ok { return false diff --git a/cli/config/configfile/file_test.go b/cli/config/configfile/file_test.go index 51aac67964..d85c4a71fd 100644 --- a/cli/config/configfile/file_test.go +++ b/cli/config/configfile/file_test.go @@ -186,7 +186,7 @@ func (c *mockNativeStore) GetAll() (map[string]types.AuthConfig, error) { return c.authConfigs, nil } -func (c *mockNativeStore) Store(_ types.AuthConfig) error { +func (*mockNativeStore) Store(_ types.AuthConfig) error { return nil } diff --git a/cli/config/credentials/file_store_test.go b/cli/config/credentials/file_store_test.go index 5cf7d585a5..e4a43e11fb 100644 --- a/cli/config/credentials/file_store_test.go +++ b/cli/config/credentials/file_store_test.go @@ -26,7 +26,7 @@ func (f *fakeStore) GetAuthConfigs() map[string]types.AuthConfig { return f.configs } -func (f *fakeStore) GetFilename() string { +func (*fakeStore) GetFilename() string { return "no-config.json" } diff --git a/cli/connhelper/commandconn/commandconn.go b/cli/connhelper/commandconn/commandconn.go index c100b97ee6..52888a9100 100644 --- a/cli/connhelper/commandconn/commandconn.go +++ b/cli/connhelper/commandconn/commandconn.go @@ -253,17 +253,17 @@ func (c *commandConn) RemoteAddr() net.Addr { return c.remoteAddr } -func (c *commandConn) SetDeadline(t time.Time) error { +func (*commandConn) SetDeadline(t time.Time) error { logrus.Debugf("unimplemented call: SetDeadline(%v)", t) return nil } -func (c *commandConn) SetReadDeadline(t time.Time) error { +func (*commandConn) SetReadDeadline(t time.Time) error { logrus.Debugf("unimplemented call: SetReadDeadline(%v)", t) return nil } -func (c *commandConn) SetWriteDeadline(t time.Time) error { +func (*commandConn) SetWriteDeadline(t time.Time) error { logrus.Debugf("unimplemented call: SetWriteDeadline(%v)", t) return nil } diff --git a/cli/internal/oauth/api/api.go b/cli/internal/oauth/api/api.go index 98c981f029..cd9ceb7da1 100644 --- a/cli/internal/oauth/api/api.go +++ b/cli/internal/oauth/api/api.go @@ -224,7 +224,7 @@ func postForm(ctx context.Context, reqURL string, data io.Reader) (*http.Respons return http.DefaultClient.Do(req) } -func (a API) GetAutoPAT(ctx context.Context, audience string, res TokenResponse) (string, error) { +func (API) GetAutoPAT(ctx context.Context, audience string, res TokenResponse) (string, error) { patURL := audience + "/v2/access-tokens/desktop-generate" req, err := http.NewRequestWithContext(ctx, http.MethodPost, patURL, nil) if err != nil { diff --git a/cli/internal/oauth/manager/manager_test.go b/cli/internal/oauth/manager/manager_test.go index 39a9b86c2f..37fae3f918 100644 --- a/cli/internal/oauth/manager/manager_test.go +++ b/cli/internal/oauth/manager/manager_test.go @@ -14,7 +14,7 @@ import ( ) const ( - //nolint:lll + //nolint:revive // ignore line-length-limit validToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InhYa3BCdDNyV3MyRy11YjlscEpncSJ9.eyJodHRwczovL2h1Yi5kb2NrZXIuY29tIjp7ImVtYWlsIjoiYm9ya0Bkb2NrZXIuY29tIiwic2Vzc2lvbl9pZCI6ImEtc2Vzc2lvbi1pZCIsInNvdXJjZSI6InNhbWxwIiwidXNlcm5hbWUiOiJib3JrISIsInV1aWQiOiIwMTIzLTQ1Njc4OSJ9LCJpc3MiOiJodHRwczovL2xvZ2luLmRvY2tlci5jb20vIiwic3ViIjoic2FtbHB8c2FtbHAtZG9ja2VyfGJvcmtAZG9ja2VyLmNvbSIsImF1ZCI6WyJodHRwczovL2F1ZGllbmNlLmNvbSJdLCJpYXQiOjE3MTk1MDI5MzksImV4cCI6MTcxOTUwNjUzOSwic2NvcGUiOiJvcGVuaWQgb2ZmbGluZV9hY2Nlc3MifQ.VUSp-9_SOvMPWJPRrSh7p4kSPoye4DA3kyd2I0TW0QtxYSRq7xCzNj0NC_ywlPlKBFBeXKm4mh93d1vBSh79I9Heq5tj0Fr4KH77U5xJRMEpjHqoT5jxMEU1hYXX92xctnagBMXxDvzUfu3Yf0tvYSA0RRoGbGTHfdYYRwOrGbwQ75Qg1dyIxUkwsG053eYX2XkmLGxymEMgIq_gWksgAamOc40_0OCdGr-MmDeD2HyGUa309aGltzQUw7Z0zG1AKSXy3WwfMHdWNFioTAvQphwEyY3US8ybSJi78upSFTjwUcryMeHUwQ3uV9PxwPMyPoYxo1izVB-OUJxM8RqEbg" ) @@ -346,7 +346,7 @@ type fakeStore struct { configs map[string]types.AuthConfig } -func (f *fakeStore) Save() error { +func (*fakeStore) Save() error { return nil } @@ -354,7 +354,7 @@ func (f *fakeStore) GetAuthConfigs() map[string]types.AuthConfig { return f.configs } -func (f *fakeStore) GetFilename() string { +func (*fakeStore) GetFilename() string { return "/tmp/docker-fakestore" } diff --git a/cli/manifest/store/store.go b/cli/manifest/store/store.go index c4f8219cec..e97e8628f1 100644 --- a/cli/manifest/store/store.go +++ b/cli/manifest/store/store.go @@ -44,7 +44,7 @@ func (s *fsStore) Get(listRef reference.Reference, manifest reference.Reference) return s.getFromFilename(manifest, filename) } -func (s *fsStore) getFromFilename(ref reference.Reference, filename string) (types.ImageManifest, error) { +func (*fsStore) getFromFilename(ref reference.Reference, filename string) (types.ImageManifest, error) { bytes, err := os.ReadFile(filename) switch { case os.IsNotExist(err): @@ -165,7 +165,7 @@ func (n *notFoundError) Error() string { } // NotFound interface -func (n *notFoundError) NotFound() {} +func (*notFoundError) NotFound() {} // IsNotFound returns true if the error is a not found error func IsNotFound(err error) bool { diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index 2446da85a0..95312b0558 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -123,6 +123,6 @@ func (th *existingTokenHandler) AuthorizeRequest(req *http.Request, _ map[string return nil } -func (th *existingTokenHandler) Scheme() string { +func (*existingTokenHandler) Scheme() string { return "bearer" } diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index 3e4b36d309..d1f255bf9f 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -304,4 +304,4 @@ func (n *notFoundError) Error() string { } // NotFound satisfies interface github.com/docker/docker/errdefs.ErrNotFound -func (n *notFoundError) NotFound() {} +func (notFoundError) NotFound() {} diff --git a/cli/trust/trust.go b/cli/trust/trust.go index 5e08b49ec5..bb7e597aa5 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -89,7 +89,7 @@ func (scs simpleCredentialStore) RefreshToken(*url.URL, string) string { return scs.auth.IdentityToken } -func (scs simpleCredentialStore) SetRefreshToken(*url.URL, string, string) {} +func (simpleCredentialStore) SetRefreshToken(*url.URL, string, string) {} // GetNotaryRepository returns a NotaryRepository which stores all the // information needed to operate on a notary repository. diff --git a/cmd/docker/builder_test.go b/cmd/docker/builder_test.go index 5f7875ff83..eac2dc5b23 100644 --- a/cmd/docker/builder_test.go +++ b/cmd/docker/builder_test.go @@ -127,7 +127,7 @@ type fakeClient struct { client.Client } -func (c *fakeClient) Ping(_ context.Context) (types.Ping, error) { +func (*fakeClient) Ping(context.Context) (types.Ping, error) { return types.Ping{OSType: "linux"}, nil } diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index b5cb621923..46a235c4bd 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -32,7 +32,7 @@ type errCtxSignalTerminated struct { signal os.Signal } -func (e errCtxSignalTerminated) Error() string { +func (errCtxSignalTerminated) Error() string { return "" } diff --git a/internal/test/cli.go b/internal/test/cli.go index f84413ba81..35e4a317a5 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -208,6 +208,6 @@ func EnableContentTrust(c *FakeCli) { } // BuildKitEnabled on the fake cli -func (c *FakeCli) BuildKitEnabled() (bool, error) { +func (*FakeCli) BuildKitEnabled() (bool, error) { return true, nil } diff --git a/internal/test/notary/client.go b/internal/test/notary/client.go index b6c6db0e58..3ee625fd3b 100644 --- a/internal/test/notary/client.go +++ b/internal/test/notary/client.go @@ -22,127 +22,127 @@ type OfflineNotaryRepository struct{} // Initialize creates a new repository by using rootKey as the root Key for the // TUF repository. -func (o OfflineNotaryRepository) Initialize([]string, ...data.RoleName) error { +func (OfflineNotaryRepository) Initialize([]string, ...data.RoleName) error { return storage.ErrOffline{} } // InitializeWithCertificate initializes the repository with root keys and their corresponding certificates -func (o OfflineNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { +func (OfflineNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { return storage.ErrOffline{} } // Publish pushes the local changes in signed material to the remote notary-server // Conceptually it performs an operation similar to a `git rebase` -func (o OfflineNotaryRepository) Publish() error { +func (OfflineNotaryRepository) Publish() error { return storage.ErrOffline{} } // AddTarget creates new changelist entries to add a target to the given roles // in the repository when the changelist gets applied at publish time. -func (o OfflineNotaryRepository) AddTarget(*client.Target, ...data.RoleName) error { +func (OfflineNotaryRepository) AddTarget(*client.Target, ...data.RoleName) error { return nil } // RemoveTarget creates new changelist entries to remove a target from the given // roles in the repository when the changelist gets applied at publish time. -func (o OfflineNotaryRepository) RemoveTarget(string, ...data.RoleName) error { +func (OfflineNotaryRepository) RemoveTarget(string, ...data.RoleName) error { return nil } // ListTargets lists all targets for the current repository. The list of // roles should be passed in order from highest to lowest priority. -func (o OfflineNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { +func (OfflineNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { return nil, storage.ErrOffline{} } // GetTargetByName returns a target by the given name. -func (o OfflineNotaryRepository) GetTargetByName(string, ...data.RoleName) (*client.TargetWithRole, error) { +func (OfflineNotaryRepository) GetTargetByName(string, ...data.RoleName) (*client.TargetWithRole, error) { return nil, storage.ErrOffline{} } // GetAllTargetMetadataByName searches the entire delegation role tree to find the specified target by name for all // roles, and returns a list of TargetSignedStructs for each time it finds the specified target. -func (o OfflineNotaryRepository) GetAllTargetMetadataByName(string) ([]client.TargetSignedStruct, error) { +func (OfflineNotaryRepository) GetAllTargetMetadataByName(string) ([]client.TargetSignedStruct, error) { return nil, storage.ErrOffline{} } // GetChangelist returns the list of the repository's unpublished changes -func (o OfflineNotaryRepository) GetChangelist() (changelist.Changelist, error) { +func (OfflineNotaryRepository) GetChangelist() (changelist.Changelist, error) { return changelist.NewMemChangelist(), nil } // ListRoles returns a list of RoleWithSignatures objects for this repo -func (o OfflineNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { +func (OfflineNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { return nil, storage.ErrOffline{} } // GetDelegationRoles returns the keys and roles of the repository's delegations -func (o OfflineNotaryRepository) GetDelegationRoles() ([]data.Role, error) { +func (OfflineNotaryRepository) GetDelegationRoles() ([]data.Role, error) { return nil, storage.ErrOffline{} } // AddDelegation creates changelist entries to add provided delegation public keys and paths. -func (o OfflineNotaryRepository) AddDelegation(data.RoleName, []data.PublicKey, []string) error { +func (OfflineNotaryRepository) AddDelegation(data.RoleName, []data.PublicKey, []string) error { return nil } // AddDelegationRoleAndKeys creates a changelist entry to add provided delegation public keys. -func (o OfflineNotaryRepository) AddDelegationRoleAndKeys(data.RoleName, []data.PublicKey) error { +func (OfflineNotaryRepository) AddDelegationRoleAndKeys(data.RoleName, []data.PublicKey) error { return nil } // AddDelegationPaths creates a changelist entry to add provided paths to an existing delegation. -func (o OfflineNotaryRepository) AddDelegationPaths(data.RoleName, []string) error { +func (OfflineNotaryRepository) AddDelegationPaths(data.RoleName, []string) error { return nil } // RemoveDelegationKeysAndPaths creates changelist entries to remove provided delegation key IDs and paths. -func (o OfflineNotaryRepository) RemoveDelegationKeysAndPaths(data.RoleName, []string, []string) error { +func (OfflineNotaryRepository) RemoveDelegationKeysAndPaths(data.RoleName, []string, []string) error { return nil } // RemoveDelegationRole creates a changelist to remove all paths and keys from a role, and delete the role in its entirety. -func (o OfflineNotaryRepository) RemoveDelegationRole(data.RoleName) error { +func (OfflineNotaryRepository) RemoveDelegationRole(data.RoleName) error { return nil } // RemoveDelegationPaths creates a changelist entry to remove provided paths from an existing delegation. -func (o OfflineNotaryRepository) RemoveDelegationPaths(data.RoleName, []string) error { +func (OfflineNotaryRepository) RemoveDelegationPaths(data.RoleName, []string) error { return nil } // RemoveDelegationKeys creates a changelist entry to remove provided keys from an existing delegation. -func (o OfflineNotaryRepository) RemoveDelegationKeys(data.RoleName, []string) error { +func (OfflineNotaryRepository) RemoveDelegationKeys(data.RoleName, []string) error { return nil } // ClearDelegationPaths creates a changelist entry to remove all paths from an existing delegation. -func (o OfflineNotaryRepository) ClearDelegationPaths(data.RoleName) error { +func (OfflineNotaryRepository) ClearDelegationPaths(data.RoleName) error { return nil } // Witness creates change objects to witness (i.e. re-sign) the given // roles on the next publish. One change is created per role -func (o OfflineNotaryRepository) Witness(...data.RoleName) ([]data.RoleName, error) { +func (OfflineNotaryRepository) Witness(...data.RoleName) ([]data.RoleName, error) { return nil, nil } // RotateKey rotates a private key and returns the public component from the remote server -func (o OfflineNotaryRepository) RotateKey(data.RoleName, bool, []string) error { +func (OfflineNotaryRepository) RotateKey(data.RoleName, bool, []string) error { return storage.ErrOffline{} } // GetCryptoService is the getter for the repository's CryptoService -func (o OfflineNotaryRepository) GetCryptoService() signed.CryptoService { +func (OfflineNotaryRepository) GetCryptoService() signed.CryptoService { return nil } // SetLegacyVersions allows the number of legacy versions of the root // to be inspected for old signing keys to be configured. -func (o OfflineNotaryRepository) SetLegacyVersions(int) {} +func (OfflineNotaryRepository) SetLegacyVersions(int) {} // GetGUN is a getter for the GUN object from a Repository -func (o OfflineNotaryRepository) GetGUN() data.GUN { +func (OfflineNotaryRepository) GetGUN() data.GUN { return data.GUN("gun") } @@ -160,50 +160,50 @@ type UninitializedNotaryRepository struct { // Initialize creates a new repository by using rootKey as the root Key for the // TUF repository. -func (u UninitializedNotaryRepository) Initialize([]string, ...data.RoleName) error { +func (UninitializedNotaryRepository) Initialize([]string, ...data.RoleName) error { return client.ErrRepositoryNotExist{} } // InitializeWithCertificate initializes the repository with root keys and their corresponding certificates -func (u UninitializedNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { +func (UninitializedNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { return client.ErrRepositoryNotExist{} } // Publish pushes the local changes in signed material to the remote notary-server // Conceptually it performs an operation similar to a `git rebase` -func (u UninitializedNotaryRepository) Publish() error { +func (UninitializedNotaryRepository) Publish() error { return client.ErrRepositoryNotExist{} } // ListTargets lists all targets for the current repository. The list of // roles should be passed in order from highest to lowest priority. -func (u UninitializedNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { +func (UninitializedNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { return nil, client.ErrRepositoryNotExist{} } // GetTargetByName returns a target by the given name. -func (u UninitializedNotaryRepository) GetTargetByName(string, ...data.RoleName) (*client.TargetWithRole, error) { +func (UninitializedNotaryRepository) GetTargetByName(string, ...data.RoleName) (*client.TargetWithRole, error) { return nil, client.ErrRepositoryNotExist{} } // GetAllTargetMetadataByName searches the entire delegation role tree to find the specified target by name for all // roles, and returns a list of TargetSignedStructs for each time it finds the specified target. -func (u UninitializedNotaryRepository) GetAllTargetMetadataByName(string) ([]client.TargetSignedStruct, error) { +func (UninitializedNotaryRepository) GetAllTargetMetadataByName(string) ([]client.TargetSignedStruct, error) { return nil, client.ErrRepositoryNotExist{} } // ListRoles returns a list of RoleWithSignatures objects for this repo -func (u UninitializedNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { +func (UninitializedNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { return nil, client.ErrRepositoryNotExist{} } // GetDelegationRoles returns the keys and roles of the repository's delegations -func (u UninitializedNotaryRepository) GetDelegationRoles() ([]data.Role, error) { +func (UninitializedNotaryRepository) GetDelegationRoles() ([]data.Role, error) { return nil, client.ErrRepositoryNotExist{} } // RotateKey rotates a private key and returns the public component from the remote server -func (u UninitializedNotaryRepository) RotateKey(data.RoleName, bool, []string) error { +func (UninitializedNotaryRepository) RotateKey(data.RoleName, bool, []string) error { return client.ErrRepositoryNotExist{} } @@ -220,40 +220,40 @@ type EmptyTargetsNotaryRepository struct { // Initialize creates a new repository by using rootKey as the root Key for the // TUF repository. -func (e EmptyTargetsNotaryRepository) Initialize([]string, ...data.RoleName) error { +func (EmptyTargetsNotaryRepository) Initialize([]string, ...data.RoleName) error { return nil } // InitializeWithCertificate initializes the repository with root keys and their corresponding certificates -func (e EmptyTargetsNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { +func (EmptyTargetsNotaryRepository) InitializeWithCertificate([]string, []data.PublicKey, ...data.RoleName) error { return nil } // Publish pushes the local changes in signed material to the remote notary-server // Conceptually it performs an operation similar to a `git rebase` -func (e EmptyTargetsNotaryRepository) Publish() error { +func (EmptyTargetsNotaryRepository) Publish() error { return nil } // ListTargets lists all targets for the current repository. The list of // roles should be passed in order from highest to lowest priority. -func (e EmptyTargetsNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { +func (EmptyTargetsNotaryRepository) ListTargets(...data.RoleName) ([]*client.TargetWithRole, error) { return []*client.TargetWithRole{}, nil } // GetTargetByName returns a target by the given name. -func (e EmptyTargetsNotaryRepository) GetTargetByName(name string, _ ...data.RoleName) (*client.TargetWithRole, error) { +func (EmptyTargetsNotaryRepository) GetTargetByName(name string, _ ...data.RoleName) (*client.TargetWithRole, error) { return nil, client.ErrNoSuchTarget(name) } // GetAllTargetMetadataByName searches the entire delegation role tree to find the specified target by name for all // roles, and returns a list of TargetSignedStructs for each time it finds the specified target. -func (e EmptyTargetsNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { +func (EmptyTargetsNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { return nil, client.ErrNoSuchTarget(name) } // ListRoles returns a list of RoleWithSignatures objects for this repo -func (e EmptyTargetsNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { +func (EmptyTargetsNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { rootRole := data.Role{ RootRole: data.RootRole{ KeyIDs: []string{"rootID"}, @@ -276,12 +276,12 @@ func (e EmptyTargetsNotaryRepository) ListRoles() ([]client.RoleWithSignatures, } // GetDelegationRoles returns the keys and roles of the repository's delegations -func (e EmptyTargetsNotaryRepository) GetDelegationRoles() ([]data.Role, error) { +func (EmptyTargetsNotaryRepository) GetDelegationRoles() ([]data.Role, error) { return []data.Role{}, nil } // RotateKey rotates a private key and returns the public component from the remote server -func (e EmptyTargetsNotaryRepository) RotateKey(data.RoleName, bool, []string) error { +func (EmptyTargetsNotaryRepository) RotateKey(data.RoleName, bool, []string) error { return nil } @@ -390,7 +390,7 @@ var loadedTargets = []client.TargetSignedStruct{ } // ListRoles returns a list of RoleWithSignatures objects for this repo -func (l LoadedNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { +func (LoadedNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) { rootRole := data.Role{ RootRole: data.RootRole{ KeyIDs: []string{"rootID"}, @@ -444,7 +444,7 @@ func (l LoadedNotaryRepository) ListRoles() ([]client.RoleWithSignatures, error) // ListTargets lists all targets for the current repository. The list of // roles should be passed in order from highest to lowest priority. -func (l LoadedNotaryRepository) ListTargets(roles ...data.RoleName) ([]*client.TargetWithRole, error) { +func (LoadedNotaryRepository) ListTargets(roles ...data.RoleName) ([]*client.TargetWithRole, error) { filteredTargets := []*client.TargetWithRole{} for _, tgt := range loadedTargets { if len(roles) == 0 || (len(roles) > 0 && roles[0] == tgt.Role.Name) { @@ -455,7 +455,7 @@ func (l LoadedNotaryRepository) ListTargets(roles ...data.RoleName) ([]*client.T } // GetTargetByName returns a target by the given name. -func (l LoadedNotaryRepository) GetTargetByName(name string, roles ...data.RoleName) (*client.TargetWithRole, error) { +func (LoadedNotaryRepository) GetTargetByName(name string, roles ...data.RoleName) (*client.TargetWithRole, error) { for _, tgt := range loadedTargets { if name == tgt.Target.Name { if len(roles) == 0 || (len(roles) > 0 && roles[0] == tgt.Role.Name) { @@ -468,7 +468,7 @@ func (l LoadedNotaryRepository) GetTargetByName(name string, roles ...data.RoleN // GetAllTargetMetadataByName searches the entire delegation role tree to find the specified target by name for all // roles, and returns a list of TargetSignedStructs for each time it finds the specified target. -func (l LoadedNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { +func (LoadedNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { if name == "" { return loadedTargets, nil } @@ -485,12 +485,12 @@ func (l LoadedNotaryRepository) GetAllTargetMetadataByName(name string) ([]clien } // GetGUN is a getter for the GUN object from a Repository -func (l LoadedNotaryRepository) GetGUN() data.GUN { - return data.GUN("signed-repo") +func (LoadedNotaryRepository) GetGUN() data.GUN { + return "signed-repo" } // GetDelegationRoles returns the keys and roles of the repository's delegations -func (l LoadedNotaryRepository) GetDelegationRoles() ([]data.Role, error) { +func (LoadedNotaryRepository) GetDelegationRoles() ([]data.Role, error) { return loadedDelegationRoles, nil } @@ -518,7 +518,7 @@ type LoadedWithNoSignersNotaryRepository struct { // ListTargets lists all targets for the current repository. The list of // roles should be passed in order from highest to lowest priority. -func (l LoadedWithNoSignersNotaryRepository) ListTargets(roles ...data.RoleName) ([]*client.TargetWithRole, error) { +func (LoadedWithNoSignersNotaryRepository) ListTargets(roles ...data.RoleName) ([]*client.TargetWithRole, error) { filteredTargets := []*client.TargetWithRole{} for _, tgt := range loadedTargets { if len(roles) == 0 || (len(roles) > 0 && roles[0] == tgt.Role.Name) { @@ -529,7 +529,7 @@ func (l LoadedWithNoSignersNotaryRepository) ListTargets(roles ...data.RoleName) } // GetTargetByName returns a target by the given name. -func (l LoadedWithNoSignersNotaryRepository) GetTargetByName(name string, _ ...data.RoleName) (*client.TargetWithRole, error) { +func (LoadedWithNoSignersNotaryRepository) GetTargetByName(name string, _ ...data.RoleName) (*client.TargetWithRole, error) { if name == "" || name == loadedGreenTarget.Name { return &client.TargetWithRole{Target: loadedGreenTarget, Role: data.CanonicalTargetsRole}, nil } @@ -538,7 +538,7 @@ func (l LoadedWithNoSignersNotaryRepository) GetTargetByName(name string, _ ...d // GetAllTargetMetadataByName searches the entire delegation role tree to find the specified target by name for all // roles, and returns a list of TargetSignedStructs for each time it finds the specified target. -func (l LoadedWithNoSignersNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { +func (LoadedWithNoSignersNotaryRepository) GetAllTargetMetadataByName(name string) ([]client.TargetSignedStruct, error) { if name == "" || name == loadedGreenTarget.Name { return []client.TargetSignedStruct{{Target: loadedGreenTarget, Role: loadedTargetsRole}}, nil } @@ -546,6 +546,6 @@ func (l LoadedWithNoSignersNotaryRepository) GetAllTargetMetadataByName(name str } // GetDelegationRoles returns the keys and roles of the repository's delegations -func (l LoadedWithNoSignersNotaryRepository) GetDelegationRoles() ([]data.Role, error) { +func (LoadedWithNoSignersNotaryRepository) GetDelegationRoles() ([]data.Role, error) { return []data.Role{}, nil } diff --git a/internal/tui/colors.go b/internal/tui/colors.go index c36dfabc85..796aa390ed 100644 --- a/internal/tui/colors.go +++ b/internal/tui/colors.go @@ -24,10 +24,10 @@ func (a noColor) With(_ ...aec.ANSI) aec.ANSI { return a } -func (a noColor) Apply(s string) string { +func (noColor) Apply(s string) string { return s } -func (a noColor) String() string { +func (noColor) String() string { return "" } diff --git a/opts/config.go b/opts/config.go index 1423ae3be5..1fc0eb356b 100644 --- a/opts/config.go +++ b/opts/config.go @@ -80,7 +80,7 @@ func (o *ConfigOpt) Set(value string) error { } // Type returns the type of this option -func (o *ConfigOpt) Type() string { +func (*ConfigOpt) Type() string { return "config" } diff --git a/opts/duration.go b/opts/duration.go index 5dc6eeaa73..d55c51e622 100644 --- a/opts/duration.go +++ b/opts/duration.go @@ -46,7 +46,7 @@ func (d *DurationOpt) Set(s string) error { } // Type returns the type of this option, which will be displayed in `--help` output -func (d *DurationOpt) Type() string { +func (*DurationOpt) Type() string { return "duration" } diff --git a/opts/gpus.go b/opts/gpus.go index 93bf939786..993f6da9ae 100644 --- a/opts/gpus.go +++ b/opts/gpus.go @@ -92,7 +92,7 @@ func (o *GpuOpts) Set(value string) error { } // Type returns the type of this option -func (o *GpuOpts) Type() string { +func (*GpuOpts) Type() string { return "gpu-request" } diff --git a/opts/mount.go b/opts/mount.go index 5e23a51394..275a4d7f87 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -215,7 +215,7 @@ func (m *MountOpt) Set(value string) error { } // Type returns the type of this option -func (m *MountOpt) Type() string { +func (*MountOpt) Type() string { return "mount" } diff --git a/opts/network.go b/opts/network.go index 2ce5dff1f8..c3510870e7 100644 --- a/opts/network.go +++ b/opts/network.go @@ -106,7 +106,7 @@ func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo } // Type returns the type of this option -func (n *NetworkOpt) Type() string { +func (*NetworkOpt) Type() string { return "network" } @@ -116,7 +116,7 @@ func (n *NetworkOpt) Value() []NetworkAttachmentOpts { } // String returns the network opts as a string -func (n *NetworkOpt) String() string { +func (*NetworkOpt) String() string { return "" } diff --git a/opts/opts.go b/opts/opts.go index 157b30f34b..061fda57c5 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -110,7 +110,7 @@ func (opts *ListOpts) Len() int { } // Type returns a string name for this Option type -func (opts *ListOpts) Type() string { +func (*ListOpts) Type() string { return "list" } @@ -180,7 +180,7 @@ func (opts *MapOpts) String() string { } // Type returns a string name for this Option type -func (opts *MapOpts) Type() string { +func (*MapOpts) Type() string { return "map" } @@ -358,7 +358,7 @@ func (o *FilterOpt) Set(value string) error { } // Type returns the option type -func (o *FilterOpt) Type() string { +func (*FilterOpt) Type() string { return "filter" } @@ -386,7 +386,7 @@ func (c *NanoCPUs) Set(value string) error { } // Type returns the type -func (c *NanoCPUs) Type() string { +func (*NanoCPUs) Type() string { return "decimal" } @@ -463,7 +463,7 @@ func (m *MemBytes) Set(value string) error { } // Type returns the type -func (m *MemBytes) Type() string { +func (*MemBytes) Type() string { return "bytes" } @@ -498,7 +498,7 @@ func (m *MemSwapBytes) Set(value string) error { } // Type returns the type -func (m *MemSwapBytes) Type() string { +func (*MemSwapBytes) Type() string { return "bytes" } diff --git a/opts/opts_test.go b/opts/opts_test.go index 14a36825a2..a69153ca25 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -190,7 +190,6 @@ func TestListOptsWithValidator(t *testing.T) { } } -//nolint:lll func TestValidateDNSSearch(t *testing.T) { valid := []string{ `.`, @@ -232,7 +231,11 @@ func TestValidateDNSSearch(t *testing.T) { `foo.bar-.baz`, `foo.-bar`, `foo.-bar.baz`, - `foo.bar.baz.this.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbe`, + `foo.bar.baz.` + + `this.should.fail.on.long.name.because.it.is.longer.thanisshouldbe` + + `this.should.fail.on.long.name.because.it.is.longer.thanisshouldbe` + + `this.should.fail.on.long.name.because.it.is.longer.thanisshouldbe` + + `this.should.fail.on.long.name.because.it.is.longer.thanisshouldbe`, } for _, domain := range valid { diff --git a/opts/port.go b/opts/port.go index 099aae3534..0407355e65 100644 --- a/opts/port.go +++ b/opts/port.go @@ -121,7 +121,7 @@ func (p *PortOpt) Set(value string) error { } // Type returns the type of this option -func (p *PortOpt) Type() string { +func (*PortOpt) Type() string { return "port" } diff --git a/opts/quotedstring.go b/opts/quotedstring.go index 741f450b14..eb2ac7fbc8 100644 --- a/opts/quotedstring.go +++ b/opts/quotedstring.go @@ -13,7 +13,7 @@ func (s *QuotedString) Set(val string) error { } // Type returns the type of the value -func (s *QuotedString) Type() string { +func (*QuotedString) Type() string { return "string" } diff --git a/opts/secret.go b/opts/secret.go index 09d2b2b3be..bdf232de63 100644 --- a/opts/secret.go +++ b/opts/secret.go @@ -79,7 +79,7 @@ func (o *SecretOpt) Set(value string) error { } // Type returns the type of this option -func (o *SecretOpt) Type() string { +func (*SecretOpt) Type() string { return "secret" } diff --git a/opts/throttledevice.go b/opts/throttledevice.go index 8bf1288047..46b09185c7 100644 --- a/opts/throttledevice.go +++ b/opts/throttledevice.go @@ -100,6 +100,6 @@ func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice { } // Type returns the option type -func (opt *ThrottledeviceOpt) Type() string { +func (*ThrottledeviceOpt) Type() string { return "list" } diff --git a/opts/ulimit.go b/opts/ulimit.go index 1409a109bc..48052c887c 100644 --- a/opts/ulimit.go +++ b/opts/ulimit.go @@ -58,6 +58,6 @@ func (o *UlimitOpt) GetList() []*container.Ulimit { } // Type returns the option type -func (o *UlimitOpt) Type() string { +func (*UlimitOpt) Type() string { return "ulimit" } diff --git a/opts/weightdevice.go b/opts/weightdevice.go index ee377fc33a..036c7c8c50 100644 --- a/opts/weightdevice.go +++ b/opts/weightdevice.go @@ -79,6 +79,6 @@ func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice { } // Type returns the option type -func (opt *WeightdeviceOpt) Type() string { +func (*WeightdeviceOpt) Type() string { return "list" }