Skip to content

Commit e7e0295

Browse files
authored
ignore build constrained files
1 parent 8a8b062 commit e7e0295

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

main.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ func main() {
167167
if !strings.HasSuffix(file.Name, ".go") {
168168
return nil
169169
}
170+
content, err := file.Contents()
171+
if err != nil {
172+
return err
173+
}
174+
175+
node, err := parser.ParseFile(fset, file.Name, content, parser.ImportsOnly|parser.ParseComments)
176+
if err != nil {
177+
return err
178+
}
179+
180+
for _, cg := range node.Comments {
181+
for _, c := range cg.List {
182+
if strings.HasPrefix(c.Text, "// +build") {
183+
return nil
184+
}
185+
}
186+
}
187+
170188
files = append(files, file)
171189
return nil
172190
}))
@@ -176,13 +194,14 @@ func main() {
176194
for _, file := range files {
177195
content, err := file.Contents()
178196
if err != nil {
179-
panic(err)
197+
die(err)
180198
}
181199

182200
node, err := parser.ParseFile(fset, file.Name, content, parser.ImportsOnly)
183201
if err != nil {
184-
panic(err)
202+
die(err)
185203
}
204+
186205
for _, i := range node.Imports {
187206
// remove quotes
188207
ref := i.Path.Value

0 commit comments

Comments
 (0)