diff --git a/DEPS.bzl b/DEPS.bzl index 79f86585b8572..db09c1f163cbf 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -1513,11 +1513,11 @@ def go_deps(): name = "com_github_kisielk_errcheck", build_file_proto_mode = "disable_global", importpath = "github.com/kisielk/errcheck", - sum = "h1:cErYo+J4SmEjdXZrVXGwLJCE2sB06s23LpkcyWNrT+s=", patch_args = ["-p1"], patches = [ "//build/patches:com_github_kisielk_errcheck.patch", ], + sum = "h1:cErYo+J4SmEjdXZrVXGwLJCE2sB06s23LpkcyWNrT+s=", version = "v1.6.1", ) go_repository( @@ -1801,6 +1801,14 @@ def go_deps(): sum = "h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=", version = "v0.0.0-20200227124842-a10e7caefd8e", ) + go_repository( + name = "com_github_nishanths_predeclared", + build_file_proto_mode = "disable", + importpath = "github.com/nishanths/predeclared", + sum = "h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk=", + version = "v0.2.2", + ) + go_repository( name = "com_github_nxadm_tail", build_file_proto_mode = "disable_global", @@ -2285,6 +2293,14 @@ def go_deps(): sum = "h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=", version = "v1.2.0", ) + go_repository( + name = "com_github_tdakkota_asciicheck", + build_file_proto_mode = "disable", + importpath = "github.com/tdakkota/asciicheck", + sum = "h1:PKzG7JUTUmVspQTDqtkX9eSiLGossXTybutHwTXuO0A=", + version = "v0.1.1", + ) + go_repository( name = "com_github_tiancaiamao_appdash", build_file_proto_mode = "disable_global", diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 40d98545befd6..3b3ceede0cc22 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -120,11 +120,13 @@ nogo( "@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", + "//build/linter/asciicheck:asciicheck", "//build/linter/durationcheck:durationcheck", "//build/linter/exportloopref:exportloopref", "//build/linter/gofmt:gofmt", "//build/linter/ineffassign:ineffassign", "//build/linter/prealloc:prealloc", + "//build/linter/predeclared:predeclared", "//build/linter/unconvert:unconvert", ] + staticcheck_analyzers(STATICHECK_ANALYZERS) + select({ diff --git a/build/linter/asciicheck/BUILD.bazel b/build/linter/asciicheck/BUILD.bazel new file mode 100644 index 0000000000000..8b1346d863744 --- /dev/null +++ b/build/linter/asciicheck/BUILD.bazel @@ -0,0 +1,9 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "asciicheck", + srcs = ["analysis.go"], + importpath = "github.com/pingcap/tidb/build/linter/asciicheck", + visibility = ["//visibility:public"], + deps = ["@com_github_tdakkota_asciicheck//:go_default_library"], +) diff --git a/build/linter/asciicheck/analysis.go b/build/linter/asciicheck/analysis.go new file mode 100644 index 0000000000000..c78c5db3fd066 --- /dev/null +++ b/build/linter/asciicheck/analysis.go @@ -0,0 +1,20 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package asciicheck + +import "github.com/tdakkota/asciicheck" + +// Analyzer is the analyzer struct of asciicheck. +var Analyzer = asciicheck.NewAnalyzer() diff --git a/build/linter/predeclared/BUILD.bazel b/build/linter/predeclared/BUILD.bazel new file mode 100644 index 0000000000000..5efbe386f0f13 --- /dev/null +++ b/build/linter/predeclared/BUILD.bazel @@ -0,0 +1,12 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "predeclared", + srcs = ["analysis.go"], + importpath = "github.com/pingcap/tidb/build/linter/predeclared", + visibility = ["//visibility:public"], + deps = [ + "//build/linter/util", + "@com_github_nishanths_predeclared//passes/predeclared", + ], +) diff --git a/build/linter/predeclared/analysis.go b/build/linter/predeclared/analysis.go new file mode 100644 index 0000000000000..605b631553f24 --- /dev/null +++ b/build/linter/predeclared/analysis.go @@ -0,0 +1,27 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package predeclared + +import ( + "github.com/nishanths/predeclared/passes/predeclared" + "github.com/pingcap/tidb/build/linter/util" +) + +// Analyzer is the analyzer struct of predeclared. +var Analyzer = predeclared.Analyzer + +func init() { + util.SkipAnalyzer(Analyzer) +} diff --git a/build/nogo_config.json b/build/nogo_config.json index 794090c0f6ccc..3b9938e39c8d1 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -1,4 +1,11 @@ { + "asciicheck": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code", + "br/pkg/lightning/web/res_vfsdata.go": "ignore code" + } + }, "asmdecl": { "exclude_files": { "/external/": "no need to vet third party code", @@ -643,5 +650,14 @@ "parser/yy_parser.go": "ignore generated code", "/cgo/": "no need to vet third party code for cgo" } + }, + "predeclared": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code", + "parser/yy_parser.go": "ignore generated code", + "parser/parser.go": "ignore generated code", + "/cgo/": "no need to vet third party code for cgo" + } } } diff --git a/go.mod b/go.mod index 9e8222fb8275b..17d8a6f3938d4 100644 --- a/go.mod +++ b/go.mod @@ -103,6 +103,8 @@ require ( github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 github.com/kisielk/errcheck v1.6.1 github.com/kyoh86/exportloopref v0.1.8 + github.com/nishanths/predeclared v0.2.2 + github.com/tdakkota/asciicheck v0.1.1 honnef.co/go/tools v0.0.1-2020.1.4 ) diff --git a/go.sum b/go.sum index 5a10ed780c146..a002b3c67bdc7 100644 --- a/go.sum +++ b/go.sum @@ -602,6 +602,8 @@ github.com/ngaut/pools v0.0.0-20180318154953-b7bc8c42aac7/go.mod h1:iWMfgwqYW+e8 github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef h1:K0Fn+DoFqNqktdZtdV3bPQ/0cuYh2H4rkg0tytX/07k= github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef/go.mod h1:7WjlapSfwQyo6LNmIvEWzsW1hbBQfpUO4JWnuQRmva8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= +github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -772,6 +774,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2-0.20220504104629-106ec21d14df h1:rh3VYpfvzXRbJ90ymx1yfhGl/wq8ac2m/cUbao61kwY= github.com/stretchr/testify v1.7.2-0.20220504104629-106ec21d14df/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tdakkota/asciicheck v0.1.1 h1:PKzG7JUTUmVspQTDqtkX9eSiLGossXTybutHwTXuO0A= +github.com/tdakkota/asciicheck v0.1.1/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= github.com/tikv/client-go/v2 v2.0.1-0.20220627063500-947d923945fd h1:VAyYcN1Nw7RupQszUYqOkueEVapWSxKFU7uBaYY5Dv8= @@ -1205,6 +1209,7 @@ golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200414032229-332987a829c3/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/store/driver/error/error.go b/store/driver/error/error.go index 6b7b444239d9c..1d9543cc1437d 100644 --- a/store/driver/error/error.go +++ b/store/driver/error/error.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package error //nolint:predeclared +package error //nolint: predeclared import ( stderrs "errors" diff --git a/store/driver/error/error_test.go b/store/driver/error/error_test.go index a8c2c6ddc9152..dde341e8da4f1 100644 --- a/store/driver/error/error_test.go +++ b/store/driver/error/error_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package error //nolint:predeclared +package error //nolint: predeclared import ( "testing"