Skip to content

Commit

Permalink
*: enable durationcheck for nogo linter (#35661)
Browse files Browse the repository at this point in the history
ref #35345
  • Loading branch information
hawkingrei authored Jun 23, 2022
1 parent e99d82a commit 966844b
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 2 deletions.
8 changes: 8 additions & 0 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/errormanager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
12 changes: 12 additions & 0 deletions build/linter/durationcheck/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 = "durationcheck",
srcs = ["analyzer.go"],
importpath = "github.com/pingcap/tidb/build/linter/durationcheck",
visibility = ["//visibility:public"],
deps = [
"//build/linter/util",
"@com_github_charithe_durationcheck//:durationcheck",
],
)
27 changes: 27 additions & 0 deletions build/linter/durationcheck/analyzer.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 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)
}
2 changes: 1 addition & 1 deletion build/linter/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
6 changes: 6 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions session/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ go_library(
"//util/memory",
"//util/parser",
"//util/rowcodec",
"//util/sem",
"//util/sli",
"//util/sqlexec",
"//util/tableutil",
Expand Down
2 changes: 2 additions & 0 deletions session/session_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ go_test(
"//config",
"//domain",
"//kv",
"//parser/auth",
"//parser/terror",
"//planner/core",
"//session",
"//store/mockstore",
"//testkit",
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/sessionstates/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ go_test(
srcs = ["session_states_test.go"],
deps = [
"//errno",
"//sessionctx/variable",
"//testkit",
"//util/sem",
"@com_github_stretchr_testify//require",
],
)
2 changes: 1 addition & 1 deletion util/dbutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions util/set/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand All @@ -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",
],
Expand Down

0 comments on commit 966844b

Please sign in to comment.