github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/staticcheck/testdata/CheckPureFunctions.go (about)

     1  package pkg
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"strings"
     7  )
     8  
     9  func fn1() {
    10  	strings.Replace("", "", "", 1) // MATCH /is a pure function but its return value is ignored/
    11  	foo(1, 2)                      // MATCH /is a pure function but its return value is ignored/
    12  	bar(1, 2)
    13  }
    14  
    15  func fn2() {
    16  	r, _ := http.NewRequest("GET", "/", nil)
    17  	r.WithContext(context.Background()) // MATCH /is a pure function but its return value is ignored/
    18  }
    19  
    20  func foo(a, b int) int { return a + b }
    21  func bar(a, b int) int {
    22  	println(a + b)
    23  	return a + b
    24  }
    25  
    26  func empty() {}
    27  
    28  func fn3() {
    29  	empty()
    30  }