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/third_party/go/patches/reflow-tool-library.patch b/third_party/go/patches/reflow-tool-library.patch
new file mode 100644
index 0000000..dcee286
--- /dev/null
+++ b/third_party/go/patches/reflow-tool-library.patch
@@ -0,0 +1,37 @@
+Copyright 2021 The Monogon Project Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+This adds a go_tool_library target to github.com/muesli/reflow. This can
+be removed when go_tool_library gets replaced with transition:
+https://github.com/bazelbuild/rules_go/issues/2374
+
+diff -ur a/BUILD.bazel b/BUILD.bazel
+--- a/BUILD.bazel 2021-05-21 14:36:39.411306726 +0200
++++ b/BUILD.bazel 2021-05-21 14:37:02.602460127 +0200
+@@ -1,4 +1,14 @@
+-load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
++load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "go_tool_library")
++
++go_tool_library(
++ name = "go_tool_library",
++ srcs = [
++ "ansibuffer.go",
++ "reflow.go",
++ ],
++ importpath = "github.com/muesli/reflow",
++ visibility = ["//visibility:public"],
++)
+
+ go_library(
+ name = "go_default_library",