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

     1  package pkg
     2  
     3  import "sort"
     4  
     5  type MyIntSlice []int
     6  
     7  func (s MyIntSlice) Len() int           { return 0 }
     8  func (s MyIntSlice) Less(i, j int) bool { return true }
     9  func (s MyIntSlice) Swap(i, j int)      {}
    10  
    11  func fn1() {
    12  	var a []int
    13  	sort.Sort(sort.IntSlice(a)) // MATCH "sort.Ints"
    14  }
    15  
    16  func fn2() {
    17  	var b []float64
    18  	sort.Sort(sort.Float64Slice(b)) // MATCH "sort.Float64s"
    19  }
    20  
    21  func fn3() {
    22  	var c []string
    23  	sort.Sort(sort.StringSlice(c)) // MATCH "sort.Strings"
    24  }
    25  
    26  func fn4() {
    27  	var a []int
    28  	sort.Sort(MyIntSlice(a))
    29  }
    30  
    31  func fn5() {
    32  	var d MyIntSlice
    33  	sort.Sort(d)
    34  }
    35  
    36  func fn6() {
    37  	var e sort.Interface
    38  	sort.Sort(e)
    39  }
    40  
    41  func fn7() {
    42  	// Don't recommend sort.Ints when there was another legitimate
    43  	// sort.Sort call already
    44  	var a []int
    45  	var e sort.Interface
    46  	sort.Sort(e)
    47  	sort.Sort(sort.IntSlice(a))
    48  }
    49  
    50  func fn8() {
    51  	var a []int
    52  	sort.Sort(sort.IntSlice(a)) // MATCH "sort.Ints"
    53  	sort.Sort(sort.IntSlice(a)) // MATCH "sort.Ints"
    54  }
    55  
    56  func fn9() {
    57  	func() {
    58  		var a []int
    59  		sort.Sort(sort.IntSlice(a)) // MATCH "sort.Ints"
    60  	}()
    61  }
    62  
    63  func fn10() {
    64  	var a MyIntSlice
    65  	sort.Sort(sort.IntSlice(a)) // MATCH "sort.Ints"
    66  }