commentwrap: ignore lines with URIs in them
Change-Id: Iad0234ff59d74845bda35213deecf9719439d1aa
Reviewed-on: https://review.monogon.dev/c/monogon/+/1105
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/third_party/go/patches/commentwrap-uri.patch b/third_party/go/patches/commentwrap-uri.patch
new file mode 100644
index 0000000..634efe7
--- /dev/null
+++ b/third_party/go/patches/commentwrap-uri.patch
@@ -0,0 +1,31 @@
+Ask commentwrap to ignore lines that contain HTTP URIs.
+Wrapping URLs is not useful and makes them not clicky in editors.
+
+---
+diff --git a/commentwrap.go b/commentwrap.go
+index a1e8c00..5491064 100644
+--- a/commentwrap.go
++++ b/commentwrap.go
+@@ -86,6 +86,10 @@ func mustFlow(g *ast.CommentGroup, limit int) bool {
+ if strings.HasPrefix(comment.Text, "/*") {
+ return false
+ }
++ // Ignore lines that are URIs.
++ if isURI(comment.Text) {
++ continue
++ }
+ if len(comment.Text) > limit {
+ exceed = true
+ }
+@@ -156,6 +160,11 @@ func isDirective(line string) bool {
+ return strings.HasPrefix(line, "go:") || strings.HasPrefix(line, "line:")
+ }
+
++// isURI returns true if the line contains an HTTP URI.
++func isURI(line string) bool {
++ return strings.Contains(line, "http://") || strings.Contains(line, "https://")
++}
++
+ var notes = []string{"TODO", "BUG", "FIXME", "OPTIMIZE"}
+
+ // isNote returns true if the unescaped comment is a note: TODO, BUG, FIXME, OPTIMIZE.
diff --git a/third_party/go/repositories.bzl b/third_party/go/repositories.bzl
index c8654fe..85d8e56 100644
--- a/third_party/go/repositories.bzl
+++ b/third_party/go/repositories.bzl
@@ -1051,6 +1051,10 @@
go_repository(
name = "com_github_corverroos_commentwrap",
importpath = "github.com/corverroos/commentwrap",
+ patch_args = ["-p1"],
+ patches = [
+ "//third_party/go/patches:commentwrap-uri.patch",
+ ],
sum = "h1:toeMwwechJKH0iwOoGJLZK6x42Ba9si+816KxqmgFc8=",
version = "v0.0.0-20191204065359-2926638be44c",
)