Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ nogo(
"//dev/linters/gocritic",
"//dev/linters/ineffassign",
"//dev/linters/unparam",
# Disabled because we currently have a lot of unused code
# "//dev/linters/unused",
] + STATIC_CHECK_ANALYZERS,
}),
)
Expand Down
13 changes: 13 additions & 0 deletions dev/linters/unused/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "unused",
srcs = ["unused.go"],
importpath = "github.com/sourcegraph/sourcegraph/dev/linters/unused",
visibility = ["//visibility:public"],
deps = [
"//dev/linters/nolint",
"@co_honnef_go_tools//unused",
"@org_golang_x_tools//go/analysis",
],
)
31 changes: 31 additions & 0 deletions dev/linters/unused/unused.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package unused

import (
"fmt"
"go/token"
"reflect"

"github.com/sourcegraph/sourcegraph/dev/linters/nolint"
"golang.org/x/tools/go/analysis"
"honnef.co/go/tools/unused"
)

var Analyzer = nolint.Wrap(&analysis.Analyzer{
Name: "unused",
Doc: "Unused code",
Run: func(pass *analysis.Pass) (interface{}, error) {
// This is just a lightweight wrapper around the default unused
// analyzer that reports a diagnostic error rather than just returning
// a result
allUnused := pass.ResultOf[unused.Analyzer.Analyzer].(unused.Result).Unused
for _, u := range allUnused {
pass.Report(analysis.Diagnostic{
Pos: token.Pos(u.Position.Offset),
Message: fmt.Sprintf("%s is unused", u.Name),
})
}
return nil, nil
},
Requires: []*analysis.Analyzer{unused.Analyzer.Analyzer},
ResultType: reflect.TypeOf(nil),
})