Skip to content

Commit 770d399

Browse files
committed
Enable additional golangci-lint checks
Refactors code to make them pass. RELEASE_NOTES=n/a Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
1 parent 9875877 commit 770d399

File tree

185 files changed

+1427
-1366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+1427
-1366
lines changed

.golangci.yml

+4-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ linters:
1313
- asciicheck
1414
- forcetypeassert
1515
- gci
16-
- gocyclo
16+
#- gocyclo # need to refactor internal/create/wizard
1717
- gofmt
1818
- goimports
1919
- gomoddirectives
@@ -26,18 +26,9 @@ linters:
2626
- nolintlint
2727
- prealloc
2828
- predeclared
29-
## These are working but disabled for now
30-
## - dogsled # two occurences we cannot really correct
31-
## - dupl # some dups in tests
32-
## - gochecknoinits # we use a lot of init
33-
## - goconst # annoying?
34-
## - godot # annoying?
35-
## - godox # we have a few todo...
36-
## - nestif # some work to refactor
37-
## - paralleltest # lots of work to pass
38-
## - revive # currently a bit buggy with Go 1.18 but works mostly
39-
## - tagliatelle # requires some refactoring
40-
## - testpackage # complains for a lot of packages
29+
- godot
30+
- nestif
31+
# - revive # currently a bit buggy with Go 1.18 but works mostly
4132

4233
## To enable once they work with Go 1.18:
4334
### - deadcode

internal/action/action.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
stdout io.Writer = os.Stdout
1818
)
1919

20-
// Action knows everything to run gopass CLI actions
20+
// Action knows everything to run gopass CLI actions.
2121
type Action struct {
2222
Name string
2323
Store *root.Store
@@ -26,7 +26,7 @@ type Action struct {
2626
rem *reminder.Store
2727
}
2828

29-
// New returns a new Action wrapper
29+
// New returns a new Action wrapper.
3030
func New(cfg *config.Config, sv semver.Version) (*Action, error) {
3131
return newAction(cfg, sv, true)
3232
}
@@ -49,16 +49,16 @@ func newAction(cfg *config.Config, sv semver.Version, remind bool) (*Action, err
4949
if err != nil {
5050
debug.Log("failed to init reminder: %s", err)
5151
} else {
52-
// only populate the reminder variable on success, the implementation
53-
// can handle being called on a nil pointer
52+
// only populate the reminder variable on success, the implementation.
53+
// can handle being called on a nil pointer.
5454
act.rem = r
5555
}
5656
}
5757

5858
return act, nil
5959
}
6060

61-
// String implement fmt.Stringer
61+
// String implement fmt.Stringer.
6262
func (s *Action) String() string {
6363
return s.Store.String()
6464
}

internal/action/aliases.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/urfave/cli/v2"
1111
)
1212

