| 1 | // Copyright 2025 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package gofix defines an analyzer that checks go:fix directives. |
| 6 | package gofix |
| 7 | |
| 8 | import ( |
| 9 | _ "embed" |
| 10 | |
| 11 | "golang.org/x/tools/go/analysis" |
| 12 | "golang.org/x/tools/go/analysis/passes/inspect" |
| 13 | "golang.org/x/tools/go/analysis/passes/internal/gofixdirective" |
| 14 | "golang.org/x/tools/go/ast/inspector" |
| 15 | "golang.org/x/tools/internal/analysis/analyzerutil" |
| 16 | ) |
| 17 | |
| 18 | //go:embed doc.go |
| 19 | var doc string |
| 20 | |
| 21 | var Analyzer = &analysis.Analyzer{ |
| 22 | Name: "gofixdirective", |
| 23 | Doc: analyzerutil.MustExtractDoc(doc, "gofixdirective"), |
| 24 | URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/gofix", |
| 25 | Run: run, |
| 26 | Requires: []*analysis.Analyzer{inspect.Analyzer}, |
| 27 | } |
| 28 | |
| 29 | func run(pass *analysis.Pass) (any, error) { |
| 30 | root := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector).Root() |
| 31 | gofixdirective.Find(pass, root, nil) |
| 32 | return nil, nil |
| 33 | } |