Skip to content

Commit

Permalink
bazel: perform staticcheck checks in nogo
Browse files Browse the repository at this point in the history
Add a new binary `generate-staticcheck`, part of `dev generate bazel`,
that creates a package in `build/bazelutil/staticcheckanalyzers`
capturing a single `staticcheck` check. Then we capture the list of
analyzers in `build/bazelutil/staticcheckanalyzers/def.bzl` and add all
those checks to `nogo`.

However, we can't directly use the `Analyzer`s provided by the upstream
library, because they report *all* violations regardless of
`lint:ignore` directives. In order to address this we add a helper
library at `pkg/testutils/lint/passes/staticcheck` that munges the
`Analyzer`s to additionally pull the `lint:ignore` directives and ignore
any reported diagnostics that correspond to a `lint:ignore`.

This follows the example set by https://github.com/sluongng/staticcheck-codegen,
but we don't directly use that code, since we need to inject our own
stuff and we want to make sure the content here is pinned to the right
version of `staticcheck`.

We run the `staticcheck` and `simple` [checks](https://staticcheck.io/docs/checks).
`stylecheck` is still broken: cockroachdb#73568

Closes cockroachdb#68496.

Release note: None
  • Loading branch information
rickystewart committed Dec 9, 2021
1 parent 3bed3a6 commit 95ec124
Show file tree
Hide file tree
Showing 252 changed files with 6,085 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
/pkg/cmd/generate-metadata-tables/ @cockroachdb/sql-experience
/pkg/cmd/generate-spatial-ref-sys/ @cockroachdb/geospatial
/pkg/cmd/generate-test-suites/ @cockroachdb/dev-inf
/pkg/cmd/generate-staticcheck/ @cockroachdb/dev-inf
/pkg/cmd/geoviz/ @cockroachdb/geospatial
/pkg/cmd/github-post/ @cockroachdb/test-eng
/pkg/cmd/github-pull-request-make/ @cockroachdb/dev-inf
Expand Down
3 changes: 2 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports_files([

load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
load("//build/bazelutil/staticcheckanalyzers:def.bzl", "STATICCHECK_CHECKS")

# The following directives inform gazelle how to auto-generate BUILD.bazel
# files throughout the repo. By including them here, we can run gazelle using
Expand Down Expand Up @@ -248,5 +249,5 @@ nogo(
"//pkg/testutils/lint/passes/returnerrcheck",
"//pkg/testutils/lint/passes/timer",
"//pkg/testutils/lint/passes/unconvert",
],
] + STATICCHECK_CHECKS,
)
1 change: 1 addition & 0 deletions build/bazelutil/bazel-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -euo pipefail

CONTENTS=$(bazel run //pkg/cmd/mirror)
echo "$CONTENTS" > DEPS.bzl
bazel run pkg/cmd/generate-staticcheck --run_under="cd $PWD && "
bazel run //:gazelle
CONTENTS=$(bazel run //pkg/cmd/generate-test-suites --run_under="cd $PWD && ")
echo "$CONTENTS" > pkg/BUILD.bazel
Loading

0 comments on commit 95ec124

Please sign in to comment.