golangci-lint/test/ruleguard/strings_simplify.go
Sebastien Rosset 2c01ea7ff2
gocritic: add support for variable substitution in ruleguard path settings (#2308)
* Add  variable for ruleguard config directory

* Add  variable for ruleguard config directory

* Add  variable for ruleguard config directory

* Add  variable for ruleguard config directory

* Add unit tests

* Add unit tests for ruleguard

* Add unit tests for ruleguard

* Add unit tests for ruleguard

* Add unit tests for ruleguard, fix package name
2021-11-02 11:34:19 -07:00

19 lines
620 B
Go

// go:build ruleguard
package ruleguard
import "github.com/quasilyte/go-ruleguard/dsl"
func StringsSimplify(m dsl.Matcher) {
// Some issues have simple fixes that can be expressed as
// a replacement pattern. Rules can use Suggest() function
// to add a quickfix action for such issues.
m.Match(`strings.Replace($s, $old, $new, -1)`).
Report(`this Replace call can be simplified`).
Suggest(`strings.ReplaceAll($s, $old, $new)`)
// Suggest() can be used without Report().
// It'll print the suggested template to the user.
m.Match(`strings.Count($s1, $s2) == 0`).
Suggest(`!strings.Contains($s1, $s2)`)
}