github.com/nozzle/golangci-lint@v1.49.0-nz3/test/ruleguard/strings_simplify.go (about)

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