github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/staticcheck/testdata/src/CheckTimerResetReturnValue/CheckTimerResetReturnValue.go (about)

     1  package fn
     2  
     3  import "time"
     4  
     5  func fn1() {
     6  	t := time.NewTimer(time.Second)
     7  	t.Reset(time.Second)
     8  }
     9  
    10  func fn2() {
    11  	t := time.NewTimer(time.Second)
    12  	_ = t.Reset(time.Second)
    13  }
    14  
    15  func fn3() {
    16  	t := time.NewTimer(time.Second)
    17  	println(t.Reset(time.Second))
    18  }
    19  
    20  func fn4() {
    21  	t := time.NewTimer(time.Second)
    22  	if t.Reset(time.Second) {
    23  		println("x")
    24  	}
    25  }
    26  
    27  func fn5() {
    28  	t := time.NewTimer(time.Second)
    29  	if t.Reset(time.Second) { // MATCH "it is not possible to use Reset's return value correctly"
    30  		<-t.C
    31  	}
    32  }
    33  
    34  func fn6(x bool) {
    35  	// Not matched because we don't support complex boolean
    36  	// expressions
    37  	t := time.NewTimer(time.Second)
    38  	if t.Reset(time.Second) || x {
    39  		<-t.C
    40  	}
    41  }
    42  
    43  func fn7(x bool) {
    44  	// Not matched because we don't analyze that deeply
    45  	t := time.NewTimer(time.Second)
    46  	y := t.Reset(2 * time.Second)
    47  	z := x || y
    48  	println(z)
    49  	if z {
    50  		<-t.C
    51  	}
    52  }
    53  
    54  func fn8() {
    55  	t := time.NewTimer(time.Second)
    56  	abc := t.Reset(time.Second) // MATCH "it is not possible to use Reset's return value correctly"
    57  	if abc {
    58  		<-t.C
    59  	}
    60  }
    61  
    62  func fn9() {
    63  	t := time.NewTimer(time.Second)
    64  	if t.Reset(time.Second) {
    65  		println("x")
    66  	}
    67  	<-t.C
    68  }
    69  
    70  func fn10() {
    71  	t := time.NewTimer(time.Second)
    72  	if !t.Reset(time.Second) { // MATCH "it is not possible to use Reset's return value correctly"
    73  		<-t.C
    74  	}
    75  }
    76  
    77  func fn11(ch chan int) {
    78  	t := time.NewTimer(time.Second)
    79  	if !t.Reset(time.Second) {
    80  		<-ch
    81  	}
    82  }