Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Codequality: add revive linter (gopasspw#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz authored Jun 1, 2018
1 parent 1a4ca33 commit f968915
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 17 deletions.
39 changes: 39 additions & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Ignores files with "GENERATED" header, similar to golint
ignoreGeneratedHeader = false

# Sets the default severity to "warning"
severity = "error"

# Sets the default failure confidence. This means that linting errors
# with less than 0.8 confidence will be ignored.
confidence = 0.6

# Sets the error code for failures with severity "error"
errorCode = 1

# Sets the error code for failures with severity "warning"
warningCode = 1

[rule.argument-limit]
arguments = [10]
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.cyclomatic]
arguments = [21]
[rule.dot-imports]
[rule.error-naming]
[rule.error-return]
[rule.error-strings]
[rule.errorf]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.indent-error-flow]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.var-declaration]
[rule.var-naming]
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ legal:

codequality:
@echo ">> CODE QUALITY"

@echo -n " REVIVE "
@which revive > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
@revive -formatter friendly -exclude vendor/... ./...
@printf '%s\n' '$(OK)'

@echo -n " FMT "
@$(foreach gofile, $(GOFILES_NOVENDOR),\
out=$$(gofmt -s -l -d -e $(gofile) | tee /dev/stderr); if [ -n "$$out" ]; then exit 1; fi;)
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set -A complete_gopass -- $PASS_LIST %s
`

if a == nil {
return fmt.Errorf("Can't parse command options")
return fmt.Errorf("can not parse command options")
}

var opts []string
Expand Down
4 changes: 4 additions & 0 deletions pkg/backend/crypto/gpg/openpgp/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (g *GPG) writeSecring(fn string) error {
return nil
}

// revive:disable

// KeysById implements openpgp.Keyring
func (g *GPG) KeysById(id uint64) []openpgp.Key {
return append(g.secring.KeysById(id), g.pubring.KeysById(id)...)
Expand All @@ -136,6 +138,8 @@ func (g *GPG) KeysByIdUsage(id uint64, requiredUsage byte) []openpgp.Key {
return append(g.secring.KeysByIdUsage(id, requiredUsage), g.pubring.KeysByIdUsage(id, requiredUsage)...)
}

// revive:enable

// DecryptionKeys implements openpgp.Keyring
func (g *GPG) DecryptionKeys() []openpgp.Key {
return append(g.secring.DecryptionKeys(), g.pubring.DecryptionKeys()...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/rcs/git/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g *Git) fixConfig(ctx context.Context) error {
// InitConfig initialized and preparse the git config
func (g *Git) InitConfig(ctx context.Context, userName, userEmail string) error {
if userName == "" || userEmail == "" || !strings.Contains(userEmail, "@") {
return fmt.Errorf("Username and Email must not be empty and valid")
return fmt.Errorf("username and email must not be empty and valid")
}
// set commit identity
if err := g.ConfigSet(ctx, "user.name", userName); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestLoadError(t *testing.T) {
capture(t, func() error {
_, err := load(gcfg)
if err == nil {
return fmt.Errorf("Should fail")
return fmt.Errorf("should fail")
}
return nil
})
Expand All @@ -198,7 +198,7 @@ func TestDecodeError(t *testing.T) {
capture(t, func() error {
_, err := load(gcfg)
if err == nil {
return fmt.Errorf("Should fail")
return fmt.Errorf("should fail")
}
return nil
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/cui/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ func confirmEditRecipients(ctx context.Context, name string, ris recipientInfos)
// AskForPrivateKey promts the user to select from a list of private keys
func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, name, prompt string) (string, error) {
if !ctxutil.IsInteractive(ctx) {
return "", errors.New("Can not select private key without terminal")
return "", errors.New("can not select private key without terminal")
}
if crypto == nil {
return "", errors.New("Can not select private key without valid crypto backend")
return "", errors.New("can not select private key without valid crypto backend")
}

kl, err := crypto.ListPrivateKeyIDs(gpg.WithAlwaysTrust(ctx, false))
if err != nil {
return "", err
}
if len(kl) < 1 {
return "", errors.New("No useable private keys found")
return "", errors.New("no useable private keys found")
}

for i := 0; i < maxTries; i++ {
Expand Down Expand Up @@ -241,7 +241,7 @@ func AskForGitConfigUser(ctx context.Context, crypto backend.Crypto, name string
return "", "", err
}
if len(keyList) < 1 {
return "", "", errors.New("No usable private keys found")
return "", "", errors.New("no usable private keys found")
}

for _, key := range keyList {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsonapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestRespondMessageBrokenInput(t *testing.T) {
runRespondMessage(t, "", "", "failed to unmarshal JSON message: unexpected end of JSON input", []storedSecret{})

// Empty object
runRespondMessage(t, "{}", "", "Unknown message of type ", []storedSecret{})
runRespondMessage(t, "{}", "", "unknown message of type ", []storedSecret{})
}

func TestRespondMessageQuery(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsonapi/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (api *API) respondMessage(ctx context.Context, msgBytes []byte) error {
case "create":
return api.respondCreateEntry(ctx, msgBytes)
default:
return fmt.Errorf("Unknown message of type %s", message.Type)
return fmt.Errorf("unknown message of type %s", message.Type)
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/pinentry/pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io"
"os/exec"
"strings"

"github.com/pkg/errors"
)

// Client is a pinentry client
Expand Down Expand Up @@ -77,7 +79,7 @@ func (c *Client) Set(key, value string) error {
}
line, _, _ := c.out.ReadLine()
if string(line) != "OK" {
return fmt.Errorf("Error: %s", line)
return errors.Errorf("error: %s", line)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/sub/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Store) GitInit(ctx context.Context, un, ue string) error {
out.Cyan(ctx, "WARNING: Initializing with no-op (mock) git backend")
return nil
default:
return fmt.Errorf("Unknown Sync Backend: %d", backend.GetRCSBackend(ctx))
return fmt.Errorf("unknown Sync Backend: %d", backend.GetRCSBackend(ctx))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/store/sub/gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ func (s *Store) importPublicKey(ctx context.Context, r string) error {
}
return s.crypto.ImportPublicKey(ctx, pk)
}
return fmt.Errorf("Public Key not found in store")
return fmt.Errorf("public key not found in store")
}
2 changes: 1 addition & 1 deletion pkg/store/sub/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Store) initRCSBackend(ctx context.Context) error {
// no-op
out.Debug(ctx, "Using RCS Backend: noop")
default:
return fmt.Errorf("Unknown RCS Backend")
return fmt.Errorf("unknown rcs backend")
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/store/sub/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *Store) initStorageBackend(ctx context.Context) error {
}
s.storage = store
default:
return fmt.Errorf("Unknown storage backend")
return fmt.Errorf("unknown storage backend")
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestInit(t *testing.T) {

out, err := ts.run("init")
assert.Error(t, err)
assert.Equal(t, "[init] Initializing a new password store ...\n\nError: failed to initialize store: failed to read user input: Can not select private key without terminal\n", out)
assert.Equal(t, "[init] Initializing a new password store ...\n\nError: failed to initialize store: failed to read user input: can not select private key without terminal\n", out)

ts = newTester(t)
defer ts.teardown()
Expand Down
2 changes: 1 addition & 1 deletion tests/jsonapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestJSONAPI(t *testing.T) {

// message with empty object
response := getMessageResponse(t, ts, "{}")
assert.Equal(t, "{\"error\":\"Unknown message of type \"}", response)
assert.Equal(t, "{\"error\":\"unknown message of type \"}", response)

// query for keys with matching one
response = getMessageResponse(t, ts, "{\"type\":\"query\",\"query\":\"foo\"}")
Expand Down

0 comments on commit f968915

Please sign in to comment.