Skip to content

Commit

Permalink
Add misspell, gocritic, revive
Browse files Browse the repository at this point in the history
  • Loading branch information
eikendev committed Apr 1, 2023
1 parent affe8a4 commit bea9b3c
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ clean:
test:
stdout=$$(gofumpt -l . 2>&1); if [ "$$stdout" ]; then exit 1; fi
go vet ./...
misspell $(GO_FILES)
gocyclo -over 10 $(GO_FILES)
staticcheck ./...
errcheck ./...
gocritic check -disable='#experimental,#opinionated' -@ifElseChain.minThreshold 3 ./...
revive -set_exit_status ./...
go test -v -cover ./...
gosec -exclude-dir=tests ./...
govulncheck ./...
@printf '\n%s\n' "> Test successful"

.PHONY: setup
setup:
go install github.com/client9/misspell/cmd/misspell@latest
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install github.com/go-critic/go-critic/cmd/gocritic@latest
go install github.com/kisielk/errcheck@latest
go install github.com/mgechev/revive@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
Expand Down
1 change: 1 addition & 0 deletions cmd/pbcli/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main provides the main function as a starting point of this tool.
package main

import (
Expand Down
12 changes: 7 additions & 5 deletions internal/api/mod.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Package api provides low-level functionality to interact with the PushBits API.
package api

import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -54,15 +56,15 @@ func Request(base, endpoint, method, proxy, username, password string, hasBody b
if hasBody {
reqBody, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
return nil, err
}

reqBodyReader = strings.NewReader(string(reqBody))
}

req, err := http.NewRequest(method, url.String(), reqBodyReader)
if err != nil {
log.Fatal(err)
return nil, err
}

req.Header.Set("Accept", "application/json")
Expand All @@ -77,19 +79,19 @@ func Request(base, endpoint, method, proxy, username, password string, hasBody b
defer handling.Close(resp.Body)

if resp.StatusCode != http.StatusOK {
log.Fatalf("Request failed with HTTP %s.", resp.Status)
return nil, fmt.Errorf("request failed with HTTP %s", resp.Status)
}

bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
return nil, err
}

var obj interface{}

err = json.Unmarshal(bodyText, &obj)
if err != nil {
log.Fatal(err)
return nil, err
}

return obj, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/application/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type createCommand struct {
StrictCompatibility bool `long:"compat" help:"Enforce strict compatibility with Gotify"`
}

func (c *createCommand) Run(s *options.Options) error {
func (c *createCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

data := map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion internal/application/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type deleteCommand struct {
ID uint `arg:"" help:"The ID of the application"`
}

func (c *deleteCommand) Run(s *options.Options) error {
func (c *deleteCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

populatedEndpoint := fmt.Sprintf(deleteEndpoint, c.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/application/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type listCommand struct {
options.AuthOptions
}

func (c *listCommand) Run(s *options.Options) error {
func (c *listCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

resp, err := api.Get(c.URL, listEndpoint, c.Proxy, c.Username, password)
Expand Down
1 change: 1 addition & 0 deletions internal/application/mod.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package application provides commands related to managing applications.
package application

// Command contains all subcommands provided by this package.
Expand Down
2 changes: 1 addition & 1 deletion internal/application/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type showCommand struct {
ID uint `arg:"" help:"The ID of the application"`
}

func (c *showCommand) Run(s *options.Options) error {
func (c *showCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

populatedEndpoint := fmt.Sprintf(showEndpoint, c.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/application/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type updateCommand struct {
StrictCompatibility bool `long:"compat" help:"Enforce strict compatibility with Gotify"`
}

func (c *updateCommand) Run(s *options.Options) error {
func (c *updateCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

if !c.RefreshToken && c.StrictCompatibility {
Expand Down
2 changes: 2 additions & 0 deletions internal/buildconfig/buildconfig.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package buildconfig cpntains variables that are set during compliation.
package buildconfig

// Version of the build.
var Version = "unknown"
5 changes: 4 additions & 1 deletion internal/commands/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package commands contains functions that are exposed as dedicated commands of the tool.
package commands

import (
Expand All @@ -7,9 +8,11 @@ import (
"github.com/pushbits/cli/internal/options"
)

// VersionCommand represents the options specific to the version command.
type VersionCommand struct{}

func (c *VersionCommand) Run(s *options.Options) error {
// Run is the function for the version command.
func (*VersionCommand) Run(_ *options.Options) error {
fmt.Printf("pbcli %s\n", buildconfig.Version)

return nil
Expand Down
2 changes: 2 additions & 0 deletions internal/handling/handling.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package handling provides convenience functions for cleaning up resources.
package handling

import (
Expand All @@ -6,6 +7,7 @@ import (
log "github.com/sirupsen/logrus"
)

// Close closes an io resource and prints a warning if that fails.
func Close(c io.Closer) {
if err := c.Close(); err != nil {
log.Warn(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/options/mod.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Package options defines the global options of this tool.
package options

// Options represents the global options.
// Options represents the global options of this tool.
type Options struct {
Verbose bool `short:"v" help:"Show debugging information"`
}
Expand Down
1 change: 1 addition & 0 deletions internal/ui/mod.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package ui provides utilities to interact with the user over the command line.
package ui

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type createCommand struct {
MatrixID string `arg:"" help:"The Matrix ID of the user"`
}

func (c *createCommand) Run(s *options.Options) error {
func (c *createCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

newPassword := ui.GetNewPassword(c.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/user/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type deleteCommand struct {
ID uint `arg:"" help:"The ID of the user"`
}

func (c *deleteCommand) Run(s *options.Options) error {
func (c *deleteCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

populatedEndpoint := fmt.Sprintf(deleteEndpoint, c.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/user/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type listCommand struct {
options.AuthOptions
}

func (c *listCommand) Run(s *options.Options) error {
func (c *listCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

resp, err := api.Get(c.URL, listEndpoint, c.Proxy, c.Username, password)
Expand Down
1 change: 1 addition & 0 deletions internal/user/mod.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package user provides commands related to managing users.
package user

// Command contains all subcommands provided by this package.
Expand Down
2 changes: 1 addition & 1 deletion internal/user/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type showCommand struct {
ID uint `arg:"" help:"The ID of the user"`
}

func (c *showCommand) Run(s *options.Options) error {
func (c *showCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

populatedEndpoint := fmt.Sprintf(showEndpoint, c.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type updateCommand struct {
NewMatrixID string `long:"new-matrixid" help:"The new Matrix ID of the user"`
}

func (c *updateCommand) Run(s *options.Options) error {
func (c *updateCommand) Run(_ *options.Options) error {
password := ui.GetCurrentPassword(c.Username)

data := map[string]interface{}{}
Expand Down

0 comments on commit bea9b3c

Please sign in to comment.