-
Notifications
You must be signed in to change notification settings - Fork 113
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
Do not use Sprintf to convert types #873
Comments
It looks like it can be expressed with AST-based patterns quite easily: https://github.com/quasilyte/go-ruleguard/blob/master/analyzer/testdata/src/extra/extra.rules.go I'll copy a small example here: m.Match(`fmt.Sprintf("%t", $i&1 == 0)`).
Report(`use strconv.FormatBool($i&1 == 0)`) We might include an ability to load ruleguard-based rules into go-critic later when it's more stable and is actually released, but for now, you can use If anyone submits a code that implements this check into go-critic (without ruleguard), I'm still willing to merge that PR. |
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This is part of the ruleguard integration experiment. Hopefully, we can get some feedback to improve the way it's integrated. The simplest way to try it out: gocritic check -enable ruleguard -@ruleguard.rules <gorules> <target> Where: <gorules> is a path to a Go rules file <target> is a linting target An example gorules file can be found here: https://github.com/quasilyte/go-ruleguard/blob/master/rules.go Visit https://github.com/quasilyte/go-ruleguard for more info on the ruleguard. Updates #873 Updates #869 Updates #837 Updates #836 Updates #831 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
Related to golangci/golangci-lint#3714 |
Do not use
fmt.Sprintf
to convert types (e.g.fmt.Sprintf("%d", aNumber)
,fmt.Sprintf("%t", aBoolean)
)Before:
After:
Inspired by Bad Go: frivolous Sprintf
The text was updated successfully, but these errors were encountered: