directive

Imports

Imports #

"go/ast"
"go/parser"
"go/token"
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = `check Go toolchain directives such as //go:debug

This analyzer checks for problems with known Go toolchain directives
in all Go source files in a package directory, even those excluded by
//go:build constraints, and all non-Go source files too.

For //go:debug (see https://go.dev/doc/godebug), the analyzer checks
that the directives are placed only in Go source files, only above the
package comment, and only in package main or *_test.go files.

Support for other known directives may be added in the future.

This analyzer does not check //go:build, which is handled by the
buildtag analyzer.
`

Structs

checker struct #

type checker struct {
pass *analysis.Pass
filename string
file *ast.File
inHeader bool
}

Functions

checkGoFile function #

func checkGoFile(pass *analysis.Pass, f *ast.File)

checkOtherFile function #

func checkOtherFile(pass *analysis.Pass, filename string) error

comment method #

func (check *checker) comment(pos token.Pos, line string)

newChecker function #

func newChecker(pass *analysis.Pass, filename string, file *ast.File) *checker

nonGoFile method #

func (check *checker) nonGoFile(pos token.Pos, fullText string)

runDirective function #

func runDirective(pass *analysis.Pass) (interface{}, error)

stringsCutPrefix function #

Go 1.20 strings.CutPrefix.

func stringsCutPrefix(s string, prefix string) (after string, found bool)

Generated with Arrow