From 8111de3f72834d0d9c72a54bf62b2341eafa1bdb Mon Sep 17 00:00:00 2001 From: Mario Carrion Date: Mon, 15 Apr 2019 17:14:32 -0400 Subject: [PATCH] methods: fix exported/unexported bug Fix case where last method was exported after a new exported method (from a different type) is defined afterwards. --- methods.go | 1 + methods_test.go | 5 +++++ testdata/methods_sorted_unexported_ok.go | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 testdata/methods_sorted_unexported_ok.go diff --git a/methods.go b/methods.go index 38af0be..52e7eb5 100644 --- a/methods.go +++ b/methods.go @@ -81,6 +81,7 @@ func (m *MethodsValidator) Validate(v *ast.FuncDecl, fset *token.FileSet) error if m.lastType != rcvType.Name { m.sortedTypes.identType = "Type" + m.sortedMethods = sortedNamesValidator{} if err := validateSorted(&m.sortedTypes, rcvType, false); err != nil { return err } diff --git a/methods_test.go b/methods_test.go index cdc41a3..5aed41f 100644 --- a/methods_test.go +++ b/methods_test.go @@ -30,6 +30,11 @@ func TestMethodsValidator_Validate(t *testing.T) { "methods_sorted_type_ok.go", false, }, + { + "OK: sorted exported/unexported", + "methods_sorted_unexported_ok.go", + false, + }, { "Error: not defined in file", "methods_not_defined.go", diff --git a/testdata/methods_sorted_unexported_ok.go b/testdata/methods_sorted_unexported_ok.go new file mode 100644 index 0000000..a2e6356 --- /dev/null +++ b/testdata/methods_sorted_unexported_ok.go @@ -0,0 +1,14 @@ +package testdata + +type ( + MethodSortedTypeUnexported_A struct{} + MethodSortedTypeUnexported_B struct{} +) + +func (MethodSortedTypeUnexported_A) A() {} +func (MethodSortedTypeUnexported_A) B() {} +func (*MethodSortedTypeUnexported_A) c() {} + +//- + +func (MethodSortedTypeUnexported_B) A() {}