Denis Isaev b31cfd6c78
update go-critic
$ git cherry --abbrev -v 0af0999fabfb ee9bf5809ead
+ abd8436 all: enable Go modules on CI (#753)
+ 3c9d0fb checkers: recognize //line and //nolint in commentFormatting (#756)
+ 0b517d7 checkers: extend deprecatedComment patterns (#757)
+ 09100f6 checkers: use astcast package instead of coerce.go (#758)
+ 2e9e97f checker: simplify boolExprSimplify (#759)
+ 575701e make: add go-consistent to CI checks list (#761)
+ b55f431 checkers: fix unlambda handling of builtins (#763)
+ 5a7dee3 checker: handle lambdas properly in boolExprSimplify (#765)
+ 5ce3939 checkers: teach boolExprSimplify a few new tricks (#766)
+ 04d160f checkers: add new patterns to boolExprSimplify (#768)
+ 09582e2 make: collect coverprofile separately from goveralls (#769)
+ d8d0ee4 checkers: recognize NOTE pattern in deprecatedComment (#770)
+ 12f0f85 Update copyright notice to 2019 (#771)
+ f54bdb6 checkers: add stringXbytes checker
+ 170d65c checkers: followup for #773 (#774)
+ 84e9e83 checkers: make stringXbytes more linear (#775)
+ a800815 checkers: add Depreacted typo pattern (#776)
+ 6751be9 checkers: add hexLiterals (#772)
+ ac61906 checkers: add typeAssertChain checker (#782)
+ d19dbf1 checkers: add codegenComment checker (#783)
+ d82b576 checkers: proper pkg/obj check for flagName (#786)
+ dfcf754 ci: enable integration tests (#787)
+ 5dafc45 checkers: fix equalFold false positive (#788)
+ ed5e8e7 checkers: refactor and fix hexLiteral checker (#789)
+ e704e07 checkers: add argOrder checker (#790)
+ 34c1dc8 checkers: add Split handling to argOrder checker (#791)
+ cbe095d checkers: add math.Max and math.Min to dupArg (#792)
+ c986ee5 checkers: add checkers info fields test (#794)
+ 66e5832 cmd/makedocs: use lintpack, fix build (#793)
+ 6bce9d0 cmd/makedocs: add enabled/disabled by default info (#795)
+ 4adbf9a checkers: simplify flagName (#799)
+ 07de34a checkers: add octalLiteral checker (#798)
+ 765907a cmd/makedocs: add checker param docs (#796)
+ ee9bf58 cmd/makedocs: fix headers formatting (#803)
2019-02-11 09:35:41 +03:00

62 lines
1.6 KiB
Go

package checkers
import (
"go/ast"
"regexp"
"strings"
"github.com/go-lintpack/lintpack"
"github.com/go-lintpack/lintpack/astwalk"
)
func init() {
var info lintpack.CheckerInfo
info.Name = "codegenComment"
info.Tags = []string{"diagnostic", "experimental"}
info.Summary = "Detects malformed 'code generated' file comments"
info.Before = `// This file was automatically generated by foogen`
info.After = `// Code generated by foogen. DO NOT EDIT.`
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
patterns := []string{
"this (?:file|code) (?:was|is) auto(?:matically)? generated",
"this (?:file|code) (?:was|is) generated automatically",
"this (?:file|code) (?:was|is) generated by",
"this (?:file|code) (?:was|is) (?:auto(?:matically)? )?generated",
"this (?:file|code) (?:was|is) generated",
"code in this file (?:was|is) auto(?:matically)? generated",
"generated (?:file|code) - do not edit",
// TODO(Quasilyte): more of these.
}
re := regexp.MustCompile("(?i)" + strings.Join(patterns, "|"))
return &codegenCommentChecker{
ctx: ctx,
badCommentRE: re,
}
})
}
type codegenCommentChecker struct {
astwalk.WalkHandler
ctx *lintpack.CheckerContext
badCommentRE *regexp.Regexp
}
func (c *codegenCommentChecker) WalkFile(f *ast.File) {
if f.Doc == nil {
return
}
for _, comment := range f.Doc.List {
if c.badCommentRE.MatchString(comment.Text) {
c.warn(comment)
return
}
}
}
func (c *codegenCommentChecker) warn(cause ast.Node) {
c.ctx.Warn(cause, "comment should match `Code generated .* DO NOT EDIT.` regexp")
}