From 079a18cba6e42b14e5d42a30c1f76655046c5784 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 00:02:38 +0800 Subject: [PATCH 1/5] *: enable durationcheck Signed-off-by: Weizhen Wang --- DEPS.bzl | 8 ++++++++ br/pkg/lightning/BUILD.bazel | 1 + br/pkg/lightning/errormanager/BUILD.bazel | 1 + build/BUILD.bazel | 1 + build/linter/durationcheck/BUILD.bazel | 9 +++++++++ build/linter/durationcheck/analyzer.go | 22 ++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ kv/BUILD.bazel | 1 + session/BUILD.bazel | 1 + session/session_test/BUILD.bazel | 2 ++ sessionctx/sessionstates/BUILD.bazel | 2 ++ util/set/BUILD.bazel | 2 ++ 13 files changed, 53 insertions(+) create mode 100644 build/linter/durationcheck/BUILD.bazel create mode 100644 build/linter/durationcheck/analyzer.go diff --git a/DEPS.bzl b/DEPS.bzl index c9625069192e7..b41d46497f96d 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -220,6 +220,14 @@ def go_deps(): sum = "h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=", version = "v2.1.2", ) + go_repository( + name = "com_github_charithe_durationcheck", + build_file_proto_mode = "disable", + importpath = "github.com/charithe/durationcheck", + sum = "h1:mPP4ucLrf/rKZiIG/a9IPXHGlh8p4CzgpyTy6EEutYk=", + version = "v0.0.9", + ) + go_repository( name = "com_github_cheggaaa_pb_v3", build_file_proto_mode = "disable_global", diff --git a/br/pkg/lightning/BUILD.bazel b/br/pkg/lightning/BUILD.bazel index 933ad8e1162d4..1cafc9ec5fbef 100644 --- a/br/pkg/lightning/BUILD.bazel +++ b/br/pkg/lightning/BUILD.bazel @@ -51,6 +51,7 @@ go_test( "//br/pkg/lightning/checkpoints", "//br/pkg/lightning/config", "//br/pkg/lightning/glue", + "//br/pkg/lightning/log", "//br/pkg/lightning/mydump", "//br/pkg/lightning/web", "@com_github_docker_go_units//:go-units", diff --git a/br/pkg/lightning/errormanager/BUILD.bazel b/br/pkg/lightning/errormanager/BUILD.bazel index e8c61ab00f0b2..7aea8447865e8 100644 --- a/br/pkg/lightning/errormanager/BUILD.bazel +++ b/br/pkg/lightning/errormanager/BUILD.bazel @@ -26,6 +26,7 @@ go_test( embed = [":errormanager"], deps = [ "//br/pkg/lightning/config", + "//br/pkg/lightning/log", "//br/pkg/utils", "@com_github_data_dog_go_sqlmock//:go-sqlmock", "@com_github_stretchr_testify//require", diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 22bc4b679c26a..7bf1a9778f709 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -81,6 +81,7 @@ 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/durationcheck:durationcheck", "//build/linter/prealloc:prealloc", ] + staticcheck_analyzers(STATICHECK_ANALYZERS), ) diff --git a/build/linter/durationcheck/BUILD.bazel b/build/linter/durationcheck/BUILD.bazel new file mode 100644 index 0000000000000..64f3959d33307 --- /dev/null +++ b/build/linter/durationcheck/BUILD.bazel @@ -0,0 +1,9 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "durationcheck", + srcs = ["analyzer.go"], + importpath = "github.com/pingcap/tidb/build/linter/durationcheck", + visibility = ["//visibility:public"], + deps = ["@com_github_charithe_durationcheck//:durationcheck"], +) diff --git a/build/linter/durationcheck/analyzer.go b/build/linter/durationcheck/analyzer.go new file mode 100644 index 0000000000000..4489e75956a50 --- /dev/null +++ b/build/linter/durationcheck/analyzer.go @@ -0,0 +1,22 @@ +// 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 durationcheck + +import ( + "github.com/charithe/durationcheck" +) + +// Analyzer is the analyzer struct of durationcheck. +var Analyzer = durationcheck.Analyzer diff --git a/go.mod b/go.mod index cd5327db9c2c2..8af187bf5e607 100644 --- a/go.mod +++ b/go.mod @@ -97,6 +97,7 @@ require ( require ( github.com/aliyun/alibaba-cloud-sdk-go v1.61.1581 + github.com/charithe/durationcheck v0.0.9 honnef.co/go/tools v0.0.1-2020.1.4 ) diff --git a/go.sum b/go.sum index c5f5f515043a7..77de5a0c0284c 100644 --- a/go.sum +++ b/go.sum @@ -131,6 +131,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/charithe/durationcheck v0.0.9 h1:mPP4ucLrf/rKZiIG/a9IPXHGlh8p4CzgpyTy6EEutYk= +github.com/charithe/durationcheck v0.0.9/go.mod h1:SSbRIBVfMjCi/kEB6K65XEA83D6prSM8ap1UCpNKtgg= github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA= github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA= github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54= diff --git a/kv/BUILD.bazel b/kv/BUILD.bazel index 600cec889528f..fed476f803dfc 100644 --- a/kv/BUILD.bazel +++ b/kv/BUILD.bazel @@ -32,6 +32,7 @@ go_library( "//util/dbterror", "//util/logutil", "//util/memory", + "//util/set", "//util/trxevents", "@com_github_coocood_freecache//:freecache", "@com_github_pingcap_errors//:errors", diff --git a/session/BUILD.bazel b/session/BUILD.bazel index e6cfe0f898682..a48f8238cc5ca 100644 --- a/session/BUILD.bazel +++ b/session/BUILD.bazel @@ -75,6 +75,7 @@ go_library( "//util/memory", "//util/parser", "//util/rowcodec", + "//util/sem", "//util/sli", "//util/sqlexec", "//util/tableutil", diff --git a/session/session_test/BUILD.bazel b/session/session_test/BUILD.bazel index 47c330e409de7..57900ac9d97cc 100644 --- a/session/session_test/BUILD.bazel +++ b/session/session_test/BUILD.bazel @@ -12,7 +12,9 @@ go_test( "//config", "//domain", "//kv", + "//parser/auth", "//parser/terror", + "//planner/core", "//session", "//store/mockstore", "//testkit", diff --git a/sessionctx/sessionstates/BUILD.bazel b/sessionctx/sessionstates/BUILD.bazel index cb421dfeac1ec..ce2f91c36176a 100644 --- a/sessionctx/sessionstates/BUILD.bazel +++ b/sessionctx/sessionstates/BUILD.bazel @@ -16,7 +16,9 @@ go_test( srcs = ["session_states_test.go"], deps = [ "//errno", + "//sessionctx/variable", "//testkit", + "//util/sem", "@com_github_stretchr_testify//require", ], ) diff --git a/util/set/BUILD.bazel b/util/set/BUILD.bazel index 790799294974f..0f733ad14ee41 100644 --- a/util/set/BUILD.bazel +++ b/util/set/BUILD.bazel @@ -5,6 +5,7 @@ go_library( srcs = [ "float64_set.go", "int_set.go", + "mem_aware_map.go", "set_with_memory_usage.go", "string_set.go", ], @@ -19,6 +20,7 @@ go_test( "float64_set_test.go", "int_set_test.go", "main_test.go", + "mem_aware_map_test.go", "set_with_memory_usage_test.go", "string_set_test.go", ], From 94c27d91bc77bba6b2c12e998d73db6822677166 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 00:09:38 +0800 Subject: [PATCH 2/5] *: enable durationcheck Signed-off-by: Weizhen Wang --- build/nogo_config.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/nogo_config.json b/build/nogo_config.json index f05718081c8ac..5fe822cce2963 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -80,6 +80,12 @@ ".*_generated\\.go$": "ignore generated code" } }, + "durationcheck": { + "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", From 6fe18648452ae12fd4a55a5ec9d07b0d60b8daf4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 00:15:16 +0800 Subject: [PATCH 3/5] *: enable durationcheck Signed-off-by: Weizhen Wang --- build/linter/durationcheck/BUILD.bazel | 5 ++++- build/linter/durationcheck/analyzer.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build/linter/durationcheck/BUILD.bazel b/build/linter/durationcheck/BUILD.bazel index 64f3959d33307..556720ba0609c 100644 --- a/build/linter/durationcheck/BUILD.bazel +++ b/build/linter/durationcheck/BUILD.bazel @@ -5,5 +5,8 @@ go_library( srcs = ["analyzer.go"], importpath = "github.com/pingcap/tidb/build/linter/durationcheck", visibility = ["//visibility:public"], - deps = ["@com_github_charithe_durationcheck//:durationcheck"], + deps = [ + "//build/linter/util", + "@com_github_charithe_durationcheck//:durationcheck", + ], ) diff --git a/build/linter/durationcheck/analyzer.go b/build/linter/durationcheck/analyzer.go index 4489e75956a50..1ebee429959fd 100644 --- a/build/linter/durationcheck/analyzer.go +++ b/build/linter/durationcheck/analyzer.go @@ -16,7 +16,12 @@ package durationcheck import ( "github.com/charithe/durationcheck" + "github.com/pingcap/tidb/build/linter/util" ) // Analyzer is the analyzer struct of durationcheck. var Analyzer = durationcheck.Analyzer + +func init() { + util.SkipAnalyzer(Analyzer) +} From f8e22384a11fd218879d9aea4143655f5ddc63c2 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 00:26:44 +0800 Subject: [PATCH 4/5] *: enable durationcheck Signed-off-by: Weizhen Wang --- build/linter/util/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/linter/util/util.go b/build/linter/util/util.go index d438ea0057a6e..d476173a973a0 100644 --- a/build/linter/util/util.go +++ b/build/linter/util/util.go @@ -55,7 +55,7 @@ func parseDirective(s string) (cmd skipType, args []string) { } return skipNone, nil } - s = strings.TrimPrefix(s, "//nolint: ") + s = strings.TrimPrefix(s, "//nolint:") return skipLinter, []string{s} } From c5f3105109121a88034289b627c507ebebbc4414 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 00:38:32 +0800 Subject: [PATCH 5/5] *: enable durationcheck Signed-off-by: Weizhen Wang --- util/dbutil/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/dbutil/common.go b/util/dbutil/common.go index ec0ffd785349e..674314af3492f 100644 --- a/util/dbutil/common.go +++ b/util/dbutil/common.go @@ -319,7 +319,7 @@ func GetTimeZoneOffset(ctx context.Context, db QueryExecutor) (time.Duration, er } hour, minute, second := t.Clock() - // nolint:durationcheck + //nolint:durationcheck return time.Duration(hour*3600+minute*60+second) * time.Second * factor, nil }