From 1d235fb56e3541a42dcee7bd2278cf912302a24b Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sat, 30 Oct 2021 00:10:16 -0700 Subject: [PATCH] buildtags: Format only go:build lines for go 1.18+ (#211) ``` $ ./tmp/testgo161718.sh ./buildtags/ ./printer/ + go1.16.8 test ./buildtags/ ./printer/ ok github.com/mmcloughlin/avo/buildtags 0.001s ok github.com/mmcloughlin/avo/printer 0.002s + go1.17.2 test ./buildtags/ ./printer/ ok github.com/mmcloughlin/avo/buildtags 0.001s ok github.com/mmcloughlin/avo/printer 0.002s + gotip test ./buildtags/ ./printer/ ok github.com/mmcloughlin/avo/buildtags 0.001s ok github.com/mmcloughlin/avo/printer 0.002s ``` Updates #183 --- buildtags/syntax.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildtags/syntax.go b/buildtags/syntax.go index 63995ae9..92583125 100644 --- a/buildtags/syntax.go +++ b/buildtags/syntax.go @@ -33,7 +33,8 @@ func Format(t ConstraintsConvertable) (string, error) { output := "" for scanner.Scan() { line := scanner.Text() - if strings.HasPrefix(line, "//") { + if (PlusBuildSyntaxSupported() && strings.HasPrefix(line, "// +build")) || + (GoBuildSyntaxSupported() && strings.HasPrefix(line, "//go:build")) { output += line + "\n" } }