13-
// AliasesPrint prints all cofigured aliases
13+
// AliasesPrint prints all cofigured aliases.
1414
func (s *Action) AliasesPrint(c *cli.Context) error {
1515
out.Printf(c.Context, "Configured aliases:")
1616
aliases := pwrules.AllAliases()
@@ -25,7 +25,7 @@ func (s *Action) AliasesPrint(c *cli.Context) error {
2525
return nil
2626
}
2727

28-
// AliasesAdd adds a single alias to a domain
28+
// AliasesAdd adds a single alias to a domain.
2929
func (s *Action) AliasesAdd(c *cli.Context) error {
3030
ctx := ctxutil.WithGlobalFlags(c)
3131
domain := c.Args().First()
@@ -43,7 +43,7 @@ func (s *Action) AliasesAdd(c *cli.Context) error {
4343
return nil
4444
}
4545

46-
// AliasesRemove removes a single alias from a domain
46+
// AliasesRemove removes a single alias from a domain.
4747
func (s *Action) AliasesRemove(c *cli.Context) error {
4848
ctx := ctxutil.WithGlobalFlags(c)
4949
domain := c.Args().First()
@@ -61,7 +61,7 @@ func (s *Action) AliasesRemove(c *cli.Context) error {
6161
return nil
6262
}
6363

64-
// AliasesDelete remove an alias mapping for a domain
64+
// AliasesDelete remove an alias mapping for a domain.
6565
func (s *Action) AliasesDelete(c *cli.Context) error {
6666
ctx := ctxutil.WithGlobalFlags(c)
6767
domain := c.Args().First()

internal/action/audit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/urfave/cli/v2"
1010
)
1111

12-
// Audit validates passwords against common flaws
12+
// Audit validates passwords against common flaws.
1313
func (s *Action) Audit(c *cli.Context) error {
1414
ctx := ctxutil.WithGlobalFlags(c)
1515

internal/action/binary.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ var (
2323
binstdin = os.Stdin
2424
)
2525

26-
// Cat prints to or reads from STDIN/STDOUT
26+
// Cat prints to or reads from STDIN/STDOUT.
2727
func (s *Action) Cat(c *cli.Context) error {
2828
ctx := ctxutil.WithGlobalFlags(c)
2929
name := c.Args().First()
3030
if name == "" {
3131
return ExitError(ExitNoName, nil, "Usage: %s cat <NAME>", c.App.Name)
3232
}
3333

34-
// handle pipe to stdin
34+
// handle pipe to stdin.
3535
info, err := binstdin.Stat()
3636
if err != nil {
3737
return ExitError(ExitIO, err, "failed to stat stdin: %s", err)
3838
}
3939

40-
// if content is piped to stdin, read and save it
40+
// if content is piped to stdin, read and save it.
4141
if info.Mode()&os.ModeCharDevice == 0 {
4242
debug.Log("Reading from STDIN ...")
4343
content := &bytes.Buffer{}
@@ -78,14 +78,14 @@ func secFromBytes(dst, src string, in []byte) gopass.Secret {
7878
return sec
7979
}
8080

81-
// BinaryCopy copies either from the filesystem to the store or from the store
82-
// to the filesystem
81+
// BinaryCopy copies either from the filesystem to the store or from the store.
82+
// to the filesystem.
8383
func (s *Action) BinaryCopy(c *cli.Context) error {
8484
ctx := ctxutil.WithGlobalFlags(c)
8585
from := c.Args().Get(0)
8686
to := c.Args().Get(1)
8787

88-
// argument checking is in s.binaryCopy
88+
// argument checking is in s.binaryCopy.
8989
if err := s.binaryCopy(ctx, c, from, to, false); err != nil {
9090
return ExitError(ExitUnknown, err, "%s", err)
9191
}
@@ -94,25 +94,25 @@ func (s *Action) BinaryCopy(c *cli.Context) error {
9494

9595
// BinaryMove works like Copy but will remove (shred/wipe) the source
9696
// after a successful copy. Mostly useful for securely moving secrets into
97-
// the store if they are no longer needed / wanted on disk afterwards
97+
// the store if they are no longer needed / wanted on disk afterwards.
9898
func (s *Action) BinaryMove(c *cli.Context) error {
9999
ctx := ctxutil.WithGlobalFlags(c)
100100
from := c.Args().Get(0)
101101
to := c.Args().Get(1)
102102

103-
// argument checking is in s.binaryCopy
103+
// argument checking is in s.binaryCopy.
104104
if err := s.binaryCopy(ctx, c, from, to, true); err != nil {
105105
return ExitError(ExitUnknown, err, "%s", err)
106106
}
107107
return nil
108108
}
109109

110110
// binaryCopy implements the control flow for copy and move. We support two
111-
// workflows:
112-
// 1. From the filesystem to the store
113-
// 2. From the store to the filesystem
111+
// workflows:.
112+
// 1. From the filesystem to the store.
113+
// 2. From the store to the filesystem.
114114
//
115-
// Copying secrets in the store must be done through the regular copy command
115+
// Copying secrets in the store must be done through the regular copy command.
116116
func (s *Action) binaryCopy(ctx context.Context, c *cli.Context, from, to string, deleteSource bool) error {
117117
if from == "" || to == "" {
118118
op := "copy"
@@ -124,10 +124,10 @@ func (s *Action) binaryCopy(ctx context.Context, c *cli.Context, from, to string
124124

125125
switch {
126126
case fsutil.IsFile(from) && fsutil.IsFile(to):
127-
// copying from on file to another file is not supported
127+
// copying from on file to another file is not supported.
128128
return fmt.Errorf("ambiguity detected. Only from or to can be a file")
129129
case s.Store.Exists(ctx, from) && s.Store.Exists(ctx, to):
130-
// copying from one secret to another secret is not supported
130+
// copying from one secret to another secret is not supported.
131131
return fmt.Errorf("ambiguity detected. Either from or to must be a file")
132132
case fsutil.IsFile(from) && !fsutil.IsFile(to):
133133
return s.binaryCopyFromFileToStore(ctx, from, to, deleteSource)
@@ -139,11 +139,11 @@ func (s *Action) binaryCopy(ctx context.Context, c *cli.Context, from, to string
139139
}
140140

141141
func (s *Action) binaryCopyFromFileToStore(ctx context.Context, from, to string, deleteSource bool) error {
142-
// if the source is a file the destination must no to avoid ambiguities
142+
// if the source is a file the destination must not to avoid ambiguities.
143143
// if necessary this can be resolved by using a absolute path for the file
144-
// and a relative one for the secret
144+
// and a relative one for the secret.
145145

146-
// copy from FS to store
146+
// copy from FS to store.
147147
buf, err := os.ReadFile(from)
148148
if err != nil {
149149
return fmt.Errorf("failed to read file from %q: %w", from, err)
@@ -159,7 +159,7 @@ func (s *Action) binaryCopyFromFileToStore(ctx context.Context, from, to string,
159159
}
160160

161161
// it's important that we return if the validation fails, because
162-
// in that case we don't want to shred our (only) copy of this data!
162+
// in that case we don't want to shred our (only) copy of this data!.
163163
if err := s.binaryValidate(ctx, buf, to); err != nil {
164164
return fmt.Errorf("failed to validate written data: %w", err)
165165
}
@@ -171,9 +171,9 @@ func (s *Action) binaryCopyFromFileToStore(ctx context.Context, from, to string,
171171

172172
func (s *Action) binaryCopyFromStoreToFile(ctx context.Context, from, to string, deleteSource bool) error {
173173
// if the source is no file we assume it's a secret and to is a filename
174-
// (which may already exist or not)
174+
// (which may already exist or not).
175175

176-
// copy from store to FS
176+
// copy from store to FS.
177177
buf, err := s.binaryGet(ctx, from)
178178
if err != nil {
179179
return fmt.Errorf("failed to read data from %q: %w", from, err)
@@ -187,7 +187,7 @@ func (s *Action) binaryCopyFromStoreToFile(ctx context.Context, from, to string,
187187
}
188188

189189
// as before: if validation of the written data fails, we MUST NOT
190-
// delete the (only) source
190+
// delete the (only) source.
191191
if err := s.binaryValidate(ctx, buf, from); err != nil {
192192
return fmt.Errorf("failed to validate the written data: %w", err)
193193
}
@@ -238,7 +238,7 @@ func (s *Action) binaryGet(ctx context.Context, name string) ([]byte, error) {
238238
return buf, nil
239239
}
240240

241-
// Sum decodes binary content and computes the SHA256 checksum
241+
// Sum decodes binary content and computes the SHA256 checksum.
242242
func (s *Action) Sum(c *cli.Context) error {
243243
ctx := ctxutil.WithGlobalFlags(c)
244244
name := c.Args().First()

internal/action/clone.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/urfave/cli/v2"
1717
)
1818

19-
// Clone will fetch and mount a new password store from a git repo
19+
// Clone will fetch and mount a new password store from a git repo.
2020
func (s *Action) Clone(c *cli.Context) error {
2121
ctx := ctxutil.WithGlobalFlags(c)
2222
if c.IsSet("crypto") {
@@ -28,7 +28,7 @@ func (s *Action) Clone(c *cli.Context) error {
2828
return ExitError(ExitUsage, nil, "Usage: %s clone repo [mount]", s.Name)
2929
}
3030

31-
// gopass clone [--crypto=foo] [--path=/some/store] git://foo/bar team0
31+
// gopass clone [--crypto=foo] [--path=/some/store] git://foo/bar team0.
3232
repo := c.Args().Get(0)
3333
mount := ""
3434
if c.Args().Len() > 1 {
@@ -63,40 +63,40 @@ func (s *Action) clone(ctx context.Context, repo, mount, path string) error {
6363
return ExitError(ExitAlreadyInitialized, nil, "Can not clone %s to the root store, as this store is already initialized. Please try cloning to a submount: `%s clone %s sub`", repo, s.Name, repo)
6464
}
6565

66-
// make sure the parent directory exists
66+
// make sure the parent directory exists.
6767
if parentPath := filepath.Dir(path); !fsutil.IsDir(parentPath) {
6868
if err := os.MkdirAll(parentPath, 0700); err != nil {
6969
return ExitError(ExitUnknown, err, "Failed to create parent directory for clone: %s", err)
7070
}
7171
}
7272

73-
// clone repo
73+
// clone repo.
7474
out.Noticef(ctx, "Cloning git repository %q to %q ...", repo, path)
7575
if _, err := backend.Clone(ctx, storageBackendOrDefault(ctx), repo, path); err != nil {
7676
return ExitError(ExitGit, err, "failed to clone repo %q to %q: %s", repo, path, err)
7777
}
7878

79-
// add mount
79+
// add mount.
8080
debug.Log("Mounting cloned repo %q at %q", path, mount)
8181
if err := s.cloneAddMount(ctx, mount, path); err != nil {
8282
return err
8383
}
8484

85-
// save new mount in config file
85+
// save new mount in config file.
8686
if err := s.cfg.Save(); err != nil {
8787
return ExitError(ExitIO, err, "Failed to update config: %s", err)
8888
}
8989

90-
// try to init git config
90+
// try to init git config.
9191
out.Notice(ctx, "Configuring git repository ...")
9292

93-
// ask for git config values
93+
// ask for git config values.
9494
username, email, err := s.cloneGetGitConfig(ctx, mount)
9595
if err != nil {
9696
return err
9797
}
9898

99-
// initialize git config
99+
// initialize git config.
100100
if err := s.Store.RCSInitConfig(ctx, mount, username, email); err != nil {
101101
debug.Log("Stacktrace: %+v\n", err)
102102
out.Errorf(ctx, "Failed to configure git: %s", err)
@@ -131,8 +131,8 @@ func (s *Action) cloneAddMount(ctx context.Context, mount, path string) error {
131131

132132
func (s *Action) cloneGetGitConfig(ctx context.Context, name string) (string, string, error) {
133133
out.Printf(ctx, "🎩 Gathering information for the git repository ...")
134-
// for convenience, set defaults to user-selected values from available private keys
135-
// NB: discarding returned error since this is merely a best-effort look-up for convenience
134+
// for convenience, set defaults to user-selected values from available private keys.
135+
// NB: discarding returned error since this is merely a best-effort look-up for convenience.
136136
username, email, _ := cui.AskForGitConfigUser(ctx, s.Store.Crypto(ctx, name))
137137
if username == "" {
138138
username = termio.DetectName(ctx, nil)

internal/action/clone_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/stretchr/testify/require"
2020
)
2121

22-
// aGitRepo creates and initializes a small git repo
22+
// aGitRepo creates and initializes a small git repo.
2323
func aGitRepo(ctx context.Context, u *gptest.Unit, t *testing.T, name string) string {
2424
gd := filepath.Join(u.Dir, name)
2525
assert.NoError(t, os.MkdirAll(gd, 0700))

internal/action/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ShowFlags() []cli.Flag {
5252
}
5353
}
5454

55-
// GetCommands returns the cli commands exported by this module
55+
// GetCommands returns the cli commands exported by this module.
5656
func (s *Action) GetCommands() []*cli.Command {
5757
return []*cli.Command{
5858
{

0 commit comments

Comments
 (0)