nogo: add exportloopref linter (#49005)

Add exportloopref linter

@jhchabran this should only be merged after your PR as yours contains
some fixes
## Test plan
* `bazel build //...`
* copious amounts of CI builds
<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
This commit is contained in:
William Bezuidenhout 2023-03-21 19:14:56 +02:00 committed by GitHub
parent 7d3ea27806
commit 95994a6e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 1 deletions

1
BUILD.bazel generated
View File

@ -208,6 +208,7 @@ nogo(
visibility = ["//visibility:public"], # must have public visibility
deps = [
"//dev/linters/bodyclose",
"//dev/linters/exportloopref",
"//dev/linters/forbidigo",
"//dev/linters/gocritic",
"//dev/linters/ineffassign",

9
dev/linters/exportloopref/BUILD.bazel generated Normal file
View File

@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "exportloopref",
srcs = ["exportloopref.go"],
importpath = "github.com/sourcegraph/sourcegraph/dev/linters/exportloopref",
visibility = ["//visibility:public"],
deps = ["@com_github_kyoh86_exportloopref//:go_default_library"],
)

View File

@ -0,0 +1,7 @@
package exportloopref
import (
"github.com/kyoh86/exportloopref"
)
var Analyzer = exportloopref.Analyzer

View File

@ -6,6 +6,7 @@ require (
github.com/ashanbrown/forbidigo v1.5.1
github.com/go-critic/go-critic v0.6.7
github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28
github.com/kyoh86/exportloopref v0.1.11
github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e
golang.org/x/tools v0.6.0
)

View File

@ -39,6 +39,8 @@ github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4 h1:d2/
github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ymEyhQ=
github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

View File

@ -147,3 +147,10 @@ def linter_dependencies():
version = "v0.0.0-20230203172020-98cc5a0785f9",
sum = "h1:6WHiuFL9FNjg8RljAaT7FNUuKDbvMqS1i5cr2OE2sLQ=",
)
go_repository(
name = "com_github_kyoh86_exportloopref",
importpath = "github.com/kyoh86/exportloopref",
version = "v0.1.11",
sum = "h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ymEyhQ=",
)

View File

@ -5,7 +5,8 @@
"rules_go.*/*": "ignore rules_go working directory",
"external/*": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
".*_pb\\.go$": "ignore protobuff generated code"
".*_pb\\.go$": "ignore protobuff generated code",
"docker-images/*": "ignore all code under docker-images"
}
},
"bodyclose": {
@ -37,5 +38,14 @@
".*_pb\\.go$": "ignore protobuff generated code",
"dev/buildchecker/slack.go": "ignore false positive"
}
},
"exportloopref": {
"exclude_files": {
"lib/batches/env/var.go": "false positive",
"rules_go.*/*": "ignore rules_go working directory",
"external/*": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code",
".*_pb\\.go$": "ignore protobuff generated code"
}
}
}