Source file
src/cmd/fix/buildtag.go
1
2
3
4
5 package main
6
7 import (
8 "go/ast"
9 "go/version"
10 "strings"
11 )
12
13 func init() {
14 register(buildtagFix)
15 }
16
17 const buildtagGoVersionCutoff = "go1.18"
18
19 var buildtagFix = fix{
20 name: "buildtag",
21 date: "2021-08-25",
22 f: buildtag,
23 desc: `Remove +build comments from modules using Go 1.18 or later`,
24 }
25
26 func buildtag(f *ast.File) bool {
27 if version.Compare(*goVersion, buildtagGoVersionCutoff) < 0 {
28 return false
29 }
30
31
32
33
34
35
36 fixed := false
37 for _, g := range f.Comments {
38 sawGoBuild := false
39 for i, c := range g.List {
40 if strings.HasPrefix(c.Text, "//go:build ") {
41 sawGoBuild = true
42 }
43 if sawGoBuild && strings.HasPrefix(c.Text, "// +build ") {
44 g.List = g.List[:i]
45 fixed = true
46 break
47 }
48 }
49 }
50
51 return fixed
52 }
53
View as plain text