diff --git a/go/tools/builders/nolint.go b/go/tools/builders/nolint.go index e6e3c0438..5e0a99526 100644 --- a/go/tools/builders/nolint.go +++ b/go/tools/builders/nolint.go @@ -23,6 +23,11 @@ func parseNolint(text string) (map[string]bool, bool) { if !strings.HasPrefix(text, "nolint") { return nil, false } + + // strip explanation comments + split := strings.Split(text, "//") + text = strings.TrimSpace(split[0]) + parts := strings.Split(text, ":") if len(parts) == 1 { return nil, true diff --git a/go/tools/builders/nolint_test.go b/go/tools/builders/nolint_test.go index 2870eaaff..143969a5b 100644 --- a/go/tools/builders/nolint_test.go +++ b/go/tools/builders/nolint_test.go @@ -50,12 +50,24 @@ func TestParseNolint(t *testing.T) { Valid: true, Linters: []string{"foo"}, }, + { + Name: "Single linter with an explanation", + Comment: "//nolint:foo // the foo lint is invalid for this line", + Valid: true, + Linters: []string{"foo"}, + }, { Name: "Multiple linters", Comment: "// nolint:a,b,c", Valid: true, Linters: []string{"a", "b", "c"}, }, + { + Name: "Multiple linters with explanation", + Comment: "// nolint:a,b,c // some reason", + Valid: true, + Linters: []string{"a", "b", "c"}, + }, } for _, tc := range tests {