Skip to content

Commit b9dbf79

Browse files
golangci-lint: add perfsprint linter and auto-fixes (#18830)
Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent c4d163b commit b9dbf79

File tree

467 files changed

+1772
-1677
lines changed

Some content is hidden

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

467 files changed

+1772
-1677
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ linters:
99
- errcheck
1010
- govet
1111
- ineffassign
12+
- perfsprint
1213
- staticcheck
1314
settings:
1415
depguard:

go/cache/theine/list_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818
package theine
1919

2020
import (
21-
"fmt"
2221
"strconv"
2322
"testing"
2423

@@ -45,7 +44,7 @@ func TestList(t *testing.T) {
4544

4645
for i := range 5 {
4746
entry := l.PopTail()
48-
require.Equal(t, StringKey(fmt.Sprintf("%d", i+1)), entry.key)
47+
require.Equal(t, StringKey(strconv.Itoa(i+1)), entry.key)
4948
}
5049
entry := l.PopTail()
5150
require.Nil(t, entry)

go/cache/theine/tlfu_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package theine
1919

2020
import (
2121
"fmt"
22+
"strconv"
2223
"strings"
2324
"testing"
2425

@@ -34,7 +35,7 @@ func TestTlfu(t *testing.T) {
3435

3536
var entries []*Entry[StringKey, string]
3637
for i := range 200 {
37-
e := NewEntry(StringKey(fmt.Sprintf("%d", i)), "", 1)
38+
e := NewEntry(StringKey(strconv.Itoa(i)), "", 1)
3839
evicted := tlfu.Set(e)
3940
entries = append(entries, e)
4041
require.Nil(t, evicted)
@@ -52,7 +53,7 @@ func TestTlfu(t *testing.T) {
5253
require.Equal(t, 1, tlfu.slru.protected.len)
5354

5455
for i := 200; i < 1000; i++ {
55-
e := NewEntry(StringKey(fmt.Sprintf("%d", i)), "", 1)
56+
e := NewEntry(StringKey(strconv.Itoa(i)), "", 1)
5657
entries = append(entries, e)
5758
evicted := tlfu.Set(e)
5859
require.Nil(t, evicted)

go/cmd/mysqlctl/command/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package command
1818

1919
import (
20-
"fmt"
20+
"errors"
2121

2222
"github.com/spf13/cobra"
2323

@@ -49,7 +49,7 @@ var (
4949
}
5050

5151
if vtcmd.IsRunningAsRoot() {
52-
return fmt.Errorf("mysqlctl cannot be run as root. Please run as a different user")
52+
return errors.New("mysqlctl cannot be run as root. Please run as a different user")
5353
}
5454

5555
return nil

go/cmd/vtbackup/cli/vtbackup.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func takeBackup(ctx, backgroundCtx context.Context, topoServer *topo.Server, bac
380380
}
381381
dbName := initDbNameOverride
382382
if dbName == "" {
383-
dbName = fmt.Sprintf("vt_%s", initKeyspace)
383+
dbName = "vt_" + initKeyspace
384384
}
385385

386386
backupParams := mysqlctl.BackupParams{
@@ -467,7 +467,7 @@ func takeBackup(ctx, backgroundCtx context.Context, topoServer *topo.Server, bac
467467
case mysqlctl.ErrNoBackup:
468468
// There is no backup found, but we may be taking the initial backup of a shard
469469
if !allowFirstBackup {
470-
return fmt.Errorf("no backup found; not starting up empty since --initial_backup flag was not enabled")
470+
return errors.New("no backup found; not starting up empty since --initial_backup flag was not enabled")
471471
}
472472
restorePos = replication.Position{}
473473
default:
@@ -854,14 +854,14 @@ func shouldBackup(ctx context.Context, topoServer *topo.Server, backupStorage ba
854854

855855
// We need at least one backup so we can restore first, unless the user explicitly says we don't
856856
if len(backups) == 0 && !allowFirstBackup {
857-
return false, fmt.Errorf("no existing backups to restore from; backup is not possible since --initial_backup flag was not enabled")
857+
return false, errors.New("no existing backups to restore from; backup is not possible since --initial_backup flag was not enabled")
858858
}
859859
if lastBackup == nil {
860860
if allowFirstBackup {
861861
// There's no complete backup, but we were told to take one from scratch anyway.
862862
return true, nil
863863
}
864-
return false, fmt.Errorf("no complete backups to restore from; backup is not possible since --initial_backup flag was not enabled")
864+
return false, errors.New("no complete backups to restore from; backup is not possible since --initial_backup flag was not enabled")
865865
}
866866

867867
// Has it been long enough since the last complete backup to need a new one?

go/cmd/vtctldclient/cli/tablets.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cli
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"strings"
2223

@@ -45,7 +46,7 @@ func TabletAliasesFromPosArgs(args []string) ([]*topodatapb.TabletAlias, error)
4546
// converts them to a map of tablet tags.
4647
func TabletTagsFromPosArgs(args []string) (map[string]string, error) {
4748
if len(args) == 0 {
48-
return nil, fmt.Errorf("no tablet tags specified")
49+
return nil, errors.New("no tablet tags specified")
4950
}
5051

5152
tags := make(map[string]string, len(args))

go/cmd/vtctldclient/command/backups.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package command
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"io"
2223
"strings"
@@ -243,7 +244,7 @@ func commandRestoreFromBackup(cmd *cobra.Command, args []string) error {
243244
}
244245

245246
if restoreFromBackupOptions.RestoreToPos != "" && restoreFromBackupOptions.RestoreToTimestamp != "" {
246-
return fmt.Errorf("--restore-to-pos and --restore-to-timestamp are mutually exclusive")
247+
return errors.New("--restore-to-pos and --restore-to-timestamp are mutually exclusive")
247248
}
248249

249250
var restoreToTimestamp time.Time

go/cmd/vtctldclient/command/root_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package command_test
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"os"
2322
"testing"
2423
"time"
@@ -85,7 +84,7 @@ func TestRootWithInternalVtctld(t *testing.T) {
8584
}{
8685
{
8786
command: "AddCellInfo",
88-
args: []string{"--root", fmt.Sprintf("/vitess/%s", cell), "--server-address", "", cell},
87+
args: []string{"--root", "/vitess/" + cell, "--server-address", "", cell},
8988
expectErr: "node already exists", // Cell already exists
9089
},
9190
{

go/cmd/vtctldclient/command/throttler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package command
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"time"
2223

@@ -75,10 +76,10 @@ var (
7576

7677
func validateUpdateThrottlerConfig(cmd *cobra.Command, args []string) error {
7778
if updateThrottlerConfigOptions.MetricName != "" && !cmd.Flags().Changed("threshold") {
78-
return fmt.Errorf("--metric-name flag requires --threshold flag. Set threshold to 0 to disable the metric threshold configuration")
79+
return errors.New("--metric-name flag requires --threshold flag. Set threshold to 0 to disable the metric threshold configuration")
7980
}
8081
if cmd.Flags().Changed("app-name") && updateThrottlerConfigOptions.AppName == "" {
81-
return fmt.Errorf("--app-name must not be empty")
82+
return errors.New("--app-name must not be empty")
8283
}
8384

8485
return nil

go/cmd/vtctldclient/command/vreplication/common/cancel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package common
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"sort"
2223

@@ -70,7 +71,7 @@ func commandCancel(cmd *cobra.Command, args []string) error {
7071
resp, err := GetClient().WorkflowDelete(GetCommandCtx(), req)
7172
if err != nil {
7273
if grpcerr, ok := status.FromError(err); ok && (grpcerr.Code() == codes.DeadlineExceeded) {
73-
return fmt.Errorf("Cancel action timed out. Please try again and the work will pick back up where it left off. Note that you can control the timeout using the --action_timeout flag and the delete batch size with --delete-batch-size.")
74+
return errors.New("Cancel action timed out. Please try again and the work will pick back up where it left off. Note that you can control the timeout using the --action_timeout flag and the delete batch size with --delete-batch-size.")
7475
}
7576
return err
7677
}

0 commit comments

Comments
 (0)