Skip to content

Commit

Permalink
Merge pull request #257 from planetscale/switch-to-staticcheck
Browse files Browse the repository at this point in the history
ci: update linter to use staticcheck
  • Loading branch information
fatih committed May 19, 2021
2 parents 216a40c + ae9d014 commit 94a168a
Show file tree
Hide file tree
Showing 36 changed files with 57 additions and 67 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ test:
build:
go build ./...

.PHONY: lint
lint:
@go install honnef.co/go/tools/cmd/staticcheck@latest
@staticcheck ./...

.PHONY: licensed
licensed:
licensed cache
licensed status

.PHONY: lint
lint:
@script/lint
3 changes: 1 addition & 2 deletions internal/cmd/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
"github.com/planetscale/planetscale-go/planetscale"
ps "github.com/planetscale/planetscale-go/planetscale"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,7 +38,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
bkp, err := client.Backups.Create(ctx, createReq)
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
case ps.ErrNotFound:
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/backup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {

if !force {
if ch.Printer.Format() != printer.Human {
return fmt.Errorf("Cannot delete backup with the output format %q (run with -force to override)", ch.Printer.Format())
return fmt.Errorf("cannot delete backup with the output format %q (run with -force to override)", ch.Printer.Format())
}

confirmationName := fmt.Sprintf("%s/%s/%s", database, branch, backup)
if !printer.IsTTY {
return fmt.Errorf("Cannot confirm deletion of backup %q (run with -force to override)", confirmationName)
return fmt.Errorf("cannot confirm deletion of backup %q (run with -force to override)", confirmationName)
}

confirmationMessage := fmt.Sprintf("%s %s %s", printer.Bold("Please type"), printer.BoldBlue(confirmationName), printer.Bold("to confirm:"))
Expand All @@ -63,7 +63,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {

// If the confirmations don't match up, let's return an error.
if userInput != confirmationName {
return errors.New("Incorrect backup name entered, skipping backup deletion...")
return errors.New("incorrect backup name entered, skipping backup deletion")
}
}

Expand All @@ -79,7 +79,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)\n",
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)",
printer.BoldBlue(backup), printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/backup/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)\n",
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/backup/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ShowCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)\n",
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)",
printer.BoldBlue(backup), printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
7 changes: 3 additions & 4 deletions internal/cmd/branch/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/pkg/browser"
"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
"github.com/planetscale/planetscale-go/planetscale"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)
Expand All @@ -30,7 +29,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {

// Simplest case, the names are equivalent
if source == branch {
return fmt.Errorf("A branch named '%s' already exists", branch)
return fmt.Errorf("a branch named '%s' already exists", branch)
}

createReq.Database = source
Expand Down Expand Up @@ -64,8 +63,8 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
dbBranch, err := client.DatabaseBranches.Create(ctx, createReq)
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("source database %s does not exist in organization %s\n",
case ps.ErrNotFound:
return fmt.Errorf("source database %s does not exist in organization %s",
printer.BoldBlue(source), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
9 changes: 4 additions & 5 deletions internal/cmd/branch/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"

"github.com/planetscale/planetscale-go/planetscale"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -36,12 +35,12 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {

if !force {
if ch.Printer.Format() != printer.Human {
return fmt.Errorf("Cannot delete branch with the output format %q (run with -force to override)", ch.Printer.Format())
return fmt.Errorf("cannot delete branch with the output format %q (run with -force to override)", ch.Printer.Format())
}

confirmationName := fmt.Sprintf("%s/%s", source, branch)
if !printer.IsTTY {
return fmt.Errorf("Cannot confirm deletion of branch %q (run with -force to override)", confirmationName)
return fmt.Errorf("cannot confirm deletion of branch %q (run with -force to override)", confirmationName)
}

confirmationMessage := fmt.Sprintf("%s %s %s", printer.Bold("Please type"),
Expand All @@ -63,7 +62,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {

// If the confirmations don't match up, let's return an error.
if userInput != confirmationName {
return errors.New("Incorrect database and branch name entered, skipping branch deletion...")
return errors.New("incorrect database and branch name entered, skipping branch deletion")
}
}

Expand All @@ -77,7 +76,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("source database %s does not exist in organization %s\n",
return fmt.Errorf("source database %s does not exist in organization %s",
printer.BoldBlue(source), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/branch/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DiffCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)\n",
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/branch/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in organization %s\n",
return fmt.Errorf("database %s does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/branch/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func SchemaCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)\n",
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/branch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/config"
"github.com/planetscale/cli/internal/printer"
"github.com/planetscale/planetscale-go/planetscale"
ps "github.com/planetscale/planetscale-go/planetscale"

"github.com/spf13/cobra"
)

Expand All @@ -34,7 +34,7 @@ func SwitchCmd(ch *cmdutil.Helper) *cobra.Command {
ch.Printer.Printf("Finding branch %s on database %s\n",
printer.BoldBlue(branch), printer.BoldBlue(ch.Config.Database))

_, err = client.DatabaseBranches.Get(ctx, &planetscale.GetDatabaseBranchRequest{
_, err = client.DatabaseBranches.Get(ctx, &ps.GetDatabaseBranchRequest{
Organization: ch.Config.Organization,
Database: ch.Config.Database,
Branch: branch,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ argument:
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s and branch %s does not exist in organization %s\n",
return fmt.Errorf("database %s and branch %s does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(branch), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/database/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"

"github.com/planetscale/planetscale-go/planetscale"
ps "github.com/planetscale/planetscale-go/planetscale"

"github.com/pkg/browser"
Expand Down Expand Up @@ -52,8 +51,8 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
database, err := client.Databases.Create(ctx, createReq)
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("organization %s does not exist\n", printer.BoldBlue(ch.Config.Organization))
case ps.ErrNotFound:
return fmt.Errorf("organization %s does not exist", printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/database/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {

if !force {
if !printer.IsTTY {
return fmt.Errorf("Cannot confirm deletion of database %q (run with -force to override)", name)
return fmt.Errorf("cannot confirm deletion of database %q (run with -force to override)", name)
}
confirmationMessage := fmt.Sprintf("%s %s %s", printer.Bold("Please type"), printer.BoldBlue(name), printer.Bold("to confirm:"))

Expand All @@ -56,7 +56,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
}

if userInput != name {
return errors.New("Incorrect database name entered, skipping database deletion...")
return errors.New("incorrect database name entered, skipping database deletion")
}
}

Expand All @@ -70,7 +70,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in organization %s\n",
return fmt.Errorf("database %s does not exist in organization %s",
printer.BoldBlue(name), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func dump(ch *cmdutil.Helper, cmd *cobra.Command, flags *dumpFlags, args []strin
}

if status.Credentials.User == "" {
return errors.New("database branch is not ready yet, please try again in a few minutes.")
return errors.New("database branch is not ready yet, please try again in a few minutes")
}

addr, err := p.LocalAddr()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("organization %s does not exist\n", printer.BoldBlue(ch.Config.Organization))
return fmt.Errorf("organization %s does not exist", printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func restore(ch *cmdutil.Helper, cmd *cobra.Command, flags *restoreFlags, args [
}

if status.Credentials.User == "" {
return errors.New("database branch is not ready yet, please try again in a few minutes.")
return errors.New("database branch is not ready yet, please try again in a few minutes")
}

addr, err := p.LocalAddr()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ShowCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in organization %s\n",
return fmt.Errorf("database %s does not exist in organization %s",
printer.BoldBlue(name), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/deployrequest/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CloseCmd(ch *cmdutil.Helper) *cobra.Command {

n, err := strconv.ParseUint(number, 10, 64)
if err != nil {
return fmt.Errorf("The argument <number> is invalid: %s", err)
return fmt.Errorf("the argument <number> is invalid: %s", err)
}

dr, err := client.DeployRequests.CloseDeploy(ctx, &planetscale.CloseDeployRequestRequest{
Expand All @@ -41,7 +41,7 @@ func CloseCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in %s\n",
return fmt.Errorf("database %s does not exist in %s",
printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/deployrequest/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func DeployCmd(ch *cmdutil.Helper) *cobra.Command {

n, err := strconv.ParseUint(number, 10, 64)
if err != nil {
return fmt.Errorf("The argument <number> is invalid: %s", err)
return fmt.Errorf("the argument <number> is invalid: %s", err)
}

dr, err := client.DeployRequests.Deploy(ctx, &planetscale.PerformDeployRequest{
Expand All @@ -41,7 +41,7 @@ func DeployCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/deployrequest/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func DiffCmd(ch *cmdutil.Helper) *cobra.Command {

n, err := strconv.ParseUint(number, 10, 64)
if err != nil {
return fmt.Errorf("The argument <number> is invalid: %s", err)
return fmt.Errorf("the argument <number> is invalid: %s", err)
}

diffs, err := client.DeployRequests.Diff(ctx, &planetscale.DiffRequest{
Expand All @@ -54,7 +54,7 @@ func DiffCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("deploy rquest '%s/%s' does not exist in organization %s\n",
return fmt.Errorf("deploy rquest '%s/%s' does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in organization %s\n",
return fmt.Errorf("database %s does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/deployrequest/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ReviewCmd(ch *cmdutil.Helper) *cobra.Command {

n, err := strconv.ParseUint(number, 10, 64)
if err != nil {
return fmt.Errorf("The argument <number> is invalid: %s", err)
return fmt.Errorf("the argument <number> is invalid: %s", err)
}

client, err := ch.Client()
Expand All @@ -59,7 +59,7 @@ func ReviewCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s",
printer.BoldBlue(database), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/deployrequest/review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/planetscale/cli/internal/printer"

qt "github.com/frankban/quicktest"
"github.com/planetscale/planetscale-go/planetscale"
ps "github.com/planetscale/planetscale-go/planetscale"
)

Expand All @@ -27,7 +26,7 @@ func TestDeployRequest_ReviewCmd(t *testing.T) {
org := "planetscale"
db := "planetscale"
var number uint64 = 10
action := planetscale.ReviewComment
action := ps.ReviewComment
comment := "this is a comment"

res := &ps.DeployRequestReview{
Expand Down

0 comments on commit 94a168a

Please sign in to comment.