From b8f0ff8ff2570963b534d70961919d638c6a763b Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 25 Mar 2024 19:32:57 +0100 Subject: [PATCH] [chore]: linting (#2840) Signed-off-by: Fernandez Ludovic --- .golangci.yml | 17 +++++++++++------ internal/action/clihelper_test.go | 2 -- internal/action/commands_test.go | 1 - internal/action/generate_test.go | 7 ------- internal/action/init_test.go | 2 -- internal/action/pwgen/pwgen.go | 6 +++--- internal/action/recipients.go | 11 +++++------ internal/audit/audit.go | 6 ++---- .../crypto/gpg/colons/parse_colons_test.go | 1 - .../backend/crypto/gpg/gpgconf/version_test.go | 2 -- internal/backend/crypto_test.go | 2 -- internal/backend/storage/fossilfs/fossil.go | 2 +- internal/backend/storage/fs/link.go | 2 +- internal/backend/storage/fs/store_test.go | 3 --- internal/cache/inmem_test.go | 4 ++-- internal/completion/fish/completion_test.go | 2 -- internal/completion/zsh/completion_test.go | 1 - internal/config/legacy/config.go | 4 ++-- internal/config/legacy/io_test.go | 1 - internal/cui/recipients.go | 2 +- internal/diff/diff_test.go | 2 -- internal/recipients/recipients_test.go | 3 --- internal/store/leaf/fsck_test.go | 1 - internal/store/leaf/list_test.go | 4 +--- internal/store/leaf/move_test.go | 10 +--------- internal/store/leaf/recipients_test.go | 4 ++-- internal/store/leaf/reencrypt.go | 2 +- internal/store/leaf/store_test.go | 6 ++---- internal/store/root/move_test.go | 2 -- internal/tpl/funcs.go | 2 +- internal/tpl/template_test.go | 1 - internal/updater/extract.go | 2 +- pkg/clipboard/clipboard_test.go | 6 +++--- pkg/debug/debug_test.go | 4 ++-- pkg/fsutil/fsutil.go | 2 +- pkg/fsutil/fsutil_test.go | 4 ++-- pkg/gitconfig/config.go | 2 +- pkg/gopass/secrets/akv_test.go | 4 ---- pkg/gopass/secrets/yaml_test.go | 2 +- pkg/otp/otp_test.go | 4 ---- pkg/otp/screenshot_supported.go | 2 +- pkg/pwgen/cryptic_test.go | 1 - pkg/pwgen/pwgen_test.go | 5 ++--- pkg/pwgen/pwrules/pwrules_test.go | 1 - pkg/termio/ask.go | 4 ++-- pkg/termio/ask_test.go | 2 +- pkg/termio/progress_test.go | 4 ++-- pkg/termio/reader.go | 2 +- 48 files changed, 56 insertions(+), 110 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 85c60c720c..efa14ff1a4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,5 @@ run: - skip-dirs: - - helpers/ - go: 1.22 - deadline: 5m + timeout: 5m linters-settings: gocyclo: @@ -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 diff --git a/internal/action/clihelper_test.go b/internal/action/clihelper_test.go index 4a4b2923c2..5ad46e30fa 100644 --- a/internal/action/clihelper_test.go +++ b/internal/action/clihelper_test.go @@ -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{} diff --git a/internal/action/commands_test.go b/internal/action/commands_test.go index 03a250c88d..9fd2a7377e 100644 --- a/internal/action/commands_test.go +++ b/internal/action/commands_test.go @@ -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) }) diff --git a/internal/action/generate_test.go b/internal/action/generate_test.go index f7a75e316b..5385b76c14 100644 --- a/internal/action/generate_test.go +++ b/internal/action/generate_test.go @@ -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) @@ -272,7 +270,6 @@ func TestExtractEmails(t *testing.T) { out: []string{"john.doe@example.org", "user@example.org"}, }, } { - tc := tc t.Run(fmt.Sprintf("%v", tc.in), func(t *testing.T) { assert.Equal(t, tc.out, extractEmails(tc.in)) }) @@ -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)) }) @@ -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)) }) @@ -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)) }) @@ -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) diff --git a/internal/action/init_test.go b/internal/action/init_test.go index 2b63c88b16..dbaf66b544 100644 --- a/internal/action/init_test.go +++ b/internal/action/init_test.go @@ -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) diff --git a/internal/action/pwgen/pwgen.go b/internal/action/pwgen/pwgen.go index e0f21167af..ad1956f632 100644 --- a/internal/action/pwgen/pwgen.go +++ b/internal/action/pwgen/pwgen.go @@ -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 @@ -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, " ") diff --git a/internal/action/recipients.go b/internal/action/recipients.go index 8f92f2c331..d2d0839b6f 100644 --- a/internal/action/recipients.go +++ b/internal/action/recipients.go @@ -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++ @@ -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 { @@ -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) @@ -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) diff --git a/internal/audit/audit.go b/internal/audit/audit.go index 11c336920a..84470dc6df 100644 --- a/internal/audit/audit.go +++ b/internal/audit/audit.go @@ -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) } @@ -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() @@ -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() diff --git a/internal/backend/crypto/gpg/colons/parse_colons_test.go b/internal/backend/crypto/gpg/colons/parse_colons_test.go index 3d399f2dfe..eed50defed 100644 --- a/internal/backend/crypto/gpg/colons/parse_colons_test.go +++ b/internal/backend/crypto/gpg/colons/parse_colons_test.go @@ -41,7 +41,6 @@ func TestParseColonIdentity(t *testing.T) { email: "", }, } { - tc := tc t.Run(tc.in, func(t *testing.T) { t.Parallel() diff --git a/internal/backend/crypto/gpg/gpgconf/version_test.go b/internal/backend/crypto/gpg/gpgconf/version_test.go index 89dff712e6..36c00b6c90 100644 --- a/internal/backend/crypto/gpg/gpgconf/version_test.go +++ b/internal/backend/crypto/gpg/gpgconf/version_test.go @@ -39,8 +39,6 @@ func TestSort(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/internal/backend/crypto_test.go b/internal/backend/crypto_test.go index 8c70278e1b..acc7842a9e 100644 --- a/internal/backend/crypto_test.go +++ b/internal/backend/crypto_test.go @@ -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() diff --git a/internal/backend/storage/fossilfs/fossil.go b/internal/backend/storage/fossilfs/fossil.go index 91f9021442..b87f0ad6f1 100644 --- a/internal/backend/storage/fossilfs/fossil.go +++ b/internal/backend/storage/fossilfs/fossil.go @@ -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") diff --git a/internal/backend/storage/fs/link.go b/internal/backend/storage/fs/link.go index 86dc4a2af1..dfe3f9f41f 100644 --- a/internal/backend/storage/fs/link.go +++ b/internal/backend/storage/fs/link.go @@ -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 } diff --git a/internal/backend/storage/fs/store_test.go b/internal/backend/storage/fs/store_test.go index db5591cda9..641e4e3e5f 100644 --- a/internal/backend/storage/fs/store_test.go +++ b/internal/backend/storage/fs/store_test.go @@ -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() @@ -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() diff --git a/internal/cache/inmem_test.go b/internal/cache/inmem_test.go index fc7de7ef1d..10b1ac4b0a 100644 --- a/internal/cache/inmem_test.go +++ b/internal/cache/inmem_test.go @@ -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) diff --git a/internal/completion/fish/completion_test.go b/internal/completion/fish/completion_test.go index 9a2fb6f879..e8ff338aa4 100644 --- a/internal/completion/fish/completion_test.go +++ b/internal/completion/fish/completion_test.go @@ -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() diff --git a/internal/completion/zsh/completion_test.go b/internal/completion/zsh/completion_test.go index 86a5198350..a9dcfbf571 100644 --- a/internal/completion/zsh/completion_test.go +++ b/internal/completion/zsh/completion_test.go @@ -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)) diff --git a/internal/config/legacy/config.go b/internal/config/legacy/config.go index f7ea7e3ff2..dd9bce0ac2 100644 --- a/internal/config/legacy/config.go +++ b/internal/config/legacy/config.go @@ -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 @@ -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 diff --git a/internal/config/legacy/io_test.go b/internal/config/legacy/io_test.go index b6c424a2fb..6eee2f6d92 100644 --- a/internal/config/legacy/io_test.go +++ b/internal/config/legacy/io_test.go @@ -333,7 +333,6 @@ version: "1.0.0"`, }, }, } { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/internal/cui/recipients.go b/internal/cui/recipients.go index 9341f84135..d2604f040a 100644 --- a/internal/cui/recipients.go +++ b/internal/cui/recipients.go @@ -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 } diff --git a/internal/diff/diff_test.go b/internal/diff/diff_test.go index dbcb2b7afb..bbe46169e6 100644 --- a/internal/diff/diff_test.go +++ b/internal/diff/diff_test.go @@ -36,8 +36,6 @@ func TestStat(t *testing.T) { removed: 1, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/internal/recipients/recipients_test.go b/internal/recipients/recipients_test.go index b934f869c1..da3145ca19 100644 --- a/internal/recipients/recipients_test.go +++ b/internal/recipients/recipients_test.go @@ -28,7 +28,6 @@ func TestMarshal(t *testing.T) { in: []string{"baz@bar.com", "zab@zab.com"}, }, } { - tc := tc t.Run(tc.want, func(t *testing.T) { t.Parallel() @@ -75,7 +74,6 @@ func TestUnmarshal(t *testing.T) { want: []string{"baz@bar.com", "zab@zab.com"}, }, } { - tc := tc t.Run(tc.in, func(t *testing.T) { t.Parallel() @@ -131,7 +129,6 @@ func TestEndToEnd(t *testing.T) { `, }, } { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/internal/store/leaf/fsck_test.go b/internal/store/leaf/fsck_test.go index d0772c0de2..aed99992b1 100644 --- a/internal/store/leaf/fsck_test.go +++ b/internal/store/leaf/fsck_test.go @@ -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() diff --git a/internal/store/leaf/list_test.go b/internal/store/leaf/list_test.go index c537506dea..0f33c16192 100644 --- a/internal/store/leaf/list_test.go +++ b/internal/store/leaf/list_test.go @@ -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" @@ -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() diff --git a/internal/store/leaf/move_test.go b/internal/store/leaf/move_test.go index 5bed30a85e..1e23bdb8f9 100644 --- a/internal/store/leaf/move_test.go +++ b/internal/store/leaf/move_test.go @@ -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" @@ -72,8 +72,6 @@ func TestCopy(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { // common setup tempdir := t.TempDir() @@ -156,8 +154,6 @@ func TestMove(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { // common setup tempdir := t.TempDir() @@ -223,8 +219,6 @@ func TestDelete(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { // common setup tempdir := t.TempDir() @@ -314,8 +308,6 @@ func TestPrune(t *testing.T) { }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { // common setup tempdir := t.TempDir() diff --git a/internal/store/leaf/recipients_test.go b/internal/store/leaf/recipients_test.go index 3f3c14f329..140bd08eab 100644 --- a/internal/store/leaf/recipients_test.go +++ b/internal/store/leaf/recipients_test.go @@ -11,7 +11,7 @@ import ( "testing" "github.com/gopasspw/gopass/internal/backend" - 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" @@ -137,7 +137,7 @@ func TestSaveRecipients(t *testing.T) { sort.Strings(foundRecs) ids := rs.IDs() - for i := 0; i < len(ids); i++ { + for i := range len(ids) { if i >= len(foundRecs) { t.Errorf("Read too few recipients") diff --git a/internal/store/leaf/reencrypt.go b/internal/store/leaf/reencrypt.go index bbb45dff0c..8a9213d3df 100644 --- a/internal/store/leaf/reencrypt.go +++ b/internal/store/leaf/reencrypt.go @@ -44,7 +44,7 @@ func (s *Store) reencrypt(ctx context.Context) error { logger := log.New(os.Stdout, "", 0) out.Print(ctx, "Starting reencrypt") - for i := 0; i < conc; i++ { + for i := range conc { wg.Add(1) // we start a new job go func(workerId int) { // the workers are fed through an unbuffered channel diff --git a/internal/store/leaf/store_test.go b/internal/store/leaf/store_test.go index 3052130753..a37d201064 100644 --- a/internal/store/leaf/store_test.go +++ b/internal/store/leaf/store_test.go @@ -100,7 +100,7 @@ func TestIdFile(t *testing.T) { // test sub-id secName := "a" - for i := 0; i < 99; i++ { + for range 99 { secName += "/a" } @@ -116,7 +116,7 @@ func TestIdFile(t *testing.T) { // test abort condition secName = "a" - for i := 0; i < 100; i++ { + for range 100 { secName += "/a" } require.NoError(t, s.Set(ctx, secName, sec)) @@ -166,8 +166,6 @@ func TestNew(t *testing.T) { ok: true, }, } { - tc := tc - t.Run(tc.dsc, func(t *testing.T) { t.Parallel() diff --git a/internal/store/root/move_test.go b/internal/store/root/move_test.go index 43042b4986..e45e99e04b 100644 --- a/internal/store/root/move_test.go +++ b/internal/store/root/move_test.go @@ -406,8 +406,6 @@ func TestComputeMoveDestination(t *testing.T) { dstIsDir: true, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/internal/tpl/funcs.go b/internal/tpl/funcs.go index b3763f3bcb..8119e11974 100644 --- a/internal/tpl/funcs.go +++ b/internal/tpl/funcs.go @@ -342,7 +342,7 @@ func stringslice(v any) []string { case reflect.Array, reflect.Slice: l := val.Len() res := make([]string, 0, l) - for i := 0; i < l; i++ { + for i := range l { value := val.Index(i).Interface() if value == nil { continue diff --git a/internal/tpl/template_test.go b/internal/tpl/template_test.go index 27eefc29ed..d27d42ce43 100644 --- a/internal/tpl/template_test.go +++ b/internal/tpl/template_test.go @@ -333,7 +333,6 @@ func TestVars(t *testing.T) { ShouldFail: true, }, } { - tc := tc t.Run(tc.Template, func(t *testing.T) { t.Parallel() diff --git a/internal/updater/extract.go b/internal/updater/extract.go index 2aef94ab0d..16fabd2725 100644 --- a/internal/updater/extract.go +++ b/internal/updater/extract.go @@ -79,7 +79,7 @@ func extractZip(buf []byte, dfh io.WriteCloser, dest string) (string, error) { return "", fmt.Errorf("failed to open zip file: %w", err) } - for i := 0; i < len(zrd.File); i++ { + for i := range len(zrd.File) { if zrd.File[i].Name != "gopass.exe" { continue } diff --git a/pkg/clipboard/clipboard_test.go b/pkg/clipboard/clipboard_test.go index d17a192f27..1b2f6e723c 100644 --- a/pkg/clipboard/clipboard_test.go +++ b/pkg/clipboard/clipboard_test.go @@ -13,7 +13,7 @@ import ( "github.com/atotto/clipboard" "github.com/gopasspw/gopass/internal/config" "github.com/gopasspw/gopass/internal/out" - ps "github.com/mitchellh/go-ps" + "github.com/mitchellh/go-ps" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -53,7 +53,7 @@ func TestClearClipboard(t *testing.T) { } func BenchmarkWalkProc(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; i < b.N; i++ { //nolint:intrange // b.N is evaluated at each iteration. _ = filepath.Walk("/proc", func(path string, info os.FileInfo, err error) error { if err != nil { return nil @@ -76,7 +76,7 @@ func BenchmarkWalkProc(b *testing.B) { } func BenchmarkListProc(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; i < b.N; i++ { //nolint:intrange // b.N is evaluated at each iteration. procs, err := ps.Processes() if err != nil { b.Fatalf("err: %s", err) diff --git a/pkg/debug/debug_test.go b/pkg/debug/debug_test.go index 10856c74d2..ff96b26d46 100644 --- a/pkg/debug/debug_test.go +++ b/pkg/debug/debug_test.go @@ -15,7 +15,7 @@ func BenchmarkLogging(b *testing.B) { initDebug() - for i := 0; i < b.N; i++ { + for i := 0; i < b.N; i++ { //nolint:intrange // b.N is evaluated at each iteration. Log("string") } } @@ -25,7 +25,7 @@ func BenchmarkNoLogging(b *testing.B) { initDebug() - for i := 0; i < b.N; i++ { + for i := 0; i < b.N; i++ { //nolint:intrange // b.N is evaluated at each iteration. Log("string") } } diff --git a/pkg/fsutil/fsutil.go b/pkg/fsutil/fsutil.go index 30127b1cc7..8d014be7d4 100644 --- a/pkg/fsutil/fsutil.go +++ b/pkg/fsutil/fsutil.go @@ -166,7 +166,7 @@ func Shred(path string, runs int) error { return buf } - for i := 0; i < runs; i++ { + for i := range runs { if i >= runs-1 { bufFn = func() []byte { return make([]byte, 1024) diff --git a/pkg/fsutil/fsutil_test.go b/pkg/fsutil/fsutil_test.go index 96f2a48d97..4d941f3a33 100644 --- a/pkg/fsutil/fsutil_test.go +++ b/pkg/fsutil/fsutil_test.go @@ -91,7 +91,7 @@ func TestShred(t *testing.T) { require.NoError(t, err) buf := make([]byte, 1024) - for i := 0; i < 10*1024; i++ { + for range 10 * 1024 { _, _ = rand.Read(buf) _, _ = fh.Write(buf) } @@ -105,7 +105,7 @@ func TestShred(t *testing.T) { require.NoError(t, err) buf = make([]byte, 1024) - for i := 0; i < 10*1024; i++ { + for range 10 * 1024 { _, _ = rand.Read(buf) _, _ = fh.Write(buf) } diff --git a/pkg/gitconfig/config.go b/pkg/gitconfig/config.go index bd84c8ec1f..6beb9824b0 100644 --- a/pkg/gitconfig/config.go +++ b/pkg/gitconfig/config.go @@ -421,7 +421,7 @@ func LoadConfigFromEnv(envPrefix string) *Config { c.vars = make(map[string][]string, count) - for i := 0; i < count; i++ { + for i := range count { keyVar := fmt.Sprintf("%s%d", envPrefix+"_KEY_", i) key := os.Getenv(keyVar) diff --git a/pkg/gopass/secrets/akv_test.go b/pkg/gopass/secrets/akv_test.go index 7e4d0c2058..fecdeb70b6 100644 --- a/pkg/gopass/secrets/akv_test.go +++ b/pkg/gopass/secrets/akv_test.go @@ -161,8 +161,6 @@ key: value2 }, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -289,8 +287,6 @@ foo: bar `, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/gopass/secrets/yaml_test.go b/pkg/gopass/secrets/yaml_test.go index 2f3dad7c9b..fbfc00aaa8 100644 --- a/pkg/gopass/secrets/yaml_test.go +++ b/pkg/gopass/secrets/yaml_test.go @@ -136,7 +136,7 @@ func TestYAMLSetMultipleKeys(t *testing.T) { numKey := 100 keys := make([]string, 0, numKey) - for i := 0; i < numKey; i++ { + for i := range numKey { // set key key := fmt.Sprintf("%s-%04d", yamlKey, i) require.NoError(t, s.Set(key, yamlValue)) diff --git a/pkg/otp/otp_test.go b/pkg/otp/otp_test.go index 946406cda7..3114fa8dd8 100644 --- a/pkg/otp/otp_test.go +++ b/pkg/otp/otp_test.go @@ -30,8 +30,6 @@ func TestCalculate(t *testing.T) { } for _, tc := range testCases { - tc := tc - t.Run(fmt.Sprintf("%s", tc), func(t *testing.T) { t.Parallel() @@ -78,8 +76,6 @@ func TestGetOTPURL(t *testing.T) { url: totpURL, }, } { - tc := tc - t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/otp/screenshot_supported.go b/pkg/otp/screenshot_supported.go index 51e8383f66..63efb44330 100644 --- a/pkg/otp/screenshot_supported.go +++ b/pkg/otp/screenshot_supported.go @@ -15,7 +15,7 @@ import ( // ParseScreen will attempt to parse all available screen and will look for otpauth QR codes. It returns the first one // it has found. func ParseScreen(ctx context.Context) (string, error) { - for i := 0; i < screenshot.NumActiveDisplays(); i++ { + for i := range screenshot.NumActiveDisplays() { out.Noticef(ctx, "Scanning screen n°%d", i) img, err := screenshot.CaptureDisplay(i) diff --git a/pkg/pwgen/cryptic_test.go b/pkg/pwgen/cryptic_test.go index 7430c2bc61..9380cad88e 100644 --- a/pkg/pwgen/cryptic_test.go +++ b/pkg/pwgen/cryptic_test.go @@ -24,7 +24,6 @@ func TestCrypticForDomain(t *testing.T) { sort.Strings(keys) for _, domain := range keys { - domain := domain t.Run(domain, func(t *testing.T) { for _, length := range []int{1, 4, 8, 100} { tcName := fmt.Sprintf("%s: generated password with %d chars", domain, length) diff --git a/pkg/pwgen/pwgen_test.go b/pkg/pwgen/pwgen_test.go index 1a508d75e8..c94fd5c7ac 100644 --- a/pkg/pwgen/pwgen_test.go +++ b/pkg/pwgen/pwgen_test.go @@ -97,7 +97,6 @@ func TestContainsAllClasses(t *testing.T) { ok: false, }, } { - tc := tc t.Run(tc.pw, func(t *testing.T) { t.Parallel() @@ -154,13 +153,13 @@ func TestPrune(t *testing.T) { } func BenchmarkPwgen(b *testing.B) { - for n := 0; n < b.N; n++ { + for n := 0; n < b.N; n++ { //nolint:intrange // b.N is evaluated at each iteration. GeneratePasswordCharset(24, CharAll) } } func BenchmarkPwgenCheck(b *testing.B) { - for n := 0; n < b.N; n++ { + for n := 0; n < b.N; n++ { //nolint:intrange // b.N is evaluated at each iteration. GeneratePasswordCharsetCheck(24, CharAll) } } diff --git a/pkg/pwgen/pwrules/pwrules_test.go b/pkg/pwgen/pwrules/pwrules_test.go index e82be0e0b6..aae73de754 100644 --- a/pkg/pwgen/pwrules/pwrules_test.go +++ b/pkg/pwgen/pwrules/pwrules_test.go @@ -53,7 +53,6 @@ func TestParseRule(t *testing.T) { }, }, } { - tc := tc t.Run(tc.in, func(t *testing.T) { t.Parallel() diff --git a/pkg/termio/ask.go b/pkg/termio/ask.go index 9fabac865e..475ad203a3 100644 --- a/pkg/termio/ask.go +++ b/pkg/termio/ask.go @@ -126,7 +126,7 @@ func AskForConfirmation(ctx context.Context, text string) bool { return true } - for i := 0; i < maxTries; i++ { + for range maxTries { choice, err := AskForBool(ctx, text, false) if err == nil { return choice @@ -166,7 +166,7 @@ func AskForPassword(ctx context.Context, name string, repeat bool) (string, erro askFn := GetPassPromptFunc(ctx) - for i := 0; i < maxTries; i++ { + for range maxTries { // check for context cancellation select { case <-ctx.Done(): diff --git a/pkg/termio/ask_test.go b/pkg/termio/ask_test.go index 7dd990f24f..c1289afc36 100644 --- a/pkg/termio/ask_test.go +++ b/pkg/termio/ask_test.go @@ -169,7 +169,7 @@ func TestAskForConfirmation(t *testing.T) { input := `y n ` - for i := 0; i < maxTries+1; i++ { + for range maxTries + 1 { input += "z\n" } diff --git a/pkg/termio/progress_test.go b/pkg/termio/progress_test.go index 4c946aa002..ea63bd72ce 100644 --- a/pkg/termio/progress_test.go +++ b/pkg/termio/progress_test.go @@ -11,7 +11,7 @@ func ExampleProgressBar() { //nolint:testableexamples max := 100 pb := NewProgressBar(int64(max)) - for i := 0; i < max+20; i++ { + for range max + 20 { pb.Inc() pb.Add(23) pb.Set(42) @@ -45,7 +45,7 @@ func TestProgressBytes(t *testing.T) { pb.Hidden = true pb.Bytes = true - for i := 0; i < 24; i++ { + for i := range 24 { pb.Set(2 << (i + 1)) } diff --git a/pkg/termio/reader.go b/pkg/termio/reader.go index 46524a9e56..6030e26010 100644 --- a/pkg/termio/reader.go +++ b/pkg/termio/reader.go @@ -59,7 +59,7 @@ func (lr LineReader) ReadLine() (string, error) { } // process the user input - for i := 0; i < n; i++ { + for i := range n { if buf[i] == '\n' { return out.String(), nil }