unused: fix false-positive (#2772)
This commit is contained in:
parent
333187c066
commit
f79bc883fb
@ -35,8 +35,27 @@ func NewUnused(settings *config.StaticCheckSettings) *goanalysis.Linter {
|
||||
|
||||
sr := unused.Serialize(pass, res.(unused.Result), pass.Fset)
|
||||
|
||||
used := make(map[string]bool)
|
||||
for _, obj := range sr.Used {
|
||||
used[fmt.Sprintf("%s %d %s", obj.Position.Filename, obj.Position.Line, obj.Name)] = true
|
||||
}
|
||||
|
||||
var issues []goanalysis.Issue
|
||||
// Inspired by https://github.com/dominikh/go-tools/blob/d694aadcb1f50c2d8ac0a1dd06217ebb9f654764/lintcmd/lint.go#L177-L197
|
||||
for _, object := range sr.Unused {
|
||||
if object.Kind == "type param" {
|
||||
continue
|
||||
}
|
||||
|
||||
if object.InGenerated {
|
||||
continue
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s %d %s", object.Position.Filename, object.Position.Line, object.Name)
|
||||
if used[key] {
|
||||
continue
|
||||
}
|
||||
|
||||
issue := goanalysis.NewIssue(&result.Issue{
|
||||
FromLinter: name,
|
||||
Text: fmt.Sprintf("%s %s is unused", object.Kind, object.Name),
|
||||
|
Loading…
x
Reference in New Issue
Block a user