Skip to content

Commit

Permalink
unused: fix false-positive (#2772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Apr 19, 2022
1 parent 333187c commit f79bc88
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/golinters/unused.go
Expand Up @@ -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),
Expand Down

0 comments on commit f79bc88

Please sign in to comment.