| 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 | /* |
| 6 | Package gofix defines an Analyzer that checks "//go:fix inline" directives. |
| 7 | See golang.org/x/tools/go/analysis/passes/inline/doc.go for details. |
| 8 | |
| 9 | # Analyzer gofixdirective |
| 10 | |
| 11 | gofixdirective: validate uses of gofix comment directives |
| 12 | |
| 13 | The gofixdirective analyzer checks "//go:fix inline" directives for correctness. |
| 14 | |
| 15 | The proposal https://go.dev/issue/32816 introduces the "//go:fix" directives. |
| 16 | |
| 17 | The analyzer checks for the following issues: |
| 18 | |
| 19 | - A constant definition can be marked for inlining only if it refers to another |
| 20 | named constant. |
| 21 | |
| 22 | //go:fix inline |
| 23 | const ( |
| 24 | a = 1 // error |
| 25 | b = iota // error |
| 26 | c = a // OK |
| 27 | d = math.Pi // OK |
| 28 | ) |
| 29 | |
| 30 | - A type definition can be marked for inlining only if it is an alias. |
| 31 | |
| 32 | //go:fix inline |
| 33 | type ( |
| 34 | T int // error |
| 35 | A = int // OK |
| 36 | ) |
| 37 | |
| 38 | - An alias whose right-hand side contains a non-literal array size |
| 39 | cannot be marked for inlining. |
| 40 | |
| 41 | const two = 2 |
| 42 | |
| 43 | //go:fix inline |
| 44 | type ( |
| 45 | A = []int // OK |
| 46 | B = [1]int // OK |
| 47 | C = [two]int // error |
| 48 | ) |
| 49 | */ |
| 50 | package gofix |