github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/test/testdata/gocritic.go (about)

     1  //golangcitest:args -Egocritic
     2  //golangcitest:config_path testdata/configs/gocritic.yml
     3  package testdata
     4  
     5  import (
     6  	"flag"
     7  	"log"
     8  	"strings"
     9  )
    10  
    11  var _ = *flag.Bool("global1", false, "") // want `flagDeref: immediate deref in \*flag.Bool\(.global1., false, ..\) is most likely an error; consider using flag\.BoolVar`
    12  
    13  type size1 struct {
    14  	a bool
    15  }
    16  
    17  type size2 struct {
    18  	size1
    19  	b bool
    20  }
    21  
    22  func gocriticRangeValCopySize1(ss []size1) {
    23  	for _, s := range ss {
    24  		log.Print(s)
    25  	}
    26  }
    27  
    28  func gocriticRangeValCopySize2(ss []size2) {
    29  	for _, s := range ss { // want "rangeValCopy: each iteration copies 2 bytes.*"
    30  		log.Print(s)
    31  	}
    32  }
    33  
    34  func gocriticStringSimplify() {
    35  	s := "Most of the time, travellers worry about their luggage."
    36  	s = strings.Replace(s, ",", "", -1) // want "ruleguard: this Replace call can be simplified.*"
    37  	log.Print(s)
    38  }
    39  
    40  func gocriticDup(x bool) {
    41  	if x && x { // want "ruleguard: suspicious identical LHS and RHS.*"
    42  		log.Print("x is true")
    43  	}
    44  }
    45  
    46  func gocriticRuleWrapperFunc() {
    47  	strings.Replace("abcabc", "a", "d", -1) // want "ruleguard: this Replace call can be simplified.*"
    48  }