File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,27 @@ func NewUnused(settings *config.StaticCheckSettings) *goanalysis.Linter {
3535
3636 sr := unused .Serialize (pass , res .(unused.Result ), pass .Fset )
3737
38+ used := make (map [string ]bool )
39+ for _ , obj := range sr .Used {
40+ used [fmt .Sprintf ("%s %d %s" , obj .Position .Filename , obj .Position .Line , obj .Name )] = true
41+ }
42+
3843 var issues []goanalysis.Issue
44+ // Inspired by https://github.com/dominikh/go-tools/blob/d694aadcb1f50c2d8ac0a1dd06217ebb9f654764/lintcmd/lint.go#L177-L197
3945 for _ , object := range sr .Unused {
46+ if object .Kind == "type param" {
47+ continue
48+ }
49+
50+ if object .InGenerated {
51+ continue
52+ }
53+
54+ key := fmt .Sprintf ("%s %d %s" , object .Position .Filename , object .Position .Line , object .Name )
55+ if used [key ] {
56+ continue
57+ }
58+
4059 issue := goanalysis .NewIssue (& result.Issue {
4160 FromLinter : name ,
4261 Text : fmt .Sprintf ("%s %s is unused" , object .Kind , object .Name ),
You can’t perform that action at this time.
0 commit comments