bzl: port go compiler directives linter from sg lint to nogo (#54485)

This removes the linter that checks for incorrectly formatted
`go:generate` directives from `sg lint` and replace it with a proper
linter handled by `nogo`.

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

Locally tested + CI
This commit is contained in:
Jean-Hadrien Chabran 2023-06-30 14:31:15 +02:00 committed by GitHub
parent 1edc56babf
commit 55b1d125a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 3 deletions

1
BUILD.bazel generated
View File

@ -314,6 +314,7 @@ nogo(
"//dev/linters/depguard",
"//dev/linters/exportloopref",
"//dev/linters/forbidigo",
"//dev/linters/gocheckcompilerdirectives",
"//dev/linters/gocritic",
"//dev/linters/ineffassign",
"//dev/linters/unparam",

View File

@ -15,6 +15,7 @@ require (
)
require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
github.com/go-toolsmith/astfmt v1.1.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect

View File

@ -1,3 +1,5 @@
4d63.com/gocheckcompilerdirectives v1.2.1 h1:AHcMYuw56NPjq/2y615IGg2kYkBdTvOaojYCBcRE7MA=
4d63.com/gocheckcompilerdirectives v1.2.1/go.mod h1:yjDJSxmDTtIHHCqX0ufRYZDL6vQtMG7tJdKVeWwsqvs=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/OpenPeeDeeP/depguard/v2 v2.0.1 h1:yr9ZswukmNxl/hmJHEoLEjCF1d+f2pQrC0m1jzVljAE=
github.com/OpenPeeDeeP/depguard/v2 v2.0.1/go.mod h1:gwSk4XDpowOuQSsMWNK5F7+C3kMz7QIexKRkD/GL4GU=

View File

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

View File

@ -0,0 +1,8 @@
package gocheckcompilerdirectives
import (
"4d63.com/gocheckcompilerdirectives/checkcompilerdirectives"
"github.com/sourcegraph/sourcegraph/dev/linters/nolint"
)
var Analyzer = nolint.Wrap(checkcompilerdirectives.Analyzer())

View File

@ -149,7 +149,7 @@ func runGoGenerate(ctx context.Context, args []string, progressBar bool, verbosi
// If no packages are given, go for everything except doc/cli/references.
// We cut down on the number of files we have to generate by looking for a
// go:generate directive by hand first.
// "go:generate" directive by hand first.
paths, err := FindFilesWithGenerate(wd)
if err != nil {
return err

View File

@ -10,7 +10,6 @@ import (
)
var (
goFmt = runScript("Go format", "dev/check/gofmt.sh")
goDBConnImport = runScript("Go pkg/database/dbconn", "dev/check/go-dbconn-import.sh")
)

View File

@ -35,7 +35,6 @@ var Targets = []Target{
Name: "go",
Description: "Check go code for linting errors, forbidden imports, generated files, etc",
Checks: []*linter{
goFmt,
goGenerateLinter,
goDBConnImport,
goEnterpriseImport,

View File

@ -175,3 +175,10 @@ def linter_dependencies():
version = "v0.0.0-20230312165513-e84e2d14e3b8",
sum = "h1:VuJo4Mt0EVPychre4fNlDWDuE5AjXtPJpRUWqZDQhaI=",
)
go_repository(
name ="com_4d63_gocheckcompilerdirectives",
importpath = "4d63.com/gocheckcompilerdirectives",
version = "v1.2.1",
sum = "h1:AHcMYuw56NPjq/2y615IGg2kYkBdTvOaojYCBcRE7MA=",
)