From 35d5b575c8d5d1367e44666afe1ec2c2eec6bac0 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 16:15:28 +0800 Subject: [PATCH 1/2] *: enable exportloopref Signed-off-by: Weizhen Wang --- build/BUILD.bazel | 1 + build/linter/exportloopref/BUILD.bazel | 9 +++++++++ build/linter/exportloopref/analyzer.go | 20 ++++++++++++++++++++ build/nogo_config.json | 6 ++++++ go.mod | 1 + go.sum | 3 +++ 6 files changed, 40 insertions(+) create mode 100644 build/linter/exportloopref/BUILD.bazel create mode 100644 build/linter/exportloopref/analyzer.go diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 6284ddcfd4a19..4264907bb1fb9 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -82,6 +82,7 @@ nogo( "@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/exportloopref:exportloopref", "//build/linter/ineffassign:ineffassign", "//build/linter/prealloc:prealloc", ] + staticcheck_analyzers(STATICHECK_ANALYZERS), diff --git a/build/linter/exportloopref/BUILD.bazel b/build/linter/exportloopref/BUILD.bazel new file mode 100644 index 0000000000000..29070c40f343c --- /dev/null +++ b/build/linter/exportloopref/BUILD.bazel @@ -0,0 +1,9 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "exportloopref", + srcs = ["analyzer.go"], + importpath = "github.com/pingcap/tidb/build/linter/exportloopref", + visibility = ["//visibility:public"], + deps = ["@com_github_kyoh86_exportloopref//:exportloopref"], +) diff --git a/build/linter/exportloopref/analyzer.go b/build/linter/exportloopref/analyzer.go new file mode 100644 index 0000000000000..4a448a8092ed4 --- /dev/null +++ b/build/linter/exportloopref/analyzer.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 exportloopref + +import "github.com/kyoh86/exportloopref" + +// Analyzer is the analyzer struct of exportloopref. +var Analyzer = exportloopref.Analyzer diff --git a/build/nogo_config.json b/build/nogo_config.json index e8ebf441e3d0f..d0d99435f146b 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -92,6 +92,12 @@ ".*_generated\\.go$": "ignore generated code" } }, + "exportloopref": { + "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", diff --git a/go.mod b/go.mod index 7d5ff420d3655..351a6ea1817cf 100644 --- a/go.mod +++ b/go.mod @@ -99,6 +99,7 @@ require ( github.com/aliyun/alibaba-cloud-sdk-go v1.61.1581 github.com/charithe/durationcheck v0.0.9 github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 + github.com/kyoh86/exportloopref v0.1.8 honnef.co/go/tools v0.0.1-2020.1.4 ) diff --git a/go.sum b/go.sum index 28ddd790a2f98..5bc93febdf2ab 100644 --- a/go.sum +++ b/go.sum @@ -533,6 +533,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kyoh86/exportloopref v0.1.8 h1:5Ry/at+eFdkX9Vsdw3qU4YkvGtzuVfzT4X7S77LoN/M= +github.com/kyoh86/exportloopref v0.1.8/go.mod h1:1tUcJeiioIs7VWe5gcOObrux3lb66+sBqGZrRkMwPgg= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= @@ -1200,6 +1202,7 @@ golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200622203043-20e05c1c8ffa/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= From 31b0f1d8800f791ab780e3a9819412a01ae4615b Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 23 Jun 2022 15:49:39 +0800 Subject: [PATCH 2/2] *: enable exportloopref Signed-off-by: Weizhen Wang --- DEPS.bzl | 8 ++++++++ sessionctx/sessionstates/BUILD.bazel | 1 + 2 files changed, 9 insertions(+) diff --git a/DEPS.bzl b/DEPS.bzl index 62f0f6ea6509c..f1e7920961fc9 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -1557,6 +1557,14 @@ def go_deps(): sum = "h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=", version = "v0.2.0", ) + go_repository( + name = "com_github_kyoh86_exportloopref", + build_file_proto_mode = "disable", + importpath = "github.com/kyoh86/exportloopref", + sum = "h1:5Ry/at+eFdkX9Vsdw3qU4YkvGtzuVfzT4X7S77LoN/M=", + version = "v0.1.8", + ) + go_repository( name = "com_github_labstack_echo_v4", build_file_proto_mode = "disable_global", diff --git a/sessionctx/sessionstates/BUILD.bazel b/sessionctx/sessionstates/BUILD.bazel index ce2f91c36176a..ba5cb9254f9f8 100644 --- a/sessionctx/sessionstates/BUILD.bazel +++ b/sessionctx/sessionstates/BUILD.bazel @@ -16,6 +16,7 @@ go_test( srcs = ["session_states_test.go"], deps = [ "//errno", + "//parser/mysql", "//sessionctx/variable", "//testkit", "//util/sem",