Stephan Renatus 468d2334ea change isGenerated heuristic to match more generated files
As observed in #30, there's tools out there that don't comply 100% with
the referenced golang convention.

With this change, golangci-lint will skip some more of those generated
files.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-05-31 09:15:22 +02:00

59 lines
1.6 KiB
Go

package processors
import (
"go/token"
"path/filepath"
"testing"
"github.com/golangci/golangci-lint/pkg/result"
)
func newNolintFileIssue(line int, fromLinter string) result.Issue {
return result.Issue{
Pos: token.Position{
Filename: filepath.Join("testdata", "nolint.go"),
Line: line,
},
FromLinter: fromLinter,
}
}
func TestNolint(t *testing.T) {
p := NewNolint(token.NewFileSet())
processAssertEmpty(t, p, newNolintFileIssue(3, "gofmt"))
processAssertEmpty(t, p, newNolintFileIssue(3, "gofmt")) // check cached is ok
processAssertSame(t, p, newNolintFileIssue(3, "gofmtA")) // check different name
processAssertEmpty(t, p, newNolintFileIssue(4, "gofmt"))
processAssertSame(t, p, newNolintFileIssue(4, "gofmtA")) // check different name
processAssertEmpty(t, p, newNolintFileIssue(5, "gofmt"))
processAssertEmpty(t, p, newNolintFileIssue(5, "govet"))
processAssertSame(t, p, newNolintFileIssue(5, "gofmtA")) // check different name
processAssertEmpty(t, p, newNolintFileIssue(6, "any"))
processAssertEmpty(t, p, newNolintFileIssue(7, "any"))
processAssertSame(t, p, newNolintFileIssue(1, "golint")) // no directive
}
func TestNoIssuesInAutogeneratedFiles(t *testing.T) {
files := []string{
"nolint_autogenerated.go",
"nolint_autogenerated_alt_hdr.go",
"nolint_autogenerated_alt_hdr2.go",
}
for _, file := range files {
t.Run(file, func(t *testing.T) {
i := result.Issue{
Pos: token.Position{
Filename: filepath.Join("testdata", file),
Line: 4,
},
}
p := NewNolint(token.NewFileSet())
processAssertEmpty(t, p, i)
})
}
}