golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/diagnostics/analyzers.txt (about)

     1  Test of warning diagnostics from various analyzers:
     2  copylocks, printf, slog, tests, timeformat, and nilness.
     3  
     4  -- go.mod --
     5  module example.com
     6  go 1.12
     7  
     8  -- flags --
     9  -min_go=go1.21
    10  
    11  -- bad_test.go --
    12  package analyzer
    13  
    14  import (
    15  	"fmt"
    16  	"log/slog"
    17  	"sync"
    18  	"testing"
    19  	"time"
    20  )
    21  
    22  // copylocks
    23  func _() {
    24  	var x sync.Mutex
    25  	_ = x //@diag("x", re"assignment copies lock value to _: sync.Mutex")
    26  }
    27  
    28  // printf
    29  func _() {
    30  	printfWrapper("%s") //@diag(re`printfWrapper\(.*\)`, re"example.com.printfWrapper format %s reads arg #1, but call has 0 args")
    31  }
    32  
    33  func printfWrapper(format string, args ...interface{}) {
    34  	fmt.Printf(format, args...)
    35  }
    36  
    37  // slog
    38  func _() {
    39  	slog.Info("msg", 1) //@diag("1", re`slog.Info arg "1" should be a string or a slog.Attr`)
    40  }
    41  
    42  // tests
    43  func Testbad(t *testing.T) { //@diag("", re"Testbad has malformed name: first letter after 'Test' must not be lowercase")
    44  }
    45  
    46  // timeformat
    47  func _() {
    48  	now := time.Now()
    49  	fmt.Println(now.Format("2006-02-01")) //@diag("2006-02-01", re"2006-02-01 should be 2006-01-02")
    50  }
    51  
    52  // nilness
    53  func _(ptr *int) {
    54  	if ptr == nil {
    55  		_ = *ptr //@diag("*ptr", re"nil dereference in load")
    56  	}
    57  }