Leopold | 506b886 | 2023-01-31 14:54:13 +0100 | [diff] [blame] | 1 | Ask commentwrap to ignore lines that contain HTTP URIs. |
| 2 | Wrapping URLs is not useful and makes them not clicky in editors. |
| 3 | |
| 4 | --- |
| 5 | diff --git a/commentwrap.go b/commentwrap.go |
| 6 | index a1e8c00..5491064 100644 |
| 7 | --- a/commentwrap.go |
| 8 | +++ b/commentwrap.go |
| 9 | @@ -86,6 +86,10 @@ func mustFlow(g *ast.CommentGroup, limit int) bool { |
| 10 | if strings.HasPrefix(comment.Text, "/*") { |
| 11 | return false |
| 12 | } |
| 13 | + // Ignore lines that are URIs. |
| 14 | + if isURI(comment.Text) { |
| 15 | + continue |
| 16 | + } |
| 17 | if len(comment.Text) > limit { |
| 18 | exceed = true |
| 19 | } |
| 20 | @@ -156,6 +160,11 @@ func isDirective(line string) bool { |
| 21 | return strings.HasPrefix(line, "go:") || strings.HasPrefix(line, "line:") |
| 22 | } |
| 23 | |
| 24 | +// isURI returns true if the line contains an HTTP URI. |
| 25 | +func isURI(line string) bool { |
| 26 | + return strings.Contains(line, "http://") || strings.Contains(line, "https://") |
| 27 | +} |
| 28 | + |
| 29 | var notes = []string{"TODO", "BUG", "FIXME", "OPTIMIZE"} |
| 30 | |
| 31 | // isNote returns true if the unescaped comment is a note: TODO, BUG, FIXME, OPTIMIZE. |