Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a368e3e
cmd/docker: fix unused-receiver (revive)
thaJeztah Nov 5, 2024
2f65cf7
cli/command: fix some unused-receiver linting
thaJeztah Nov 5, 2024
3825d37
cli/command: define some consts for repeated values
thaJeztah Oct 31, 2024
9fda913
cli/command/service/progress: define const for magic value
thaJeztah Nov 4, 2024
d8e76bc
cli: define const for magic value
thaJeztah Nov 4, 2024
eef4127
cli/internal/oauth/manager: ignore line-length-limit
thaJeztah Nov 4, 2024
cac88ca
cli/command: wrap some long lines (revive)
thaJeztah Nov 4, 2024
20c15ce
cli/compose/loader: shorten skip-comment to please the linters
thaJeztah Nov 5, 2024
88b2e78
internal/tui: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
fdc6658
cli/config/credentials: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
d0c3380
cli/connhelper/commandconn: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
f79193c
opts: fix "unused-receiver", line-length-limit linting
thaJeztah Feb 17, 2025
9b62e57
cli/config/configfile: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
1e7add9
cli/internal/oauth/api: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
20b4ab3
cli/compose: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
c8bd0a7
cli/manifest: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
f0f19c6
cli/trust: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
ba3f4fb
cli/internal/oauth/manager: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
72b32c6
internal/test/notary: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
d27f6a6
cli/registry: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
1b3718f
cli/command: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
e5f3cc1
internal/test: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
450768c
cli-plugins/manager: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
25e6b2d
cli/command/formatter: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
a54d356
cli/command/swarm: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
e2f28fa
cli/command/registry: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
3e44cc4
cli/command/image: fix "unused-receiver", "line-length-limit" linting
thaJeztah Feb 17, 2025
4827fde
cli/command/trust: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
e71380e
cli/command/container: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
5ef673b
cli/command/system: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
994e1b7
cli/command/service: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
1a4491f
cli/command/stack: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
a35b899
cmd/docker: fix "unused-receiver" linting
thaJeztah Feb 17, 2025
71c40df
golangci-lint: sort revive rules
thaJeztah Nov 5, 2024
a67c656
golangci-lint: enable revive "unused-receiver" rule
thaJeztah Nov 5, 2024
2b169c1
golangci-lint: enable revive "line-length-limit" linter
thaJeztah Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli-plugins/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type DockerCli struct {
}

// DefaultVersion returns api.defaultVersion.
func (cli *DockerCli) DefaultVersion() string {
func (*DockerCli) DefaultVersion() string {
return api.DefaultVersion
}

Expand Down Expand Up @@ -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"))
}
Expand Down
15 changes: 12 additions & 3 deletions cli/command/cli_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -191,15 +194,21 @@ 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.
// This is something we could allow in future (e.g. to read value
// 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
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
14 changes: 8 additions & 6 deletions cli/command/container/formatter_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 7 additions & 3 deletions cli/command/formatter/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
},
{
Expand Down Expand Up @@ -525,7 +530,6 @@ type ports struct {
expected string
}

//nolint:lll
func TestDisplayablePorts(t *testing.T) {
cases := []ports{
{
Expand Down Expand Up @@ -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)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cli/command/formatter/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 5 additions & 5 deletions cli/command/formatter/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (c *diskUsageImagesContext) MarshalJSON() ([]byte, error) {
return MarshalJSON(c)
}

func (c *diskUsageImagesContext) Type() string {
func (*diskUsageImagesContext) Type() string {
return "Images"
}

Expand Down Expand Up @@ -321,15 +321,15 @@ func (c *diskUsageContainersContext) MarshalJSON() ([]byte, error) {
return MarshalJSON(c)
}

func (c *diskUsageContainersContext) Type() string {
func (*diskUsageContainersContext) Type() string {
return "Containers"
}

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")
Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion cli/command/formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type fakeSubContext struct {
Name string
}

func (f fakeSubContext) FullHeader() any {
func (fakeSubContext) FullHeader() any {
return map[string]string{"Name": "NAME"}
}

Expand Down
14 changes: 7 additions & 7 deletions cli/command/formatter/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

Expand Down
10 changes: 5 additions & 5 deletions cli/command/image/formatter_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion cli/command/image/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
Expand Down
3 changes: 2 additions & 1 deletion cli/command/node/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/plugin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/registry/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Loading