github.com/gwaycc/gometalinter@v3.0.0+incompatible/regressiontests/staticcheck_test.go (about)

     1  package regressiontests
     2  
     3  import "testing"
     4  
     5  func TestStaticCheck(t *testing.T) {
     6  	t.Parallel()
     7  	source := `package test
     8  
     9  import "regexp"
    10  
    11  var v = regexp.MustCompile("*")
    12  
    13  func f(ch chan bool) {
    14  	var ok bool
    15  	select {
    16  	case <- ch:
    17  	}
    18  
    19  	for {
    20  		select {
    21  		case <- ch:
    22  		}
    23  	}
    24  
    25  	if ok == true {
    26  	}
    27  }
    28  `
    29  	expected := Issues{
    30  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 5, Col: 5, Message: "var v is unused (U1000)"},
    31  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 5, Col: 27, Message: "error parsing regexp: missing argument to repetition operator: `*` (SA1000)"},
    32  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 7, Col: 6, Message: "func f is unused (U1000)"},
    33  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 9, Col: 2, Message: "should use a simple channel send/receive instead of select with a single case (S1000)"},
    34  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 13, Col: 2, Message: "should use for range instead of for { select {} } (S1000)"},
    35  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 19, Col: 2, Message: "empty branch (SA9003)"},
    36  		{Linter: "staticcheck", Severity: "warning", Path: "test.go", Line: 19, Col: 5, Message: "should omit comparison to bool constant, can be simplified to ok (S1002)"},
    37  	}
    38  	ExpectIssues(t, "staticcheck", source, expected)
    39  }