Skip to content

Commit

Permalink
Unknown linter breaks //nolint
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankgb committed Nov 6, 2020
1 parent 3fe444c commit 105a35c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pkg/result/processors/nolint.go
Expand Up @@ -250,14 +250,14 @@ func (p *Nolint) extractInlineRangeFromComment(text string, g ast.Node, fset *to
var linters []string
text = strings.Split(text, "//")[0] // allow another comment after this comment
linterItems := strings.Split(strings.TrimPrefix(text, "nolint:"), ",")
var gotUnknownLinters bool
for _, linter := range linterItems {
linterName := strings.ToLower(strings.TrimSpace(linter))

lcs := p.dbManager.GetLinterConfigs(linterName)
if lcs == nil {
p.unknownLintersSet[linterName] = true
gotUnknownLinters = true
linters = append(linters, linterName)
nolintDebugf("unknown linter %s on line %d", linterName, fset.Position(g.Pos()).Line)
continue
}

Expand All @@ -266,10 +266,6 @@ func (p *Nolint) extractInlineRangeFromComment(text string, g ast.Node, fset *to
}
}

if gotUnknownLinters {
return buildRange(nil) // ignore all linters to not annoy user
}

nolintDebugf("%d: linters are %s", fset.Position(g.Pos()).Line, linters)
return buildRange(linters)
}
Expand Down
6 changes: 6 additions & 0 deletions test/testdata/nolint_apply_to_unknown.go
@@ -0,0 +1,6 @@
//args: -Egofmt
package testdata

func bar() {
_ = 0 //nolint: foobar // ERROR "File is not `gofmt`-ed with `-s`"
}

0 comments on commit 105a35c

Please sign in to comment.