diff --git a/checkers/argOrder_checker.go b/checkers/argOrder_checker.go index 9e6a4fa70..85a6f7c66 100644 --- a/checkers/argOrder_checker.go +++ b/checkers/argOrder_checker.go @@ -48,7 +48,7 @@ func (c *argOrderChecker) VisitExpr(expr ast.Expr) { x := call.Args[0] y := call.Args[1] switch calledExpr.Sel.Name { - case "HasPrefix", "HasSuffix", "Contains", "TrimPrefix", "TrimSuffix": + case "HasPrefix", "HasSuffix", "Contains", "TrimPrefix", "TrimSuffix", "Split": if obj.Name() != "bytes" && obj.Name() != "strings" { return } diff --git a/checkers/testdata/argOrder/negative_tests.go b/checkers/testdata/argOrder/negative_tests.go index 9eb55caff..f43503ca9 100644 --- a/checkers/testdata/argOrder/negative_tests.go +++ b/checkers/testdata/argOrder/negative_tests.go @@ -14,10 +14,30 @@ func nonConstArgs(s1, s2 string, b1, b2 []byte) { _ = bytes.HasPrefix([]byte(s1), b1) } +func constOnlyArgs() { + _ = strings.HasPrefix("", "http://") + _ = bytes.HasPrefix([]byte{}, []byte("http://")) + _ = bytes.HasPrefix([]byte{}, []byte{'h', 't', 't', 'p', ':', '/', '/'}) + _ = strings.Contains("", ":") + _ = bytes.Contains([]byte{}, []byte(":")) + _ = strings.TrimPrefix("", ":") + _ = bytes.TrimPrefix([]byte{}, []byte(":")) + _ = strings.TrimSuffix("", ":") + _ = bytes.TrimSuffix([]byte{}, []byte(":")) + _ = strings.Split("", "/") + _ = bytes.Split([]byte{}, []byte("/")) +} + func properArgsOrder(s string, b []byte) { _ = strings.HasPrefix(s, "http://") _ = bytes.HasPrefix(b, []byte("http://")) _ = bytes.HasPrefix(b, []byte{'h', 't', 't', 'p', ':', '/', '/'}) _ = strings.Contains(s, ":") _ = bytes.Contains(b, []byte(":")) + _ = strings.TrimPrefix(s, ":") + _ = bytes.TrimPrefix(b, []byte(":")) + _ = strings.TrimSuffix(s, ":") + _ = bytes.TrimSuffix(b, []byte(":")) + _ = strings.Split(s, "/") + _ = bytes.Split(b, []byte("/")) } diff --git a/checkers/testdata/argOrder/positive_tests.go b/checkers/testdata/argOrder/positive_tests.go index 1f47c6543..bc8396678 100644 --- a/checkers/testdata/argOrder/positive_tests.go +++ b/checkers/testdata/argOrder/positive_tests.go @@ -28,6 +28,11 @@ func badArgOrder(s string, b []byte) { _ = strings.TrimSuffix(":", s) /*! probably meant `bytes.TrimSuffix(b, []byte(":"))` */ _ = bytes.TrimSuffix([]byte(":"), b) + + /*! probably meant `strings.Split(s, "/")` */ + _ = strings.Split("/", s) + /*! probably meant `bytes.Split(b, []byte("/"))` */ + _ = bytes.Split([]byte("/"), b) } func argubleCases(s string) {