github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/misc/lint/rules.go (about)

     1  //go:build ruleguard
     2  
     3  package gorules
     4  
     5  import "github.com/quasilyte/go-ruleguard/dsl"
     6  
     7  // cf. https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices
     8  func declareEmptySlices(m dsl.Matcher) {
     9  	m.Match(
    10  		`$name := []$t{}`,
    11  		`$name := make([]$t, 0)`,
    12  	).
    13  		Suggest(`var $name []$t`).
    14  		Report(`replace '$$' with 'var $name []$t'`)
    15  }
    16  
    17  // cf. https://github.com/uber-go/guide/blob/master/style.md#initializing-maps
    18  func initializeMaps(m dsl.Matcher) {
    19  	m.Match(`map[$key]$value{}`).
    20  		Suggest(`make(map[$key]$value)`).
    21  		Report(`replace '$$' with 'make(map[$key]$value)`)
    22  }