Skip to content

Commit

Permalink
analyzer: add tests for #360
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte committed Jan 16, 2022
1 parent 1e92ea5 commit bd58379
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions analyzer/testdata/src/regression/issue360.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package regression

import "strings"

func _(s1, s2 string) {
_ = map[int]int{
strings.Compare("", ""): 0, // want `\Qdon't use strings.Compare`
}

_ = map[int]int{
10: strings.Compare("", ""), // want `\Qdon't use strings.Compare`
}

_ = map[int]string{
10: "a",
strings.Compare(s1, s2): s2, // want `\Qdon't use strings.Compare`
20: "b",
}

_ = map[int]string{
10: "a",
20: "b",
strings.Compare(s1, s2): s2, // want `\Qdon't use strings.Compare`
}

_ = map[int]string{
strings.Compare(s1, s2): s2, // want `\Qdon't use strings.Compare`
10: "a",
20: "b",
}

}
7 changes: 7 additions & 0 deletions analyzer/testdata/src/regression/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ func issue315(m dsl.Matcher) {
!m["arg"].Type.Is(`error`),
).Report(`return concrete type instead of $arg`).At(m["name"])
}

func issue360(m dsl.Matcher) {
m.Match(`$_{$*_, $_: strings.Compare($s1, $_), $*_}`,
`$_{$*_, strings.Compare($s1, $_): $_, $*_}`).
Report(`don't use strings.Compare`).
At(m["s1"])
}

0 comments on commit bd58379

Please sign in to comment.