Skip to content

Commit

Permalink
*: support predeclared and asciicheck (#35895)
Browse files Browse the repository at this point in the history
ref #35345
  • Loading branch information
hawkingrei committed Jul 3, 2022
1 parent e00ad2b commit 57ff144
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 3 deletions.
18 changes: 17 additions & 1 deletion DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 9 additions & 0 deletions build/linter/asciicheck/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
20 changes: 20 additions & 0 deletions build/linter/asciicheck/analysis.go
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions build/linter/predeclared/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
27 changes: 27 additions & 0 deletions build/linter/predeclared/analysis.go
Original file line number Diff line number Diff line change
@@ -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)
}
16 changes: 16 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion store/driver/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion store/driver/error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 57ff144

Please sign in to comment.