Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for inefficient string formatting #2878

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading