Documentation ¶
Overview ¶
Package gofmt provides an analyzer which checks that files have been run through gofmt.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Analyzer = &analysis.Analyzer{ Name: "gofmt", Doc: "checks if files have been run through `gofmt -s`", Run: func(pass *analysis.Pass) (any, error) { files := map[string]token.Pos{} for _, f := range pass.Files { fileName := pass.Fset.PositionFor(f.Pos(), true).Filename ext := filepath.Ext(fileName) if ext != "" && ext != ".go" { fileName = pass.Fset.PositionFor(f.Pos(), false).Filename } files[fileName] = f.Pos() } for f, pos := range files { diff, err := gofmt.RunRewrite(f, true, nil) if err != nil { return nil, errors.Wrap(err, "gofmt.RunRewrite") } if len(diff) > 0 { pass.Report(analysis.Diagnostic{ Pos: pos, Message: "not formatted with gofmt -s:\n" + string(diff), }) } } return nil, nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.