Skip to content

Commit

Permalink
Add tests for inefficient string formatting (#2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 27, 2024
1 parent cb9386f commit 42aefda
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ linters-settings:
- name: string-format
disabled: false
arguments:
- ["b.Logf[0]", "/.*%.*/", "no format directive, use b.Log instead"]
- ["fmt.Errorf[0]", "/.*%.*/", "no format directive, use errors.New instead"]
- ["fmt.Fprintf[1]", "/.*%.*/", "no format directive, use fmt.Fprint instead"]
- ["fmt.Printf[0]", "/.*%.*/", "no format directive, use fmt.Print instead"]
- ["fmt.Sprintf[0]", "/.*%.*/", "no format directive, use fmt.Sprint instead"]
- ["log.Fatalf[0]", "/.*%.*/", "no format directive, use log.Fatal instead"]
- ["log.Printf[0]", "/.*%.*/", "no format directive, use log.Print instead"]
- ["t.Logf[0]", "/.*%.*/", "no format directive, use t.Log instead"]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
- name: struct-tag
disabled: false
Expand All @@ -159,6 +166,7 @@ linters-settings:
arguments:
- "fmt\\.Fprint"
- "fmt\\.Fprintf"
- "fmt\\.Fprintln"
- "fmt\\.Print"
- "fmt\\.Printf"
- "fmt\\.Println"
Expand Down
2 changes: 1 addition & 1 deletion indexer/examples/p-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
container, err := client.GetContainerByIndex(ctx, nextIndex)
if err != nil {
time.Sleep(time.Second)
log.Printf("polling for next accepted block\n")
log.Println("polling for next accepted block")
continue
}

Expand Down
2 changes: 1 addition & 1 deletion indexer/examples/x-chain-blocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
container, err := client.GetContainerByIndex(ctx, nextIndex)
if err != nil {
time.Sleep(time.Second)
log.Printf("polling for next accepted block\n")
log.Println("polling for next accepted block")
continue
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/tmpnet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
return err
}

fmt.Fprintf(os.Stdout, "\nConfigure tmpnetctl to target this network by default with one of the following statements:\n")
fmt.Fprintln(os.Stdout, "\nConfigure tmpnetctl to target this network by default with one of the following statements:")
fmt.Fprintf(os.Stdout, " - source %s\n", network.EnvFilePath())
fmt.Fprintf(os.Stdout, " - %s\n", network.EnvFileContents())
fmt.Fprintf(os.Stdout, " - export %s=%s\n", tmpnet.NetworkDirEnvName, latestSymlinkPath)
Expand Down
8 changes: 4 additions & 4 deletions tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (n *Network) Start(ctx context.Context, w io.Writer) error {
}
}

if _, err := fmt.Fprintf(w, "Waiting for all nodes to report healthy...\n\n"); err != nil {
if _, err := fmt.Fprint(w, "Waiting for all nodes to report healthy...\n\n"); err != nil {
return err
}
if err := n.WaitForHealthy(ctx, w); err != nil {
Expand Down Expand Up @@ -468,7 +468,7 @@ func (n *Network) Stop(ctx context.Context) error {

// Restarts all non-ephemeral nodes in the network.
func (n *Network) Restart(ctx context.Context, w io.Writer) error {
if _, err := fmt.Fprintf(w, " restarting network\n"); err != nil {
if _, err := fmt.Fprintln(w, " restarting network"); err != nil {
return err
}
for _, node := range n.Nodes {
Expand Down Expand Up @@ -627,7 +627,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
return err
}

if _, err := fmt.Fprintf(w, "Restarting node(s) to enable them to track the new subnet(s)\n"); err != nil {
if _, err := fmt.Fprintln(w, "Restarting node(s) to enable them to track the new subnet(s)"); err != nil {
return err
}
reconfiguredNodes := []*Node{}
Expand Down Expand Up @@ -704,7 +704,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
return nil
}

if _, err := fmt.Fprintf(w, "Restarting node(s) to pick up chain configuration\n"); err != nil {
if _, err := fmt.Fprintln(w, "Restarting node(s) to pick up chain configuration"); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ func waitForActiveValidators(
return err
}

if _, err := fmt.Fprintf(w, " "); err != nil {
if _, err := fmt.Fprint(w, " "); err != nil {
return err
}

for {
if _, err := fmt.Fprintf(w, "."); err != nil {
if _, err := fmt.Fprint(w, "."); err != nil {
return err
}
validators, err := pChainClient.GetCurrentValidators(ctx, subnet.SubnetID, nil)
Expand Down
2 changes: 1 addition & 1 deletion vms/rpcchainvm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestHelperProcess(t *testing.T) {
}

if len(args) == 0 {
fmt.Fprintf(os.Stderr, "failed to receive testKey\n")
fmt.Fprintln(os.Stderr, "failed to receive testKey")
os.Exit(2)
}

Expand Down

0 comments on commit 42aefda

Please sign in to comment.