Nogo: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst# =Overview= <code>nogo</code> 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, <code>nogo</code> may report compiler-like errors. It may be used to run the same analyses as <code>vet</code>. The <code>nogo</code> rule will generate a progr...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst#
* https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst#
* https://github.com/bazel-contrib/rules_go/blob/master/go/nogo.rst
=Internal=
* [[Bazel_Concepts#nogo|Bazel Concepts]]
* [[Bazel_BUILD_Files#Build-time_Code_Analysis_with_nogo|<tt>BUILD</tt> Files]]
=Overview=
=Overview=
<code>nogo</code> 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, <code>nogo</code> may report compiler-like errors. It may be used to run the same analyses as <code>[[#vet|vet</code>]]. The <code>nogo</code> [[#nogo_Setup|rule]] will generate a program that executes all the supplied [[#Analyzers|analyzers]] at build-time. The generated <code>nogo</code> program will run alongside the compiler when building any Go target (e.g. <code>go_library</code>) 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.
<code>nogo</code> 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, <code>nogo</code> may report compiler-like errors. It may be used to run the same analyses as <code>[[#vet|vet</code>]]. The <code>nogo</code> [[#nogo_Setup|rule]] will generate a program that executes all the supplied [[#Analyzers|analyzers]] at build-time. The generated <code>nogo</code> program will run alongside the compiler when building any Go target (e.g. <code>go_library</code>) 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.

Latest revision as of 07:07, 23 November 2024

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

https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst#configuring-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

https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst#configuring-analyzers

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"
    }
  },