Skip to content

Commit

Permalink
[chore]: linting (#2840)
Browse files Browse the repository at this point in the history
Signed-off-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
ldez authored Mar 25, 2024
1 parent 57f19d2 commit b8f0ff8
Show file tree
Hide file tree
Showing 48 changed files with 56 additions and 110 deletions.
17 changes: 11 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
run:
skip-dirs:
- helpers/
go: 1.22
deadline: 5m
timeout: 5m

linters-settings:
gocyclo:
Expand Down Expand Up @@ -80,6 +77,14 @@ linters:
- wsl

issues:
exclude-use-default: false # disable filtering of defaults for better zero-issue policy
max-per-linter: 0 # disable limit; report all issues of a linter
max-issues-per-linter: 0 # disable limit; report all issues of a linter
max-same-issues: 0 # disable limit; report all issues of the same issue
exclude-use-default: false # disable filtering of defaults for better zero-issue policy
exclude-dirs:
- helpers/

output:
sort-results: true
sort-order:
- linter
- file
2 changes: 0 additions & 2 deletions internal/action/clihelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func TestParseArgs(t *testing.T) {
kvOut: map[string]string{"baz": "bam"},
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
if tc.argOut == nil {
tc.argOut = argList{}
Expand Down
1 change: 0 additions & 1 deletion internal/action/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func TestCommands(t *testing.T) {
ctx = act.cfg.WithConfig(ctx) //nolint:ineffassign

for _, cmd := range act.GetCommands() {
cmd := cmd
t.Run(cmd.Name, func(t *testing.T) {
testCommand(t, cmd)
})
Expand Down
7 changes: 0 additions & 7 deletions internal/action/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ func TestKeyAndLength(t *testing.T) {
length: "",
},
} {
tc := tc

t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
app := cli.NewApp()
fs := flag.NewFlagSet("default", flag.ContinueOnError)
Expand All @@ -272,7 +270,6 @@ func TestExtractEmails(t *testing.T) {
out: []string{"[email protected]", "[email protected]"},
},
} {
tc := tc
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
assert.Equal(t, tc.out, extractEmails(tc.in))
})
Expand All @@ -292,7 +289,6 @@ func TestExtractDomains(t *testing.T) {
out: []string{"gmail.com", "live.com", "web.de"},
},
} {
tc := tc
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
assert.Equal(t, tc.out, extractDomains(tc.in))
})
Expand All @@ -312,7 +308,6 @@ func TestUniq(t *testing.T) {
out: []string{"bar", "foo"},
},
} {
tc := tc
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
assert.Equal(t, tc.out, uniq(tc.in))
})
Expand All @@ -339,7 +334,6 @@ func TestFilterPrefix(t *testing.T) {
out: []string{"foo/bar", "foo/baz"},
},
} {
tc := tc
t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) {
assert.Equal(t, tc.out, filterPrefix(tc.in, tc.prefix))
})
Expand Down Expand Up @@ -372,7 +366,6 @@ func TestDefaultLengthFromEnv(t *testing.T) {
{in: "abc", expected: config.DefaultPasswordLength, custom: false},
{in: "-1", expected: config.DefaultPasswordLength, custom: false},
} {
tc := tc
t.Setenv(pwLengthEnvName, tc.in)
actual, isCustom := config.DefaultPasswordLengthFromEnv(ctx)
assert.Equal(t, tc.expected, actual)
Expand Down
2 changes: 0 additions & 2 deletions internal/action/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ func TestInitParseContext(t *testing.T) {
},
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
c := gptest.CliCtxWithFlags(config.NewContextInMemory(), t, tc.flags)
require.NoError(t, tc.check(initParseContext(c.Context, c)), tc.name)
Expand Down
6 changes: 3 additions & 3 deletions internal/action/pwgen/pwgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func xkcdGen(c *cli.Context, length, num int) error {
numbers = c.Bool("xkcdnumbers")
}

for i := 0; i < num; i++ {
for range num {
s, err := xkcdgen.RandomLengthDelim(length, sep, lang, capitalize, numbers)
if err != nil {
return err
Expand Down Expand Up @@ -109,8 +109,8 @@ func pwGen(c *cli.Context, pwLen, pwNum int) error {
charset += pwgen.Syms
}

for i := 0; i < pwNum; i++ {
for j := 0; j < perLine; j++ {
for range pwNum {
for range perLine {
ctx := out.WithNewline(ctx, false)
out.Print(ctx, pwgen.GeneratePasswordCharset(pwLen, charset))
out.Print(ctx, " ")
Expand Down
11 changes: 5 additions & 6 deletions internal/action/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,13 @@ func (s *Action) RecipientsAdd(c *cli.Context) error {
continue
}

recp := r
debug.Log("found recipients for %q: %+v", r, keys)

if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add %q (key %q) as a recipient to the store %q?", crypto.FormatKey(ctx, recp, ""), recp, store)) {
if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add %q (key %q) as a recipient to the store %q?", crypto.FormatKey(ctx, r, ""), r, store)) {
continue
}

if err := s.Store.AddRecipient(ctx, store, recp); err != nil {
if err := s.Store.AddRecipient(ctx, store, r); err != nil {
return exit.Error(exit.Recipients, err, "failed to add recipient %q: %s", r, err)
}
added++
Expand Down Expand Up @@ -201,7 +200,7 @@ func (s *Action) RecipientsRemove(c *cli.Context) error {
}
}

// if we a literal recipient (e.g. ID) is given just remove that w/o any kind of lookups.
// if a literal recipient (e.g. ID) is given just remove that w/o any kind of lookups.
if set.Contains(knownRecipients, r) {
debug.Log("Removing %q from %q (direct)", r, store)
if err := s.Store.RemoveRecipient(ctx, store, r); err != nil {
Expand All @@ -213,7 +212,7 @@ func (s *Action) RecipientsRemove(c *cli.Context) error {
continue
}

// look up the full key ID of the given recipient (could be email or any kinf of short ID)
// look up the full key ID of the given recipient (could be email or any kind of short ID)
keys, err := crypto.FindRecipients(ctx, r)
if err != nil {
out.Printf(ctx, "WARNING: Failed to list public key %q: %s", r, err)
Expand All @@ -235,7 +234,7 @@ func (s *Action) RecipientsRemove(c *cli.Context) error {
continue
}

recp := r
recp := r //nolint:copyloopvar
if len(keys) > 0 {
if nr := crypto.Fingerprint(ctx, keys[0]); nr != "" {
debug.Log("Fingerprint translated %q into %q", keys[0], nr)
Expand Down
6 changes: 2 additions & 4 deletions internal/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (a *Auditor) Batch(ctx context.Context, secrets []string) (*Report, error)
debug.Log("launching %d audit workers", maxJobs)

done := make(chan struct{}, maxJobs)
for jobs := 0; jobs < maxJobs; jobs++ {
for range maxJobs {
go a.audit(ctx, pending, done)
}

Expand All @@ -166,7 +166,7 @@ func (a *Auditor) Batch(ctx context.Context, secrets []string) (*Report, error)
bar.Inc()
}

for i := 0; i < maxJobs; i++ {
for range maxJobs {
<-done
}
bar.Done()
Expand Down Expand Up @@ -228,8 +228,6 @@ func (a *Auditor) auditSecret(ctx context.Context, secret string) {
// pass the secret to all validators.
var wg sync.WaitGroup
for _, v := range a.v {
v := v

wg.Add(1)
go func() {
defer wg.Done()
Expand Down
1 change: 0 additions & 1 deletion internal/backend/crypto/gpg/colons/parse_colons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestParseColonIdentity(t *testing.T) {
email: "",
},
} {
tc := tc
t.Run(tc.in, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/backend/crypto/gpg/gpgconf/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func TestSort(t *testing.T) {
},
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/backend/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ func TestDetectCrypto(t *testing.T) {
file: ".age-recipients",
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
ctx := config.NewContextInMemory()

Expand Down
2 changes: 1 addition & 1 deletion internal/backend/storage/fossilfs/fossil.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (f *Fossil) Revisions(ctx context.Context, name string) ([]backend.Revision
}

debug.Log("Parsing line: %s", line)
body := line // retain full line for the body
body := line //nolint:copyloopvar // retain full line for the body
date, line, found := strings.Cut(line, " ")
if !found {
debug.Log("Failed to parse date")
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/storage/fs/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// addRel adds the required number of relative elements to go from dst back to
// src.
func addRel(src, dst string) string {
for i := 0; i < strings.Count(dst, "/"); i++ {
for range strings.Count(dst, "/") {
src = "../" + src
}

Expand Down
3 changes: 0 additions & 3 deletions internal/backend/storage/fs/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ func TestRemoveEmptyParentDirectories(t *testing.T) {
}

for _, test := range tests {
test := test

t.Run(test.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -221,7 +219,6 @@ func TestDelete(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions internal/cache/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func TestPar(t *testing.T) {
c := NewInMemTTL[int, int](time.Minute, time.Minute)
c.now = nowFunc(0)

for i := 0; i < 32; i++ {
for j := 0; j < 32; j++ {
for i := range 32 {
for range 32 {
t.Run("set"+strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
c.Set(i, i)
Expand Down
2 changes: 0 additions & 2 deletions internal/completion/fish/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func TestFormatFlag(t *testing.T) {
{"", "Print", "long", ""},
{"print, p", "Print", "foo", ""},
} {
tc := tc

t.Run(tc.Name, func(t *testing.T) {
assert.Equal(t, tc.Out, formatFlag(tc.Name, tc.Usage, tc.Typ))
t.Parallel()
Expand Down
1 change: 0 additions & 1 deletion internal/completion/zsh/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestFormatFlag(t *testing.T) {
}{
{"print, p", "Print", "--print[Print]"},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tc.out, formatFlag(tc.name, tc.usage))
Expand Down
4 changes: 2 additions & 2 deletions internal/config/legacy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *Config) SetConfigValue(key, value string) error {
func (c *Config) setConfigValue(key, value string) error {
value = strings.ToLower(value)
o := reflect.ValueOf(c).Elem()
for i := 0; i < o.NumField(); i++ {
for i := range o.NumField() {
jsonArg := o.Type().Field(i).Tag.Get("yaml")
if jsonArg == "" || jsonArg == "-" {
continue
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *Config) Directory() string {
func (c *Config) ConfigMap() map[string]string {
m := make(map[string]string, 20)
o := reflect.ValueOf(c).Elem()
for i := 0; i < o.NumField(); i++ {
for i := range o.NumField() {
jsonArg := o.Type().Field(i).Tag.Get("yaml")
if jsonArg == "" || jsonArg == "-" {
continue
Expand Down
1 change: 0 additions & 1 deletion internal/config/legacy/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ version: "1.0.0"`,
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion internal/cui/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func AskForPrivateKey(ctx context.Context, crypto backend.Crypto, prompt string)
}

fmtStr := "[%" + strconv.Itoa((len(kl)/10)+1) + "d] %s - %s\n"
for i := 0; i < maxTries; i++ {
for range maxTries {
if !ctxutil.IsTerminal(ctx) || !ctxutil.IsInteractive(ctx) {
return kl[0], nil
}
Expand Down
2 changes: 0 additions & 2 deletions internal/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func TestStat(t *testing.T) {
removed: 1,
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 0 additions & 3 deletions internal/recipients/recipients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestMarshal(t *testing.T) {
in: []string{"[email protected]", "[email protected]"},
},
} {
tc := tc
t.Run(tc.want, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -75,7 +74,6 @@ func TestUnmarshal(t *testing.T) {
want: []string{"[email protected]", "[email protected]"},
},
} {
tc := tc
t.Run(tc.in, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -131,7 +129,6 @@ func TestEndToEnd(t *testing.T) {
`,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/store/leaf/fsck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func TestCompareStringSlices(t *testing.T) {
extra: []string{"baz", "zab"},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 1 addition & 3 deletions internal/store/leaf/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

plain "github.com/gopasspw/gopass/internal/backend/crypto/plain"
"github.com/gopasspw/gopass/internal/backend/crypto/plain"
"github.com/gopasspw/gopass/internal/backend/storage/fs"
"github.com/gopasspw/gopass/internal/config"
"github.com/gopasspw/gopass/internal/out"
Expand Down Expand Up @@ -77,8 +77,6 @@ func TestList(t *testing.T) {
out: []string{"foo/bar", "foo/baz", "foo/zab"},
},
} {
tc := tc

t.Run(tc.name, func(t *testing.T) {
// common setup
tempdir := t.TempDir()
Expand Down
Loading

0 comments on commit b8f0ff8

Please sign in to comment.