RFC: build/analysis: add commentwrap
This adds a Go analyzer which limits the length of comment lines to 80
characters.
Rationale:
Monogon currently follows gofmt style. Gofmt in itself is already quite
opinionated, but one thing it explicitly does not check for is maximum
line length.
This implements a limit for the maximum length of a comment line in Go
source within Monogon. It explicitly does not limit code line length, as
these can be handled much more easily by soft reflows.
The tool used, github.com/corverroos/commentwrap, will now be
automatically ran by our nogo pass, and prevent any line of commnets
within Go to be longer than 80 characters, with the exception of:
- cgo/generate directives
- TODOs
- indented comments (eg. sample code or long URLs)
Downsides:
1. We have to reformat the entire codebase. CR/67 does this.
2. We end up with a bulk Git commit that will pollute Git history. A
followup CR attempts to resolve this by using Git's ignoreRevsFile
functionality.
3. There's currently no integration with IntelliJ and no way to
automatically reformat code. If this RFC gets approved, a follow up
CR will be created that adds integration/automation to make this
easier to work against.
Open questions:
1. Is 80 characters the right limit? I, personally, quite like it, but
am willing to compromise on line length.
Change-Id: I063d64596ca5ef038a8426c6b9f806b65c18451e
Reviewed-on: https://review.monogon.dev/c/monogon/+/66
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/build/analysis/BUILD.bazel b/build/analysis/BUILD.bazel
index edaefbe..621e30b 100644
--- a/build/analysis/BUILD.bazel
+++ b/build/analysis/BUILD.bazel
@@ -33,5 +33,13 @@
name = "nogo",
config = "nogo_config.json",
visibility = ["//visibility:public"],
- deps = govet,
+ deps = govet + [
+ # This analyzer ensures that all comment lines are <= 80 characters long
+ # in Go source. This is in line with general practices around the Go
+ # community, where code lines can be as long as needed (and is expected
+ # to be soft-reflowable by text editors), but comments are kept at a
+ # 'standard' 80 characters long, as prose within comment blocks does not
+ # soft-reflow well.
+ "@com_github_corverroos_commentwrap//:go_tool_library",
+ ],
)
diff --git a/build/analysis/nogo_config.json b/build/analysis/nogo_config.json
index c13baaf..ae01f0a 100644
--- a/build/analysis/nogo_config.json
+++ b/build/analysis/nogo_config.json
@@ -88,5 +88,11 @@
"external/com_github_google_gvisor/": "third_party",
"external/com_github_sbezverk_nfproxy/": "third_party"
}
+ },
+ "commentwrap": {
+ "exclude_files": {
+ "dev_source_monogon/": "temporary until fixup CR",
+ "external/": "third_party"
+ }
}
}