Skip to content

Commit

Permalink
*: enable nogo to use fast incremental linter (#35344)
Browse files Browse the repository at this point in the history
ref #35345
  • Loading branch information
hawkingrei authored Jun 17, 2022
1 parent 712e51a commit 566a215
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/licenserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ header:
- '**/*.result'
- '**/*.example'
- '**/*.patch'
- 'DEPS.bzl'
- '**/*.bzl'
- '.codecov.yml'
- 'Jenkinsfile'
- '.editorconfig'
Expand Down
10 changes: 8 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ http_archive(
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

load("//:DEPS.bzl", "go_deps")
load("//build:lint.bzl", "nogo_deps")

# gazelle:repository_macro DEPS.bzl%go_deps
go_deps()

nogo_deps()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

go_rules_dependencies()

go_register_toolchains(version = "1.18.3")
go_register_toolchains(
nogo = "@//build:tidb_nogo",
version = "1.18.3",
)

gazelle_dependencies()

Expand Down
50 changes: 46 additions & 4 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "all_patches",
srcs = glob(["*.patch"]),
visibility = ["//visibility:public"],
load("@io_bazel_rules_go//go:def.bzl", "nogo")

nogo(
name = "tidb_nogo",
config = ":nogo_config.json",
visibility = ["//visibility:public"], # must have public visibility
deps = [
# https://github.com/golang/go/issues/48525
# "@com_github_timakin_bodyclose//passes/bodyclose:go_default_library",
"@org_golang_x_tools//go/analysis/passes/asmdecl:go_default_library",
"@org_golang_x_tools//go/analysis/passes/assign:go_default_library",
"@org_golang_x_tools//go/analysis/passes/atomic:go_default_library",
"@org_golang_x_tools//go/analysis/passes/atomicalign:go_default_library",
"@org_golang_x_tools//go/analysis/passes/bools:go_default_library",
# https://github.com/golang/go/issues/48525
# "@org_golang_x_tools//go/analysis/passes/buildssa:go_default_library",
"@org_golang_x_tools//go/analysis/passes/buildtag:go_default_library",
# https://github.com/bazelbuild/rules_go/issues/2396
# "@org_golang_x_tools//go/analysis/passes/cgocall:go_default_library",
"@org_golang_x_tools//go/analysis/passes/composite:go_default_library",
"@org_golang_x_tools//go/analysis/passes/copylock:go_default_library",
"@org_golang_x_tools//go/analysis/passes/ctrlflow:go_default_library",
"@org_golang_x_tools//go/analysis/passes/deepequalerrors:go_default_library",
"@org_golang_x_tools//go/analysis/passes/errorsas:go_default_library",
"@org_golang_x_tools//go/analysis/passes/findcall:go_default_library",
"@org_golang_x_tools//go/analysis/passes/httpresponse:go_default_library",
"@org_golang_x_tools//go/analysis/passes/ifaceassert:go_default_library",
"@org_golang_x_tools//go/analysis/passes/inspect:go_default_library",
"@org_golang_x_tools//go/analysis/passes/loopclosure:go_default_library",
"@org_golang_x_tools//go/analysis/passes/lostcancel:go_default_library",
"@org_golang_x_tools//go/analysis/passes/nilfunc:go_default_library",
#"@org_golang_x_tools//go/analysis/passes/nilness:go_default_library",
"@org_golang_x_tools//go/analysis/passes/pkgfact:go_default_library",
"@org_golang_x_tools//go/analysis/passes/printf:go_default_library",
"@org_golang_x_tools//go/analysis/passes/shift:go_default_library",
"@org_golang_x_tools//go/analysis/passes/sortslice:go_default_library",
"@org_golang_x_tools//go/analysis/passes/stdmethods:go_default_library",
"@org_golang_x_tools//go/analysis/passes/stringintconv:go_default_library",
"@org_golang_x_tools//go/analysis/passes/structtag:go_default_library",
"@org_golang_x_tools//go/analysis/passes/testinggoroutine:go_default_library",
"@org_golang_x_tools//go/analysis/passes/tests:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unmarshal:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unreachable:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unsafeptr:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unusedresult:go_default_library",
],
)
21 changes: 21 additions & 0 deletions build/lint.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@bazel_gazelle//:deps.bzl", "go_repository")

def nogo_deps():
go_repository(
name = "com_github_gostaticanalysis_analysisutil",
importpath = "github.com/gostaticanalysis/analysisutil",
sum = "h1:ZMCjoue3DtDWQ5WyU16YbjbQEQ3VuzwxALrpYd+HeKk=",
version = "v0.7.1",
)
go_repository(
name = "com_github_gostaticanalysis_comment",
importpath = "github.com/gostaticanalysis/comment",
sum = "h1:hlnx5+S2fY9Zo9ePo4AhgYsYHbM2+eAv8m/s1JiCd6Q=",
version = "v1.4.2",
)
go_repository(
name = "com_github_timakin_bodyclose",
importpath = "github.com/timakin/bodyclose",
sum = "h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro=",
version = "v0.0.0-20210704033933-f49887972144",
)
205 changes: 205 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"asmdecl": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"assign": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"atomic": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"atomicalign": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"bodyclose": {
"exclude_files": {
"external/": "no need to vet third party code"
}
},
"bools": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"buildtag": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"printf": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"unreachable": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"composites": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
"br/pkg/glue/console_glue_test.go": "ignore code",
"br/pkg/restore/db_test.go": "ignore code",
".*_/testmain\\.go$": "ignore code"
}
},
"copylocks": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
"/cgo/": "ignore cgo code"
}
},
"ctrlflow": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"deepequalerrors": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"errorsas": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"findcall": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"httpresponse": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"ifaceassert": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"inspect": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"loopclosure": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"lostcancel": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"nilfunc": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"nilness": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"pkgfact": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"shift": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"sortslice": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"stdmethods": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"stringintconv": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"structtag": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"testinggoroutine": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"tests": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"unmarshal": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"unsafeptr": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
"parser/digester.go": "ignore code"
}
},
"unusedresult": {
"exclude_files": {
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
"parser/digester_test.go": "ignore code"
}
}
}

0 comments on commit 566a215

Please sign in to comment.