Skip to content

Commit

Permalink
Add golangci-lint config and fix linter errors (#353)
Browse files Browse the repository at this point in the history
* Add golangci-lint and fixes

* Use consistent line breaks on AddCommand

* Correct some load balancer command docs

* Update workflows to use go v1.21

* Add exclude rules to printer functions

The errors will be addressed in another, more complicated changeset

* Remove unecessary whitespace

* Remove obsolete nolint directive
  • Loading branch information
optik-aper authored Sep 28, 2023
1 parent 289dba0 commit 20f4990
Show file tree
Hide file tree
Showing 35 changed files with 668 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"

- name: Run unit tests and coverage test
id: test-coverage
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gochecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"

- name: Install dependencies
run: |
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"

- name: Run fmt
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
go-version: "1.21"
-
name: Docker Login
env:
Expand Down
135 changes: 135 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
linters-settings:
dupl:
threshold: 300
funlen:
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: unexported-return
disabled: true

linters:
disable-all: true
enable:
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

# don't enable:
# - bodyclose
# - depguard
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl

issues:
# List of regexps of issue texts to exclude.
#
# But independently of this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`.
# To list all excluded by default patterns execute `golangci-lint run --help`
#
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude:
- abcdef
exclude-rules:
# Exclude some linters from running on tests files.
- path: cmd/printer/
linters:
- funlen
- gocyclo
- dupl
- lll
- gomnd
- gocritic
- stylecheck

run:
timeout: 5m
2 changes: 1 addition & 1 deletion cmd/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Applications() *cobra.Command {
appsCmd.AddCommand(appsList)

appsList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
appsList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
appsList.Flags().IntP("per-page", "p", perPageDefault, "(optional) Number of items requested per page. Default is 100 and Max is 500.")

return appsCmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Backups() *cobra.Command {
backupsCmd.AddCommand(backupsList, backupsGet)

backupsList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
backupsList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
backupsList.Flags().IntP("per-page", "p", perPageDefault, "(optional) Number of items requested per page. Default is 100 and Max is 500.")

return backupsCmd
}
Expand Down
70 changes: 60 additions & 10 deletions cmd/bareMetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,79 @@ func BareMetal() *cobra.Command {
os.Exit(1)
}
bareMetalCreate.Flags().IntP("os", "o", 0, "ID of the operating system that will be installed on the server.")
bareMetalCreate.Flags().StringP("script", "s", "", "(optional) ID of the startup script that will run after the server is created.")
bareMetalCreate.Flags().StringP("snapshot", "", "", "(optional) ID of the snapshot that the server will be restored from.")
bareMetalCreate.Flags().StringP("ipv6", "i", "", "(optional) Whether IPv6 is enabled on the server. Possible values: 'yes', 'no'. Defaults to 'no'.")
bareMetalCreate.Flags().StringP(
"script",
"s",
"",
"(optional) ID of the startup script that will run after the server is created.",
)
bareMetalCreate.Flags().StringP(
"snapshot",
"",
"",
"(optional) ID of the snapshot that the server will be restored from.",
)
bareMetalCreate.Flags().StringP(
"ipv6",
"i",
"",
"(optional) Whether IPv6 is enabled on the server. Possible values: 'yes', 'no'. Defaults to 'no'.",
)
bareMetalCreate.Flags().StringP("label", "l", "", "(optional) The label to assign to the server.")
bareMetalCreate.Flags().StringSliceP("ssh", "k", []string{}, "(optional) Comma separated list of SSH key IDs that will be added to the server.")
bareMetalCreate.Flags().IntP("app", "a", 0, "(optional) ID of the application that will be installed on the server.")
bareMetalCreate.Flags().StringSliceP(
"ssh",
"k",
[]string{},
"(optional) Comma separated list of SSH key IDs that will be added to the server.",
)
bareMetalCreate.Flags().IntP(
"app",
"a",
0,
"(optional) ID of the application that will be installed on the server.",
)
bareMetalCreate.Flags().StringP("image", "", "", "(optional) Image ID of the application that will be installed on the server.")
bareMetalCreate.Flags().StringP("userdata", "u", "", "(optional) A generic data store, which some provisioning tools and cloud operating systems use as a configuration file.")
bareMetalCreate.Flags().StringP("notify", "n", "", "(optional) Whether an activation email will be sent when the server is ready. Possible values: 'yes', 'no'. Defaults to 'yes'.")
bareMetalCreate.Flags().StringP(
"userdata",
"u",
"",
"(optional) A generic data store, which some provisioning tools and cloud operating systems use as a configuration file.",
)
bareMetalCreate.Flags().StringP(
"notify",
"n",
"",
"(optional) Whether an activation email will be sent when the server is ready. Possible values: 'yes', 'no'. Defaults to 'yes'.",
)
bareMetalCreate.Flags().StringP("hostname", "m", "", "(optional) The hostname to assign to the server.")
bareMetalCreate.Flags().StringP("tag", "t", "", "Deprecated: use `tags` instead. (optional) The tag to assign to the server.")
bareMetalCreate.Flags().StringSliceP("tags", "", []string{}, "(optional) A comma separated list of tags to assign to the server.")
bareMetalCreate.Flags().StringP("ripv4", "v", "", "(optional) IP address of the floating IP to use as the main IP of this server.")
bareMetalCreate.Flags().BoolP("persistent_pxe", "x", false, "enable persistent_pxe | true or false")

bareMetalList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
bareMetalList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
bareMetalList.Flags().IntP(
"per-page",
"p",
perPageDefault,
"(optional) Number of items requested per page. Default is 100 and Max is 500.",
)

bareMetalListIPV4.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
bareMetalListIPV4.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
bareMetalListIPV4.Flags().IntP(
"per-page",
"p",
perPageDefault,
"(optional) Number of items requested per page. Default is 100 and Max is 500.",
)

bareMetalListIPV6.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
bareMetalListIPV6.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
bareMetalListIPV6.Flags().IntP(
"per-page",
"p",
perPageDefault,
"(optional) Number of items requested per page. Default is 100 and Max is 500.",
)

bareMetalTags.Flags().StringSliceP("tags", "t", []string{}, "A comma separated list of tags to apply to the server")
if err := bareMetalTags.MarkFlagRequired("tags"); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions cmd/bareMetalUserData.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/vultr/govultr/v3"
Expand Down Expand Up @@ -71,9 +72,10 @@ var bareMetalSetUserData = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
userData, _ := cmd.Flags().GetString("userdata")
userDataPath, _ := cmd.Flags().GetString("userdata")
userDataPath = filepath.Clean(userDataPath)

rawData, err := os.ReadFile(userData)
rawData, err := os.ReadFile(userDataPath)
if err != nil {
fmt.Printf("error reading user-data : %v\n", err)
os.Exit(1)
Expand Down
16 changes: 13 additions & 3 deletions cmd/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,25 @@ func Billing() *cobra.Command {
}

invoicesList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
invoicesList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
invoicesList.Flags().IntP("per-page", "p", perPageDefault, "(optional) Number of items requested per page. Default is 100 and Max is 500.")

invoiceItemsList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
invoiceItemsList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
invoiceItemsList.Flags().IntP(
"per-page",
"p",
perPageDefault,
"(optional) Number of items requested per page. Default is 100 and Max is 500.",
)

invoiceCmd.AddCommand(invoicesList, invoiceGet, invoiceItemsList)

billingHistoryList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
billingHistoryList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
billingHistoryList.Flags().IntP(
"per-page",
"p",
perPageDefault,
"(optional) Number of items requested per page. Default is 100 and Max is 500.",
)

billingCmd.AddCommand(historyCmd, invoiceCmd)

Expand Down
11 changes: 8 additions & 3 deletions cmd/blockStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ var (

// BlockStorageCmd represents the blockStorage command
func BlockStorageCmd() *cobra.Command {

bsCmd := &cobra.Command{
Use: "block-storage",
Aliases: []string{"bs"},
Expand All @@ -119,7 +118,7 @@ func BlockStorageCmd() *cobra.Command {

// List
bsList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
bsList.Flags().IntP("per-page", "p", 100, "(optional) Number of items requested per page. Default is 100 and Max is 500.")
bsList.Flags().IntP("per-page", "p", perPageDefault, "(optional) Number of items requested per page. Default is 100 and Max is 500.")

// Attach
bsAttach.Flags().StringP("instance", "i", "", "instance id you want to attach to")
Expand All @@ -146,7 +145,13 @@ func BlockStorageCmd() *cobra.Command {

bsCreate.Flags().StringP("label", "l", "", "label you want to give the block storage")

bsCreate.Flags().StringP("block-type", "b", "", "(optional) Block type you want to give the block storage. Possible values: 'high_perf', 'storage_opt'. Currently defaults to 'high_perf'.")
bsCreate.Flags().StringP(
"block-type",
"b",
"",
`(optional) Block type you want to give the block storage.
Possible values: 'high_perf', 'storage_opt'. Currently defaults to 'high_perf'.`,
)

// Label
bsLabelSet.Flags().StringP("label", "l", "", "label you want your block storage to have")
Expand Down
Loading

0 comments on commit 20f4990

Please sign in to comment.