build/analysis/importsort: init
This adds an analyzer which enforces import sorting as per
CODING_STANDARDS.md. It is not yet enabled in nogo.
This effectively duplicates some logic that is present in goimports.
However, that logic is mostly within an 'internal' package in x/tools,
and would be somewhat tricky to make work within the framework of an
analysis.Analyser (as it expects to also mutate a file). Thus, we
end up writing the analysis logic ourselves. Tests are provided to make
sure this logic doesn't rot away.
We also move some common logic from 'noioutil' to a new 'lib' package,
and implement the last piece of the puzzle there: a code generator to
provide information about the toolchain's stdlib as a map/set.
Change-Id: Ia0f32d6f9122e13117d18ae781d8255c6e3a887d
Reviewed-on: https://review.monogon.dev/c/monogon/+/494
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/build/analysis/importsort/BUILD.bazel b/build/analysis/importsort/BUILD.bazel
new file mode 100644
index 0000000..309edfb
--- /dev/null
+++ b/build/analysis/importsort/BUILD.bazel
@@ -0,0 +1,38 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
+ name = "go_default_library",
+ srcs = [
+ "classify.go",
+ "importsort.go",
+ ],
+ importpath = "source.monogon.dev/build/analysis/importsort",
+ visibility = ["//visibility:public"],
+ deps = [
+ "//build/analysis/lib:go_default_library",
+ "@org_golang_x_tools//go/analysis:go_default_library",
+ ],
+)
+
+go_test(
+ name = "go_default_test",
+ srcs = ["importsort_test.go"],
+ data = glob(["testdata/**"]),
+ embed = [":go_default_library"],
+ embedsrcs = [
+ "testdata/README.md",
+ "testdata/example.com/extlib/extlib.notgo",
+ "testdata/example.com/extlib/foo/foo.notgo",
+ "testdata/source.monogon.dev/dut/mixed_in_group.notgo",
+ "testdata/source.monogon.dev/dut/okay.notgo",
+ "testdata/source.monogon.dev/dut/unsorted_group.notgo",
+ "testdata/source.monogon.dev/dut/wrong_group_order.notgo",
+ "testdata/source.monogon.dev/lib/lib.notgo",
+ "testdata/source.monogon.dev/project/a/a.notgo",
+ "testdata/source.monogon.dev/project/b/b.notgo",
+ ],
+ deps = [
+ "//build/toolbase/gotoolchain:go_default_library",
+ "@org_golang_x_tools//go/analysis/analysistest:go_default_library",
+ ],
+)