findDirective searches a comment group for a line matching re and returns the first capture group (typically the directive payload) along with the comment's source line number. Returns "" when no comment matches.
(group *ast.CommentGroup, fset *token.FileSet, re *regexp.Regexp)
| 12 | // first capture group (typically the directive payload) along with the comment's |
| 13 | // source line number. Returns "" when no comment matches. |
| 14 | func findDirective(group *ast.CommentGroup, fset *token.FileSet, re *regexp.Regexp) (string, int) { |
| 15 | if group == nil { |
| 16 | return "", 0 |
| 17 | } |
| 18 | for _, comment := range group.List { |
| 19 | if matches := re.FindStringSubmatch(comment.Text); matches != nil { |
| 20 | return strings.TrimSpace(matches[1]), fset.Position(comment.Pos()).Line |
| 21 | } |
| 22 | } |
| 23 | return "", 0 |
| 24 | } |
| 25 | |
| 26 | // extractNodeSource returns the verbatim source text covered by node in src. |
| 27 | func extractNodeSource(src []byte, fset *token.FileSet, node ast.Node) string { |
no outgoing calls
no test coverage detected