Skip to content

Commit

Permalink
Linter updates and fixes (#457)
Browse files Browse the repository at this point in the history
* Fix long line

* Update golangci-lint config

* Fix all long line after change to 120 char limit
  • Loading branch information
optik-aper authored Jun 11, 2024
1 parent 91fba88 commit 9628bae
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 142 deletions.
9 changes: 3 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ linters-settings:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
mnd:
# don't include the "operation" and "assign"
checks:
- argument
Expand All @@ -37,9 +37,7 @@ linters-settings:
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
Expand All @@ -48,7 +46,7 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
line-length: 120
misspell:
locale: US
nolintlint:
Expand All @@ -59,7 +57,6 @@ linters-settings:
rules:
- name: unexported-return
disabled: true

linters:
disable-all: true
enable:
Expand All @@ -71,7 +68,7 @@ linters:
- gocyclo
- gofmt
- goimports
- gomnd
- mnd
- goprintffuncname
- gosec
- gosimple
Expand Down
5 changes: 4 additions & 1 deletion cmd/applications/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ func NewCmdApplications(base *cli.Base) *cobra.Command {
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

cmd.AddCommand(list)
Expand Down
5 changes: 4 additions & 1 deletion cmd/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func NewCmdBackups(base *cli.Base) *cobra.Command {
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

// Get
Expand Down
57 changes: 47 additions & 10 deletions cmd/baremetal/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ There is no going back from this call.`
ipv4Example = ``

ipv6Long = `
List the IPv6 information of a bare metal server. IP information is only available for bare metal servers in the "active" state.
List the IPv6 information of a bare metal server.
IP information is only available for bare metal servers in the "active" state.
`
ipv6Example = ``

Expand Down Expand Up @@ -165,7 +166,10 @@ func NewCmdBareMetal(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

// Get
Expand Down Expand Up @@ -254,25 +258,53 @@ func NewCmdBareMetal(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo
0,
"(optional) ID of the application that will be installed on the server.",
)
create.Flags().StringP("image", "", "", "(optional) Image ID of the application that will be installed on the server.")
create.Flags().StringP(
"image",
"",
"",
"(optional) Image ID of the application that will be installed on the server.",
)
create.Flags().StringP(
"userdata",
"u",
"",
"(optional) A generic data store, which some provisioning tools and cloud operating systems use as a configuration file.",
`(optional) A generic data store, which some provisioning tools and cloud operating
systems use as a configuration file.`,
)
create.Flags().StringP(
"notify",
"n",
"",
"(optional) Whether an activation email will be sent when the server is ready. Possible values: 'yes', 'no'. Defaults to 'yes'.",
`(optional) Whether an activation email will be sent when the server is ready. Possible values: 'yes', 'no'.
Defaults to 'yes'.`,
)
create.Flags().StringP("hostname", "m", "", "(optional) The hostname to assign to the server.")
create.Flags().StringP("tag", "t", "", "Deprecated: use `tags` instead. (optional) The tag to assign to the server.")
create.Flags().StringSliceP("tags", "", []string{}, "(optional) A comma separated list of tags to assign to the server.")
create.Flags().StringP("ripv4", "v", "", "(optional) IP address of the floating IP to use as the main IP of this server.")
create.Flags().StringP(
"tag",
"t",
"",
"Deprecated: use `tags` instead. (optional) The tag to assign to the server.",
)
create.Flags().StringSliceP(
"tags",
"",
[]string{},
"(optional) A comma separated list of tags to assign to the server.",
)
create.Flags().StringP(
"ripv4",
"v",
"",
"(optional) IP address of the floating IP to use as the main IP of this server.",
)
create.Flags().BoolP("persistent_pxe", "x", false, "enable persistent_pxe | true or false")
create.Flags().StringP("mdisk_mode", "", "", "(optional) The raid configuration to use when provisioning this server. Possible values: 'raid1', 'jbod', 'none''. Defaults to 'none'.")
create.Flags().StringP(
"mdisk_mode",
"",
"",
`(optional) The raid configuration to use when provisioning this server.
Possible values: 'raid1', 'jbod', 'none''. Defaults to 'none'.`,
)
if err := create.MarkFlagRequired("region"); err != nil {
fmt.Printf("error marking bare metal create 'region' flag required: %v", err)
os.Exit(1)
Expand Down Expand Up @@ -913,7 +945,12 @@ func NewCmdBareMetal(base *cli.Base) *cobra.Command { //nolint:funlen,gocyclo
}

vpc2Attach.Flags().StringP("vpc-id", "v", "", "the ID of the VPC 2.0 network you wish to attach")
vpc2Attach.Flags().StringP("ip-address", "i", "", "the IP address to use for this server on the attached VPC 2.0 network")
vpc2Attach.Flags().StringP(
"ip-address",
"i",
"",
"the IP address to use for this server on the attached VPC 2.0 network",
)
if errVPC := vpc2Attach.MarkFlagRequired("vpc-id"); errVPC != nil {
fmt.Printf("error marking bare metal 'vpc-id' flag required for attach : %v", errVPC)
os.Exit(1)
Expand Down
15 changes: 12 additions & 3 deletions cmd/billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func NewCmdBilling(base *cli.Base) *cobra.Command {
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

// Invoice Get
Expand Down Expand Up @@ -192,7 +195,10 @@ func NewCmdBilling(base *cli.Base) *cobra.Command {
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

invoice.AddCommand(
Expand Down Expand Up @@ -235,7 +241,10 @@ func NewCmdBilling(base *cli.Base) *cobra.Command {
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

history.AddCommand(
Expand Down
5 changes: 4 additions & 1 deletion cmd/blockstorage/blockstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ func NewCmdBlockStorage(base *cli.Base) *cobra.Command { //nolint:gocyclo
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

// Get
Expand Down
37 changes: 29 additions & 8 deletions cmd/containerregistry/containerregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ var (
repoUpdateLong = `Update the details of registry's repository`
repoUpdateExample = `
# Full example
vultr-cli container-registry repository update 4dcdc52e-9c63-401e-8c5f-1582490fe09c --image-name="my-thing" --description="new description"
vultr-cli container-registry repository update 4dcdc52e-9c63-401e-8c5f-1582490fe09c --image-name="my-thing"
--description="new description"
# Shortened example with aliases
vultr-cli cr r u 4dcdc52e-9c63-401e-8c5f-1582490fe09c -i="my-thing" -d="new description"
Expand Down Expand Up @@ -162,7 +163,10 @@ func NewCmdContainerRegistry(base *cli.Base) *cobra.Command { //nolint:funlen,go
"per-page",
"p",
utils.PerPageDefault,
fmt.Sprintf("(optional) Number of items requested per page. Default is %d and Max is 500.", utils.PerPageDefault),
fmt.Sprintf(
"(optional) Number of items requested per page. Default is %d and Max is 500.",
utils.PerPageDefault,
),
)

// Get
Expand Down Expand Up @@ -250,7 +254,12 @@ func NewCmdContainerRegistry(base *cli.Base) *cobra.Command { //nolint:funlen,go
os.Exit(1)
}

create.Flags().BoolP("public", "p", false, "If the registry is publicly available. Should be true | false (default is false)")
create.Flags().BoolP(
"public",
"p",
false,
"If the registry is publicly available. Should be true | false (default is false)",
)
if err := create.MarkFlagRequired("public"); err != nil {
fmt.Printf("error marking container registry create 'public' flag required: %v", err)
os.Exit(1)
Expand Down Expand Up @@ -462,12 +471,18 @@ func NewCmdContainerRegistry(base *cli.Base) *cobra.Command { //nolint:funlen,go
RunE: func(cmd *cobra.Command, args []string) error {
name, errIm := cmd.Flags().GetString("image-name")
if errIm != nil {
return fmt.Errorf("error parsing 'image-name' flag for container registry repository update : %v", errIm)
return fmt.Errorf(
"error parsing 'image-name' flag for container registry repository update : %v",
errIm,
)
}

description, errDe := cmd.Flags().GetString("description")
if errDe != nil {
return fmt.Errorf("error parsing 'description' flag for container registry repository update : %v", errDe)
return fmt.Errorf(
"error parsing 'description' flag for container registry repository update : %v",
errDe,
)
}

o.RepoName = name
Expand Down Expand Up @@ -513,7 +528,10 @@ func NewCmdContainerRegistry(base *cli.Base) *cobra.Command { //nolint:funlen,go
RunE: func(cmd *cobra.Command, args []string) error {
name, errIm := cmd.Flags().GetString("image-name")
if errIm != nil {
return fmt.Errorf("error parsing 'image-name' flag for container registry repository delete : %v", errIm)
return fmt.Errorf(
"error parsing 'image-name' flag for container registry repository delete : %v",
errIm,
)
}

o.RepoName = name
Expand Down Expand Up @@ -560,7 +578,10 @@ func NewCmdContainerRegistry(base *cli.Base) *cobra.Command { //nolint:funlen,go
RunE: func(cmd *cobra.Command, args []string) error {
expiry, errEx := cmd.Flags().GetInt("expiry-seconds")
if errEx != nil {
return fmt.Errorf("error parsing 'expiry-seconds' flag for container registry docker creds : %v", errEx)
return fmt.Errorf(
"error parsing 'expiry-seconds' flag for container registry docker creds : %v",
errEx,
)
}

access, errAc := cmd.Flags().GetBool("read-write")
Expand Down Expand Up @@ -662,7 +683,7 @@ func (o *options) regions() ([]govultr.ContainerRegistryRegion, *govultr.Meta, e
}

func (o *options) repositoryList() ([]govultr.ContainerRegistryRepo, *govultr.Meta, error) {
repos, meta, _, err := o.Base.Client.ContainerRegistry.ListRepositories(o.Base.Context, o.Base.Args[0], o.Base.Options)
repos, meta, _, err := o.Base.Client.ContainerRegistry.ListRepositories(o.Base.Context, o.Base.Args[0], o.Base.Options) //nolint:lll
return repos, meta, err
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/containerregistry/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func (c *ContainerRegistriesPrinter) Data() [][]string {

var data [][]string
for i := range c.Registries {
usage := fmt.Sprintf("%vGB / %vGB", c.Registries[i].Storage.Used.GigaBytes, c.Registries[i].Storage.Allowed.GigaBytes)
usage := fmt.Sprintf(
"%vGB / %vGB",
c.Registries[i].Storage.Used.GigaBytes,
c.Registries[i].Storage.Allowed.GigaBytes,
)
data = append(data, []string{
c.Registries[i].ID,
c.Registries[i].Name,
Expand Down Expand Up @@ -171,7 +175,7 @@ func (c *ContainerRegistryPlansPrinter) Data() [][]string {

data = append(data, []string{
botVals.FieldByName("VanityName").String(),
fmt.Sprintf("%vGB", botVals.FieldByName("MaxStorageMB").Int()/1024), //nolint:gomnd
fmt.Sprintf("%vGB", botVals.FieldByName("MaxStorageMB").Int()/1024), //nolint:mnd
strconv.FormatInt(botVals.FieldByName("MonthlyPrice").Int(), 10),
})
}
Expand Down
Loading

0 comments on commit 9628bae

Please sign in to comment.