pkg/result/processors: compile nolint regexp only once (#2463)

This commit is contained in:
Iskander (Alex) Sharipov 2022-01-06 20:10:42 +03:00 committed by GitHub
parent eaed228d2f
commit 29eedbf6e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import (
)
var nolintDebugf = logutils.Debug("nolint")
var nolintRe = regexp.MustCompile(`^nolint( |:|$)`)
type ignoredRange struct {
linters []string
@ -234,7 +235,7 @@ func (p *Nolint) extractFileCommentsInlineRanges(fset *token.FileSet, comments .
func (p *Nolint) extractInlineRangeFromComment(text string, g ast.Node, fset *token.FileSet) *ignoredRange {
text = strings.TrimLeft(text, "/ ")
if ok, _ := regexp.MatchString(`^nolint( |:|$)`, text); !ok {
if !nolintRe.MatchString(text) {
return nil
}