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

Incorrect (*strings.Builder).Write suggestion #26

Closed
Juneezee opened this issue May 22, 2023 · 1 comment
Closed

Incorrect (*strings.Builder).Write suggestion #26

Juneezee opened this issue May 22, 2023 · 1 comment
Assignees

Comments

@Juneezee
Copy link

Minimal reproducible example:

package main

import "strings"

func main() {
	var strBuilder strings.Builder
	var text string = "text"
	var b byte = text[0]

	strBuilder.WriteString(string(b))
}

What did I do

$ mirror --fix main.go
main.go:10:2: avoid allocations with (*strings.Builder).Write

Expected

strBuilder.WriteString(string(b)) is replaced by strBuilder.WriteByte(b)

Actual

mirror replaces strBuilder.WriteString(string(b)) with strBuilder.Write(b), which is incorrect as b is a byte and (*strings.Builder).Write takes []byte.

Reference
  1. https://pkg.go.dev/strings#Builder.Write

  2. https://pkg.go.dev/strings#Builder.WriteByte

  3. https://pkg.go.dev/strings#Builder.WriteString

@butuzov butuzov self-assigned this May 22, 2023
butuzov added a commit that referenced this issue May 27, 2023
we going to ignore other types than []byte while doing conversion
butuzov added a commit that referenced this issue May 27, 2023
we going to ignore other types than []byte while doing conversion
@butuzov
Copy link
Owner

butuzov commented May 27, 2023

  • (bytes.Buffer|strings.Builder).WriteByte(c byte) error
  • (bytes.Buffer|strings.Builder).WriteRune(r rune) (n int, err error)

Support will be added in the near future (or whenever I have time to code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants