catenacyber / perfsprint

Golang linter to use strconv
MIT License
21 stars 2 forks source link

Fix linting sprintf that uses "%[1]s" #16

Closed Frassle closed 9 months ago

Frassle commented 10 months ago

Noticed when running "--fix" against a codebase that made use of "%[1]s" and "%s" format directives.

Without the fixes the negative test incorrectly tries to concatenate:

        -       fmt.Sprintf("%s %[1]s", "hello")
        +       "hello" + " %[1]s"

and the positive test doesn't:

        -       "Hello says " + s // want "fmt.Sprintf can be replaced with string addition"
        +       fmt.Sprintf("Hello says %[1]s", s) // want "fmt.Sprintf can be replaced with string addition"
catenacyber commented 9 months ago

Thanks @Frassle for the report and the fix

Any other feedback ?

Frassle commented 9 months ago

Any other feedback ?

Nope, otherwise seems to have worked as advertised 👍