From 33f63ec2f2f5d8afe1efe662caef401e1513b8d8 Mon Sep 17 00:00:00 2001 From: junk1tm Date: Sat, 8 Oct 2022 23:58:37 +0400 Subject: [PATCH] rules: add sort.Float64s to sortFuncs --- rules/refactor.go | 4 ++++ rules/testdata/refactor.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/rules/refactor.go b/rules/refactor.go index f46a1e28..e2ba0d8b 100644 --- a/rules/refactor.go +++ b/rules/refactor.go @@ -16,4 +16,8 @@ func sortFuncs(m dsl.Matcher) { m.Match(`sort.Slice($s, func($i, $j int) bool { return $s[$i] < $s[$j] })`). Where(m["s"].Type.Is(`[]int`)). Suggest(`sort.Ints($s)`) + + m.Match(`sort.Slice($s, func($i, $j int) bool { return $s[$i] < $s[$j] })`). + Where(m["s"].Type.Is(`[]float64`)). + Suggest(`sort.Float64s($s)`) } diff --git a/rules/testdata/refactor.go b/rules/testdata/refactor.go index e328dc1c..d8b1c3e4 100644 --- a/rules/testdata/refactor.go +++ b/rules/testdata/refactor.go @@ -7,6 +7,7 @@ import ( func sortFuncs() { var ints []int var strs []string + var floats []float64 sort.Slice(ints, func(i, j int) bool { // want `\QsortFuncs: suggestion: sort.Ints(ints)` return ints[i] < ints[j] @@ -15,4 +16,8 @@ func sortFuncs() { sort.Slice(strs, func(i, j int) bool { // want `\QsortFuncs: suggestion: sort.Strings(strs)` return strs[i] < strs[j] }) + + sort.Slice(floats, func(i, j int) bool { // want `\QsortFuncs: suggestion: sort.Float64s(floats)` + return floats[i] < floats[j] + }) }