build/analysis: move nogo configuration

This moves the nogo config JSON file from the root of the repository,
and cleans up the BUILD file in preparation for adding extra, possibly
custom, analyzers.

Change-Id: Id85c9cd8515b9178712329fe425c1e1740f04d8b
Reviewed-on: https://review.monogon.dev/c/monogon/+/65
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/build/analysis/BUILD.bazel b/build/analysis/BUILD.bazel
new file mode 100644
index 0000000..edaefbe
--- /dev/null
+++ b/build/analysis/BUILD.bazel
@@ -0,0 +1,37 @@
+load("@io_bazel_rules_go//go:def.bzl", "nogo")
+
+# These deps enable the analyses equivalent to running `go vet`.
+# Passing vet = True enables only a tiny subset of these (the ones
+# that are always correct).
+# You can see the what `go vet` does by running `go doc cmd/vet`.
+govet = [
+    "@org_golang_x_tools//go/analysis/passes/asmdecl:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/assign:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/atomic:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/bools:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/buildtag:go_tool_library",
+    # Disable cgocall because it fails processing com_github_mattn_go_sqlite3 before exclusions are applied
+    #"@org_golang_x_tools//go/analysis/passes/cgocall:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/composite:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/copylock:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/httpresponse:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/loopclosure:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/lostcancel:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/nilfunc:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/printf:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/shift:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/stdmethods:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/structtag:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/tests:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/unmarshal:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/unreachable:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/unsafeptr:go_tool_library",
+    "@org_golang_x_tools//go/analysis/passes/unusedresult:go_tool_library",
+]
+
+nogo(
+    name = "nogo",
+    config = "nogo_config.json",
+    visibility = ["//visibility:public"],
+    deps = govet,
+)
diff --git a/build/analysis/nogo_config.json b/build/analysis/nogo_config.json
new file mode 100644
index 0000000..c13baaf
--- /dev/null
+++ b/build/analysis/nogo_config.json
@@ -0,0 +1,92 @@
+{
+  "composites": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/bazel_gazelle/language/go/": "third_party",
+      "external/com_github_golang_protobuf/": "third_party",
+      "external/com_github_google_gvisor/": "third_party",
+      "external/io_k8s_apimachinery/pkg/runtime/serializer/versioning/": "third_party",
+      "external/io_k8s_sigs_structured_merge_diff/": "third_party",
+      "external/io_k8s_client_go/": "third_party",
+      "external/io_k8s_kube_openapi/": "third_party",
+      "external/io_k8s_apiserver/": "third_party",
+      "external/org_golang_x_tools/": "third_party",
+      "external/io_k8s_apiextensions_apiserver/": "third_party",
+      "external/org_golang_x_text/": "third_party",
+      "external/io_bazel_rules_docker/": "third_party",
+      "external/com_github_grpc_ecosystem_grpc_opentracing": "third_party"
+    }
+  },
+  "copylocks": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/com_github_google_gvisor/": "third_party",
+      "external/io_k8s_sigs_structured_merge_diff/": "third_party",
+      "external/io_k8s_component_base/": "third_party",
+      "external/io_k8s_apiserver/": "third_party",
+      "external/org_golang_google_protobuf/": "third_party",
+      "external/com_github_armon_go_metrics/": "third_party",
+      "external/com_github_elazarl_goproxy/": "third_party",
+      "external/com_github_googleapis_gnostic/": "third_party"
+    }
+  },
+  "lostcancel": {
+    "exclude_files": {
+      "external/com_github_golang_protobuf/": "third_party",
+      "external/com_github_grpc_ecosystem_grpc_gateway/runtime/": "third_party",
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/com_github_denisenkom_go_mssqldb/": "third_party"
+    }
+  },
+  "unreachable": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/bazel_gazelle/pathtools": "third_party",
+      "external/com_github_magiconair_properties": "third_party",
+      "external/com_github_ghodss_yaml": "third_party",
+      "external/io_k8s_kubectl": "third_party",
+      "external/org_golang_google_protobuf/": "third_party",
+      "external/com_github_shirou_gopsutil/": "unreachable",
+      "external/io_k8s_apimachinery/": "third_party",
+      "external/com_github_hpcloud_tail": "third_party",
+      "external/com_github_flynn_go_shlex": "third_party"
+    }
+  },
+  "assign": {
+    "exclude_files": {
+      "external/bazel_gazelle/walk": "third_party"
+    }
+  },
+  "unsafeptr": {
+    "exclude_files": {
+      "external/com_github_modern_go_reflect2/": "third_party",
+      "sqlite3.*go": "third_party",
+      "external/com_github_google_gvisor/": "third_party",
+      "external/io_k8s_sigs_structured_merge_diff/": "third_party",
+      "external/com_github_go_delve_delve/": "third_party",
+      "external/com_github_mailru_easyjson/jlexer/": "third_party",
+      "external/com_github_cilium_ebpf/": "third_party"
+    }
+  },
+  "unusedresult": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/com_github_docker_spdystream": "third_party",
+      "external/io_k8s_apimachinery/": "third_party"
+    }
+  },
+  "structtag": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/com_github_c9s_goprocinfo/": "third_party"
+    }
+  },
+  "printf": {
+    "exclude_files": {
+      "external/io_k8s_kubernetes/": "third_party",
+      "external/runc/vendor/github.com/vishvananda/netlink": "third_party",
+      "external/com_github_google_gvisor/": "third_party",
+      "external/com_github_sbezverk_nfproxy/": "third_party"
+    }
+  }
+}