mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
bazel: add gosimple analyzers for nogo (#50592)
This adds the gosimple linters as analyzers to nogo. Also added a few fixes it suggested in squirrel. ## Test plan * `bazel build //...` <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles -->
This commit is contained in:
parent
d9135055f5
commit
60d1769444
@ -7,7 +7,7 @@ linters:
|
||||
- forbidigo # nogo equivelant
|
||||
- gocritic # nogo equivelant
|
||||
- goimports
|
||||
- gosimple
|
||||
- gosimple # nogo equivelant
|
||||
- govet # nogo equivelant
|
||||
- ineffassign # nogo equivelant
|
||||
#- nolintlint see https://github.com/golangci/golangci-lint/issues/3228.
|
||||
|
||||
@ -131,9 +131,9 @@ type DirOrNode struct {
|
||||
|
||||
func (dirOrNode *DirOrNode) String() string {
|
||||
if dirOrNode.Dir != nil {
|
||||
return fmt.Sprintf("%s", dirOrNode.Dir)
|
||||
return dirOrNode.Dir.String()
|
||||
}
|
||||
return fmt.Sprintf("%s", dirOrNode.Node)
|
||||
return dirOrNode.Node.String()
|
||||
}
|
||||
|
||||
func (s *SquirrelService) getDef(ctx context.Context, node Node) (*Node, error) {
|
||||
|
||||
@ -244,7 +244,7 @@ var UnsupportedLanguageError = errors.New("unsupported language")
|
||||
// Parses a file and returns info about it.
|
||||
func (s *SquirrelService) parse(ctx context.Context, repoCommitPath types.RepoCommitPath) (*Node, error) {
|
||||
ext := filepath.Base(repoCommitPath.Path)
|
||||
if strings.Index(ext, ".") >= 0 {
|
||||
if strings.Contains(ext, ".") {
|
||||
ext = strings.TrimPrefix(filepath.Ext(repoCommitPath.Path), ".")
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ func lazyNodeStringer(node **Node) func() fmt.Stringer {
|
||||
if (*node).Node != nil {
|
||||
return String(fmt.Sprintf("%s ...%s...", (*node).Type(), snippet(*node)))
|
||||
} else {
|
||||
return String(fmt.Sprintf("%s", (*node).RepoCommitPath.Path))
|
||||
return String((*node).RepoCommitPath.Path)
|
||||
}
|
||||
} else {
|
||||
return String("<nil>")
|
||||
|
||||
617
dev/linters/staticcheck/BUILD.bazel
generated
617
dev/linters/staticcheck/BUILD.bazel
generated
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,41 @@
|
||||
# and re-run go generate
|
||||
|
||||
STATIC_CHECK_ANALYZERS = [
|
||||
"//dev/linters/staticcheck:S1000",
|
||||
"//dev/linters/staticcheck:S1001",
|
||||
"//dev/linters/staticcheck:S1002",
|
||||
"//dev/linters/staticcheck:S1003",
|
||||
"//dev/linters/staticcheck:S1004",
|
||||
"//dev/linters/staticcheck:S1005",
|
||||
"//dev/linters/staticcheck:S1006",
|
||||
"//dev/linters/staticcheck:S1007",
|
||||
"//dev/linters/staticcheck:S1008",
|
||||
"//dev/linters/staticcheck:S1009",
|
||||
"//dev/linters/staticcheck:S1010",
|
||||
"//dev/linters/staticcheck:S1011",
|
||||
"//dev/linters/staticcheck:S1012",
|
||||
"//dev/linters/staticcheck:S1016",
|
||||
"//dev/linters/staticcheck:S1017",
|
||||
"//dev/linters/staticcheck:S1018",
|
||||
"//dev/linters/staticcheck:S1019",
|
||||
"//dev/linters/staticcheck:S1020",
|
||||
"//dev/linters/staticcheck:S1021",
|
||||
"//dev/linters/staticcheck:S1023",
|
||||
"//dev/linters/staticcheck:S1024",
|
||||
"//dev/linters/staticcheck:S1025",
|
||||
"//dev/linters/staticcheck:S1028",
|
||||
"//dev/linters/staticcheck:S1029",
|
||||
"//dev/linters/staticcheck:S1030",
|
||||
"//dev/linters/staticcheck:S1031",
|
||||
"//dev/linters/staticcheck:S1032",
|
||||
"//dev/linters/staticcheck:S1033",
|
||||
"//dev/linters/staticcheck:S1034",
|
||||
"//dev/linters/staticcheck:S1035",
|
||||
"//dev/linters/staticcheck:S1036",
|
||||
"//dev/linters/staticcheck:S1037",
|
||||
"//dev/linters/staticcheck:S1038",
|
||||
"//dev/linters/staticcheck:S1039",
|
||||
"//dev/linters/staticcheck:S1040",
|
||||
"//dev/linters/staticcheck:SA1000",
|
||||
"//dev/linters/staticcheck:SA1001",
|
||||
"//dev/linters/staticcheck:SA1002",
|
||||
|
||||
2
dev/linters/staticcheck/cmd/BUILD.bazel
generated
2
dev/linters/staticcheck/cmd/BUILD.bazel
generated
@ -6,8 +6,8 @@ go_library(
|
||||
importpath = "github.com/sourcegraph/sourcegraph/dev/linters/staticcheck/cmd",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//dev/linters/staticcheck",
|
||||
"@co_honnef_go_tools//analysis/lint",
|
||||
"@co_honnef_go_tools//staticcheck",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@ -7,14 +7,16 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/dev/linters/staticcheck"
|
||||
"honnef.co/go/tools/analysis/lint"
|
||||
"honnef.co/go/tools/staticcheck"
|
||||
)
|
||||
|
||||
var ignoredLinters = map[string]string{
|
||||
var ignoredAnalyzer = map[string]string{
|
||||
"SAXXXX": "I am an exmaple for a linter that should be ignored",
|
||||
}
|
||||
var analyzers []*lint.Analyzer = sortedAnalyzers()
|
||||
|
||||
// if you add analyzers here make sure that staticcheck.go knows about it too!
|
||||
var analyzers []*lint.Analyzer = sorted(staticcheck.AllAnalyzers)
|
||||
|
||||
var BazelBuildTemplate = `# GENERATED FILE - DO NOT EDIT
|
||||
# This file was generated by running go generate on dev/linters/staticcheck
|
||||
@ -33,6 +35,7 @@ go_library(
|
||||
deps = [
|
||||
"//dev/linters/nolint",
|
||||
"@co_honnef_go_tools//analysis/lint",
|
||||
"@co_honnef_go_tools//simple",
|
||||
"@co_honnef_go_tools//staticcheck",
|
||||
"@org_golang_x_tools//go/analysis",
|
||||
],
|
||||
@ -45,7 +48,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//dev/linters/nolint",
|
||||
"@co_honnef_go_tools//analysis/lint",
|
||||
"@co_honnef_go_tools//simple",
|
||||
"@co_honnef_go_tools//staticcheck",
|
||||
"@org_golang_x_tools//go/analysis",
|
||||
],
|
||||
@ -64,14 +67,35 @@ STATIC_CHECK_ANALYZERS = [
|
||||
]
|
||||
`
|
||||
|
||||
func sortedAnalyzers() []*lint.Analyzer {
|
||||
linters := make([]*lint.Analyzer, 0)
|
||||
// remove ignored linters first
|
||||
for _, linter := range staticcheck.Analyzers {
|
||||
if _, shouldIgnore := ignoredLinters[linter.Analyzer.Name]; !shouldIgnore {
|
||||
linters = append(linters, linter)
|
||||
func unique(analyzers ...*lint.Analyzer) []*lint.Analyzer {
|
||||
set := make(map[string]bool)
|
||||
uniq := make([]*lint.Analyzer, 0)
|
||||
|
||||
for _, a := range analyzers {
|
||||
if _, ok := set[a.Analyzer.Name]; !ok {
|
||||
// first time we see this analyzer!
|
||||
uniq = append(uniq, a)
|
||||
set[a.Analyzer.Name] = true
|
||||
}
|
||||
}
|
||||
|
||||
return uniq
|
||||
}
|
||||
|
||||
func filterIgnored(analyzers []*lint.Analyzer, ignored map[string]string) []*lint.Analyzer {
|
||||
result := make([]*lint.Analyzer, 0)
|
||||
for _, a := range analyzers {
|
||||
if _, shouldIgnore := ignored[a.Analyzer.Name]; !shouldIgnore {
|
||||
result = append(result, a)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func sorted(analyzers []*lint.Analyzer) []*lint.Analyzer {
|
||||
linters := filterIgnored(unique(analyzers...), ignoredAnalyzer)
|
||||
// remove ignored linters first
|
||||
// now sort them
|
||||
sort.SliceStable(linters, func(i, j int) bool {
|
||||
return strings.Compare(linters[i].Analyzer.Name, linters[j].Analyzer.Name) < 0
|
||||
|
||||
@ -3,18 +3,20 @@ package staticcheck
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"honnef.co/go/tools/analysis/lint"
|
||||
"honnef.co/go/tools/simple"
|
||||
"honnef.co/go/tools/staticcheck"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/dev/linters/nolint"
|
||||
)
|
||||
|
||||
var StaticCheckAnalyzers []*lint.Analyzer = staticcheck.Analyzers
|
||||
// AllAnalyzers contains staticcheck and gosimple Analyzers
|
||||
var AllAnalyzers = append(staticcheck.Analyzers, simple.Analyzers...)
|
||||
|
||||
var AnalyzerName = ""
|
||||
var Analyzer *analysis.Analyzer = GetAnalyzerByName(AnalyzerName)
|
||||
|
||||
func GetAnalyzerByName(name string) *analysis.Analyzer {
|
||||
for _, a := range StaticCheckAnalyzers {
|
||||
for _, a := range AllAnalyzers {
|
||||
if a.Analyzer.Name == name {
|
||||
return nolint.Wrap(a.Analyzer)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user