~samwhited/checkdoc

237519b6f86857a9516936828f12a162f4708556 — Sam Whited 3 months ago 8aeb857
checkdoc: skip generated files in header check

Signed-off-by: Sam Whited <sam@samwhited.com>
1 files changed, 10 insertions(+), 1 deletions(-)

M header.go
M header.go => header.go +10 -1
@@ 20,8 20,12 @@ import (
func fileHeader() *analysis.Analyzer {
	const name = "fileheader"
	flags := flag.NewFlagSet(name, flag.ExitOnError)
	var headerFile string
	var (
		headerFile string
		includeGen bool
	)
	flags.StringVar(&headerFile, "pattern", "", "a file containing a regular expression to match against header comments or - to use stdin")
	flags.BoolVar(&includeGen, "generated", includeGen, "do not skip files containing a code generated header")

	return &analysis.Analyzer{
		Name:  name,


@@ 54,6 58,7 @@ func fileHeader() *analysis.Analyzer {
				return nil, err
			}
		afterparse:
			genExp := regexp.MustCompile(`^Code generated .* DO NOT EDIT\.$`)

			for _, file := range pass.Files {
				switch {


@@ 68,6 73,10 @@ func fileHeader() *analysis.Analyzer {
				case pass.Fset.Position(file.Comments[0].List[0].Slash).Offset != 0:
					pass.Reportf(file.Comments[0].List[0].Slash, "no header comment found at start of file")
					continue
				case genExp.MatchString(file.Comments[0].Text()):
					// Skip generated files.
					// TODO: this can technically appear anywhere in the file.
					continue
				}

				if exp != nil && !exp.MatchString(file.Comments[0].Text()) {