Skip to content

Commit

Permalink
add nolint parsing support for explanations (#3899)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyscott committed Mar 21, 2024
1 parent aeb83e8 commit 5a0e2c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/tools/builders/nolint.go
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions go/tools/builders/nolint_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 5a0e2c7

Please sign in to comment.