-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes list of checks and check overrides.
- Loading branch information
Showing
15 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copied part from the repo root. | ||
# | ||
test --test_output=errors | ||
test --test_verbose_timeout_warnings | ||
# BuildBuddy config | ||
build:workflows --config=buildbuddy_bes_backend | ||
build:workflows --config=buildbuddy_bes_results_url | ||
build:workflows --config=buildbuddy_remote_cache | ||
## TODO: remove this once BuildBuddy folks confirmed that | ||
## the bug has been fixed on their end regarding command is | ||
## not publicly displayed. | ||
build:workflows --build_metadata=VISIBILITY=PUBLIC | ||
test:workflows --keep_going |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
load("@bazel_gazelle//:def.bzl", "gazelle") | ||
load("@com_github_sluongng_nogo_analyzer//staticcheck:def.bzl", "staticcheck_analyzers") | ||
load("@com_github_sluongng_nogo_analyzer//:def.bzl", "nogo_config") | ||
load("@io_bazel_rules_go//go:def.bzl", "TOOLS_NOGO", "nogo") | ||
load(":staticcheck.bzl", "STATICCHECK_ANALYZERS", "STATICCHECK_OVERRIDE") | ||
|
||
# gazelle:prefix github.com/sluongng/nogo-analyzer/examples/staticcheck | ||
gazelle(name = "gazelle") | ||
|
||
gazelle( | ||
name = "deps", | ||
args = [ | ||
"-from_file=go.mod", | ||
"-to_macro=go_deps.bzl%go_deps", | ||
"-prune", | ||
], | ||
command = "update-repos", | ||
) | ||
|
||
nogo_config( | ||
name = "nogo_config", | ||
out = "nogo_config.json", | ||
analyzers = STATICCHECK_ANALYZERS, | ||
override = STATICCHECK_OVERRIDE, | ||
) | ||
|
||
nogo( | ||
name = "nogo", | ||
config = ":nogo_config.json", | ||
visibility = ["//visibility:public"], | ||
deps = staticcheck_analyzers(STATICCHECK_ANALYZERS), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Nogo/staticcheck example. | ||
|
||
This example setup includes initial nogo configuration with sevral checks and | ||
check overrides. | ||
|
||
Targets: | ||
* `bazel build //cmd/pass` built without errors. | ||
* `bazel build //cmd/failed` fails with the following errors: | ||
|
||
``` | ||
compilepkg: nogo: errors found by nogo during build-time code analysis: | ||
cmd/failed/main.go:8:20: parsing time "01-01-2023" as "01-01-2023": cannot parse "" as "3" (SA1002) | ||
cmd/failed/main.go:10:14: sleeping for 1 nanoseconds is probably a bug; be explicit if it isn't (SA1004) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
workspace(name = "examples_staticcheck") | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
# http_archive( | ||
# name = "com_github_sluongng_nogo_analyzer", | ||
# sha256 = "a74a5e44751d292d17bd879e5aa8b40baa94b5dc2f043df1e3acbb3e23ead073", | ||
# strip_prefix = "nogo-analyzer-0.0.2", | ||
# urls = [ | ||
# "https://github.com/sluongng/nogo-analyzer/archive/refs/tags/v0.0.2.tar.gz", | ||
# ], | ||
# ) | ||
|
||
# for dev usage only, see an example above for external usage. | ||
local_repository( | ||
name = "com_github_sluongng_nogo_analyzer", | ||
path = "../..", | ||
) | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
sha256 = "91585017debb61982f7054c9688857a2ad1fd823fc3f9cb05048b0025c47d023", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.42.0/rules_go-v0.42.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.42.0/rules_go-v0.42.0.zip", | ||
], | ||
) | ||
|
||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
||
go_rules_dependencies() | ||
|
||
go_register_toolchains( | ||
nogo = "@//:nogo", | ||
version = "1.21.4", | ||
) | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "b7387f72efb59f876e4daae42f1d3912d0d45563eac7cb23d1de0b094ab588cf", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
load("//:go_deps.bzl", "go_deps") | ||
|
||
# gazelle:repository_macro go_deps.bzl%go_deps | ||
go_deps() | ||
|
||
load("@com_github_sluongng_nogo_analyzer//staticcheck:deps.bzl", "staticcheck") | ||
|
||
staticcheck() | ||
|
||
gazelle_dependencies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
# fails with an error: | ||
# | ||
# compilepkg: nogo: errors found by nogo during build-time code analysis: | ||
# cmd/failed/main.go:8:20: parsing time "01-01-2023" as "01-01-2023": cannot parse "" as "3" (SA1002) | ||
# cmd/failed/main.go:10:14: sleeping for 1 nanoseconds is probably a bug; be explicit if it isn't (SA1004) | ||
# | ||
# Check SA4013 is excluded | ||
go_library( | ||
name = "failed_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/sluongng/nogo-analyzer/examples/staticcheck/cmd/failed", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
go_binary( | ||
name = "failed", | ||
embed = [":failed_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func main() { | ||
_, _ = time.Parse("01-01-2023", "2023-01-01") | ||
if !!true { | ||
time.Sleep(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "pass_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/sluongng/nogo-analyzer/examples/staticcheck/cmd/pass", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
go_binary( | ||
name = "pass", | ||
embed = [":pass_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
d, err := time.Parse("01-02-2006", "01-01-2023") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("date: %s\n", d) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load("@bazel_gazelle//:deps.bzl", "go_repository") | ||
|
||
def go_deps(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
SA1 = [ | ||
"SA1002", # Invalid format in time.Parse | ||
"SA1004", # Suspiciously small untyped constant in time.Sleep | ||
] | ||
|
||
SA4 = [ | ||
"SA4013", # Negating a boolean twice (!!b) is the same as writing b. This is either redundant, or a typo. | ||
] | ||
|
||
STATICCHECK_ANALYZERS = SA1 + SA4 | ||
|
||
STATICCHECK_OVERRIDE = { | ||
"SA4013": { | ||
"exclude_files": { | ||
"/": "excluded", | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test") | ||
|
||
go_bazel_test( | ||
name = "tests", | ||
size = "medium", | ||
srcs = ["staticcheck_test.go"], | ||
rule_files = [ | ||
"@com_github_sluongng_nogo_analyzer//:all_files", | ||
"@io_bazel_rules_go//:all_files", | ||
"@bazel_gazelle//:all_files", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
testonly = True, | ||
srcs = [ | ||
"BUILD.bazel", | ||
"staticcheck_test.go", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.