2022-07-15 15:32:10 +02:00
//golangcitest:args -Egocritic
//golangcitest:config_path testdata/configs/gocritic.yml
2018-11-05 18:20:28 +03:00
package testdata
2019-01-26 18:26:38 +03:00
import (
"flag"
2024-02-19 16:50:25 +03:00
"io"
2019-01-26 18:26:38 +03:00
"log"
2021-11-02 11:34:19 -07:00
"strings"
2019-01-26 18:26:38 +03:00
)
2018-11-05 18:20:28 +03:00
2022-08-20 18:53:45 +02:00
var _ = * flag . Bool ( "global1" , false , "" ) // want `flagDeref: immediate deref in \*flag.Bool\(.global1., false, ..\) is most likely an error; consider using flag\.BoolVar`
2019-01-26 18:26:38 +03:00
type size1 struct {
2024-02-19 16:50:25 +03:00
a [ 12 ] bool
2019-01-26 18:26:38 +03:00
}
type size2 struct {
size1
2024-02-19 16:50:25 +03:00
b [ 12 ] bool
2019-01-26 18:26:38 +03:00
}
2024-02-19 16:50:25 +03:00
func gocriticAppendAssign ( ) {
var positives , negatives [ ] int
positives = append ( negatives , 1 )
negatives = append ( negatives , - 1 )
log . Print ( positives , negatives )
}
func gocriticDupSubExpr ( x bool ) {
if x && x { // want "dupSubExpr: suspicious identical LHS and RHS.*"
log . Print ( "x is true" )
2019-01-26 18:26:38 +03:00
}
}
2024-02-19 16:50:25 +03:00
func gocriticHugeParamSize1 ( ss size1 ) {
log . Print ( ss )
}
func gocriticHugeParamSize2 ( ss size2 ) { // want "hugeParam: ss is heavy \\(24 bytes\\); consider passing it by pointer"
log . Print ( ss )
}
func gocriticHugeParamSize2Ptr ( ss * size2 ) {
log . Print ( * ss )
}
func gocriticSwitchTrue ( ) {
switch true {
case false :
log . Print ( "false" )
default :
log . Print ( "default" )
2019-01-26 18:26:38 +03:00
}
}
2021-11-02 11:34:19 -07:00
2024-02-19 16:50:25 +03:00
func goCriticPreferStringWriter ( w interface {
io . Writer
io . StringWriter
} ) {
w . Write ( [ ] byte ( "test" ) ) // want "ruleguard: w\\.WriteString\\(\"test\"\\) should be preferred.*"
}
2021-11-02 11:34:19 -07:00
func gocriticStringSimplify ( ) {
s := "Most of the time, travellers worry about their luggage."
2022-08-20 18:53:45 +02:00
s = strings . Replace ( s , "," , "" , - 1 ) // want "ruleguard: this Replace call can be simplified.*"
2021-11-02 11:34:19 -07:00
log . Print ( s )
}
2022-08-14 18:21:32 +02:00
func gocriticRuleWrapperFunc ( ) {
2022-08-20 18:53:45 +02:00
strings . Replace ( "abcabc" , "a" , "d" , - 1 ) // want "ruleguard: this Replace call can be simplified.*"
2022-08-14 18:21:32 +02:00
}