Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,39 @@ func (c *unitImportChecker) Visit(n ast.Node) bool {
}
return false
}

type sameTypeArgumentsChecker struct {
checkerBase

allTypesPresent opVariant
optionalTypesOmited opVariant
}

func newSameTypeArgumentsChecker(ctxt *context) checker {
c := &sameTypeArgumentsChecker{}
c.ctxt = ctxt
c.allTypesPresent.warning = "use types always after each argument"
c.optionalTypesOmited.warning = "use only one type declaration after several arguments of the same type"
c.op = &operation{
name: "same type arguments",
variants: []*opVariant{&c.allTypesPresent, &c.optionalTypesOmited},
}
return c
}

func (c *sameTypeArgumentsChecker) Visit(n ast.Node) bool {
fun, ok := n.(*ast.FuncDecl)
if !ok {
return true
}

for _, param := range fun.Type.Params.List {
if len(param.Names) > 1 {
c.ctxt.mark(n, &c.optionalTypesOmited)
} else {
c.ctxt.mark(n, &c.allTypesPresent)
}
}

return false
}
1 change: 1 addition & 0 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestEnd2End(t *testing.T) {
"negative_tests1.go",
"negative_tests2.go",
"negative_tests3.go",
"negative_tests4.go",
}

for _, filename := range filenames {
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/Quasilyte/go-consistent

require (
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6
github.com/go-toolsmith/astcast v1.0.0
github.com/go-toolsmith/astequal v1.0.0
github.com/go-toolsmith/astinfo v0.0.0-20180906194353-9809ff7efb21
github.com/go-toolsmith/pkgload v1.0.0
github.com/go-toolsmith/typep v1.0.0
github.com/kisielk/gotool v1.0.0
golang.org/x/tools v0.0.0-20181024171208-a2dc47679d30
golang.org/x/tools v0.0.0-20190110163146-51295c7ec13a
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g=
github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6 h1:aTBUNRTatDDU24gbOEKEoLiDwxtc98ga6K/iMTm6fvs=
github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY=
github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ=
github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY=
github.com/go-toolsmith/astinfo v0.0.0-20180906194353-9809ff7efb21 h1:wP6mXeB2V/d1P1K7bZ5vDUO3YqEzcvOREOxZPEu3gVI=
github.com/go-toolsmith/astinfo v0.0.0-20180906194353-9809ff7efb21/go.mod h1:dDStQCHtmZpYOmjRP/8gHHnCCch3Zz3oEgCdZVdtweU=
github.com/go-toolsmith/pkgload v1.0.0 h1:4DFWWMXVfbcN5So1sBNW9+yeiMqLFGl1wFLTL5R0Tgg=
github.com/go-toolsmith/pkgload v1.0.0/go.mod h1:5eFArkbO80v7Z0kdngIxsRXRMTaX4Ilcwuh3clNrQJc=
github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8=
github.com/go-toolsmith/typep v1.0.0 h1:zKymWyA1TRYvqYrYDrfEMZULyrhcnGY3x7LDKU2XQaA=
github.com/go-toolsmith/typep v1.0.0/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
golang.org/x/tools v0.0.0-20181024171208-a2dc47679d30 h1:iZIABIEHjQFp5zqGZgQiaXi5Ue5czJhXyylr2CTtdRY=
golang.org/x/tools v0.0.0-20181024171208-a2dc47679d30/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190110163146-51295c7ec13a h1:sSIx6lCxXoSnDgf7mm3vA/EYXI/gFaJupV18uYCUDmQ=
golang.org/x/tools v0.0.0-20190110163146-51295c7ec13a/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
13 changes: 13 additions & 0 deletions testdata/negative_tests4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ntests4

// In this test suite function definitions have all types. No warnings should be generated.

func someFunc(
a int, b int, c int, d string, e string,
) {
return
}

func someOtherFunc(a int, b int, c int) {
return
}
12 changes: 12 additions & 0 deletions testdata/positive_tests1.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,15 @@ func defaultCaseOrder(x int, v interface{}) {
default:
}
}

func allTypes(a int, b int, c int) {
return
}

func allTypes2(a int, b int, c int) {
return
}

func omitTypes(a, b, c int) { //= use types always after each argument
return
}
12 changes: 12 additions & 0 deletions testdata/positive_tests2.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,15 @@ func defaultCaseOrder(x int, v interface{}) {
default:
}
}

func omitTypes(a, b, c int) {
return
}

func omitTypes2(a, b, c int) {
return
}

func allTypes(a int, b int, c int) { //= use only one type declaration after several arguments of the same type
return
}