Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
  • Loading branch information
silvin-lubecki committed Feb 27, 2024
1 parent 1382c60 commit 7f68742
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ARG GO_VERSION=1.22.0-alpine3.19
ARG CLI_VERSION=20.10.2
ARG ALPINE_VERSION=3.19.0
ARG GOLANGCI_LINT_VERSION=v1.33.0-alpine
ARG GOLANGCI_LINT_VERSION=v1.56.2-alpine

####
# BUILDER
Expand Down
5 changes: 2 additions & 3 deletions e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/docker/cli/cli/config/configfile"
clitypes "github.com/docker/cli/cli/config/types"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
"gotest.tools/v3/icmd"
)
Expand All @@ -48,10 +47,10 @@ func hubToolCmd(t *testing.T, args ...string) (icmd.Cmd, func()) {
assert.NilError(t, err)
hubTool := os.Getenv("BINARY")
configDir := fs.NewDir(t, t.Name(), fs.WithFile("config.json", string(data)))
cleanup := env.Patch(t, "PATH", os.Getenv("PATH")+getPathSeparator()+filepath.Join(pwd, "..", "bin"))
t.Setenv("PATH", os.Getenv("PATH")+getPathSeparator()+filepath.Join(pwd, "..", "bin"))
env := append(os.Environ(), "DOCKER_CONFIG="+configDir.Path())

return icmd.Cmd{Command: append([]string{hubTool}, args...), Env: env}, func() { cleanup(); configDir.Remove() }
return icmd.Cmd{Command: append([]string{hubTool}, args...), Env: env}, func() { configDir.Remove() }
}

