Nogo
External
Internal
Overview
nogo
is a tool that analyzes source code of Go programs. It runs alongside the Go compiler in the Bazel Go rules and rejects programs that contain disallowing coding patterns. In addition, nogo
may report compiler-like errors. It may be used to run the same analyses as vet
. The nogo
rule will generate a program that executes all the supplied analyzers at build-time. The generated nogo
program will run alongside the compiler when building any Go target (e.g. go_library
) within your workspace, even if the target is imported from an external repository. However, nogo will not run when targets from the current repository are imported into other workspaces and built there.
Analyzers
nogo Setup
To activate nogo
, declare a nogo
target in the BUILD file.
load("@io_bazel_rules_go//go:def.bzl", "nogo")
nogo(
name = "my_nogo",
deps = [
# analyzer from the local repository
":importunsafe",
# analyzer from a remote repository
"@org_golang_x_tools//go/analysis/passes/printf:go_default_library",
],
visibility = ["//visibility:public"], # must have public visibility
)
go_library(
name = "importunsafe",
srcs = ["importunsafe.go"],
importpath = "importunsafe",
deps = ["@org_golang_x_tools//go/analysis:go_default_library"],
visibility = ["//visibility:public"],
)
nogo Configuration
nogo
is configured with a JSON file that specifies analyzers:
{
"structtag": {
"exclude_files": {
"vendor/": "vendor tools don't pass vet",
"external/": "external tools don't pass vet"
}
},
"exhaustive": {
"exclude_files": {
"vendor/": "vendor tools don't pass vet",
"external/": "external tools don't pass vet"
}
},
...
}
To exclude completely all files:
"exhaustive": {
"exclude_files": {
".*": "disable completely"
}
},