func getPathSeparator() string {
Expand Down
30 changes: 15 additions & 15 deletions internal/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (

var (
// Outputs ANSI color if stdout is a tty
Red = makeColorFunc("red")
Yellow = makeColorFunc("yellow")
Blue = makeColorFunc("blue")
Green = makeColorFunc("green")
red = makeColorFunc("red")
yellow = makeColorFunc("yellow")
blue = makeColorFunc("blue")
green = makeColorFunc("green")
)

func makeColorFunc(color string) func(string) string {
Expand All @@ -56,32 +56,32 @@ func isColorEnabled() bool {
}

// TODO ignores cmd.OutOrStdout
return IsTerminal(os.Stdout)
return isTerminal(os.Stdout)
}

var IsTerminal = func(f *os.File) bool {
return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
var isTerminal = func(f *os.File) bool {
return isatty.IsTerminal(f.Fd()) || isCygwinTerminal(f)
}

func IsCygwinTerminal(f *os.File) bool {
func isCygwinTerminal(f *os.File) bool {
return isatty.IsCygwinTerminal(f.Fd())
}

var (
// Title color should be used for any important title
Title = Green
Title = green
// Header color should be used for all the listing column headers
Header = Blue
Header = blue
// Key color should be used for all key title content
Key = Blue
Key = blue
// Info color should be used when we prompt an info
Info = Blue
Info = blue
// Warn color should be used when we warn the user
Warn = Yellow
Warn = yellow
// Error color should be used when something bad happened
Error = Red
Error = red
// Emphasise color should be used with important content
Emphasise = Green
Emphasise = green
// NoColor doesn't add any colors to the output
NoColor = noop
)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/account/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
accountName = "account"
)

//NewAccountCmd configures the org manage command
// NewAccountCmd configures the org manage command
func NewAccountCmd(streams command.Streams, hubClient *hub.Client) *cobra.Command {
cmd := &cobra.Command{
Use: accountName,
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/org/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
orgName = "org"
)

//NewOrgCmd configures the org manage command
// NewOrgCmd configures the org manage command
func NewOrgCmd(streams command.Streams, hubClient *hub.Client) *cobra.Command {
cmd := &cobra.Command{
Use: orgName,
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/repo/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
repoName = "repo"
)

//NewRepoCmd configures the repo manage command
// NewRepoCmd configures the repo manage command
func NewRepoCmd(streams command.Streams, hubClient *hub.Client) *cobra.Command {
cmd := &cobra.Command{
Use: repoName,
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/repo/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

"github.com/docker/hub-tool/internal/errdef"

"github.com/distribution/reference"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/distribution/reference"
"github.com/spf13/cobra"

"github.com/docker/hub-tool/internal/ansi"
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/tag/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
tagName = "tag"
)

//NewTagCmd configures the tag manage command
// NewTagCmd configures the tag manage command
func NewTagCmd(streams command.Streams, hubClient *hub.Client) *cobra.Command {
cmd := &cobra.Command{
Use: tagName,
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/tag/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/distribution/reference"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/distribution/reference"
"github.com/docker/go-units"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand All @@ -52,15 +52,15 @@ type inspectOptions struct {
platform string
}

//Image is the combination of a manifest and its config object
// Image is the combination of a manifest and its config object
type Image struct {
Name string
Manifest ocispec.Manifest
Config ocispec.Image
Descriptor ocispec.Descriptor
}

//Index is the combination of an OCI index and its descriptor
// Index is the combination of an OCI index and its descriptor
type Index struct {
Name string
Index ocispec.Index
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/tag/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"fmt"
"strings"

"github.com/distribution/reference"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/distribution/reference"
"github.com/docker/hub-tool/internal/ansi"
"github.com/docker/hub-tool/internal/errdef"
"github.com/docker/hub-tool/internal/metrics"
Expand Down
8 changes: 4 additions & 4 deletions internal/format/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import (
"github.com/spf13/pflag"
)

//Option handles format flags and printing the values depending the format
// Option handles format flags and printing the values depending the format
type Option struct {
format string
}

//PrettyPrinter prints all the values in a pretty print format
// PrettyPrinter prints all the values in a pretty print format
type PrettyPrinter func(io.Writer, interface{}) error

//AddFormatFlag add the format flag to a command
// AddFormatFlag add the format flag to a command
func (o *Option) AddFormatFlag(flags *pflag.FlagSet) {
flags.StringVar(&o.format, "format", "", `Print values using a custom format ("json")`)
}

//Print outputs values depending the given format
// Print outputs values depending the given format
func (o *Option) Print(out io.Writer, values interface{}, prettyPrinter PrettyPrinter) error {
switch o.format {
case "":
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {

func newSigContext() (context.Context, func()) {
ctx, cancel := context.WithCancel(context.Background())
s := make(chan os.Signal)
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-s
Expand Down
9 changes: 4 additions & 5 deletions pkg/hub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -225,7 +224,7 @@ func (c *Client) Login(username string, password string, twoFactorCodeProvider f
return "", "", err
}
defer func() { _ = resp.Body.Close() }()
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -282,7 +281,7 @@ func (c *Client) getTwoFactorToken(token string, twoFactorCodeProvider func() (s
}
defer func() { _ = resp.Body.Close() }()

buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -320,7 +319,7 @@ func (c *Client) doRequest(req *http.Request, reqOps ...RequestOp) ([]byte, erro
if resp.StatusCode == http.StatusForbidden {
return nil, &forbiddenError{}
}
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
log.Debugf("bad status code %q: %s", resp.Status, buf)
if err == nil {
if ok, err := extractError(buf, resp); ok {
Expand All @@ -329,7 +328,7 @@ func (c *Client) doRequest(req *http.Request, reqOps ...RequestOp) ([]byte, erro
}
return nil, fmt.Errorf("bad status code %q", resp.Status)
}
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
log.Tracef("HTTP response body: %s", buf)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/hub/consumption.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"golang.org/x/sync/errgroup"
)

//Consumption represents current user or org consumption
// Consumption represents current user or org consumption
type Consumption struct {
Seats int
PrivateRepositories int
Teams int
}

//GetOrgConsumption return the current organization consumption
// GetOrgConsumption return the current organization consumption
func (c *Client) GetOrgConsumption(org string) (*Consumption, error) {
var (
members int
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *Client) GetOrgConsumption(org string) (*Consumption, error) {
}, nil
}

//GetUserConsumption return the current user consumption
// GetUserConsumption return the current user consumption
func (c *Client) GetUserConsumption(user string) (*Consumption, error) {
c.fetchAllElements = true
privateRepos := 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/hub/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/docker/docker/api/types/registry"
)

//Instance stores all the specific pieces needed to dialog with Hub
// Instance stores all the specific pieces needed to dialog with Hub
type Instance struct {
APIHubBaseURL string
RegistryInfo *registry.IndexInfo
Expand Down
4 changes: 2 additions & 2 deletions pkg/hub/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const (
MembersPerTeamURL = "/v2/orgs/%s/groups/%s/members/"
)

//Member is a user part of an organization
// Member is a user part of an organization
type Member struct {
Username string `json:"username"`
FullName string `json:"full_name"`
}

//GetMembers lists all the members in an organization
// GetMembers lists all the members in an organization
func (c *Client) GetMembers(organization string) ([]Member, error) {
u, err := url.Parse(c.domain + fmt.Sprintf(MembersURL, organization))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/hub/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
OrganizationInfoURL = "/v2/orgs/%s"
)

//Organization represents a Docker Hub organization
// Organization represents a Docker Hub organization
type Organization struct {
Namespace string
FullName string
Expand All @@ -44,7 +44,7 @@ type Organization struct {
Members []Member
}

//GetOrganizations lists all the organizations a user has joined
// GetOrganizations lists all the organizations a user has joined
func (c *Client) GetOrganizations(ctx context.Context) ([]Organization, error) {
u, err := url.Parse(c.domain + OrganizationsURL)
if err != nil {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *Client) GetOrganizations(ctx context.Context) ([]Organization, error) {
return organizations, nil
}

//GetOrganizationInfo returns organization info
// GetOrganizationInfo returns organization info
func (c *Client) GetOrganizationInfo(orgname string) (*Account, error) {
u, err := url.Parse(c.domain + fmt.Sprintf(OrganizationInfoURL, orgname))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/hub/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const (
FreePlan = "free"
)

//Plan represents the current account Hub plan
// Plan represents the current account Hub plan
type Plan struct {
Name string
Limits Limits
}

//Limits represents the current account limits
// Limits represents the current account limits
type Limits struct {
Seats int
PrivateRepos int
Expand All @@ -49,7 +49,7 @@ type Limits struct {
ParallelBuilds int
}

//GetHubPlan returns an account current Hub plan
// GetHubPlan returns an account current Hub plan
func (c *Client) GetHubPlan(accountID string) (*Plan, error) {
u, err := url.Parse(c.domain + fmt.Sprintf(HubPlanURL, accountID))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/hub/ratelimiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *Client) getToken(password string, anonymous bool) (string, error) {
return "", errors.New("unable to get authorization token")
}

buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 7f68742

Please sign in to comment.