From 44c070af0829b1f87ecf754e2cccc4e74a22b27f Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sun, 14 Apr 2024 14:52:41 +0200 Subject: [PATCH] fix: keep only typecheck issues (#4640) --- pkg/result/processors/invalid_issue.go | 12 ++++++++---- pkg/result/processors/invalid_issue_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pkg/result/processors/invalid_issue.go b/pkg/result/processors/invalid_issue.go index 192fa29de057..569929680f77 100644 --- a/pkg/result/processors/invalid_issue.go +++ b/pkg/result/processors/invalid_issue.go @@ -22,16 +22,20 @@ func (InvalidIssue) Name() string { } func (p InvalidIssue) Process(issues []result.Issue) ([]result.Issue, error) { + tcIssues := filterIssues(issues, func(issue *result.Issue) bool { + return issue.FromLinter == "typecheck" + }) + + if len(tcIssues) > 0 { + return tcIssues, nil + } + return filterIssuesErr(issues, p.shouldPassIssue) } func (InvalidIssue) Finish() {} func (p InvalidIssue) shouldPassIssue(issue *result.Issue) (bool, error) { - if issue.FromLinter == "typecheck" { - return true, nil - } - if issue.FilePath() == "" { p.log.Warnf("no file path for the issue: probably a bug inside the linter %q: %#v", issue.FromLinter, issue) diff --git a/pkg/result/processors/invalid_issue_test.go b/pkg/result/processors/invalid_issue_test.go index a4bb38523f99..b0e45998041e 100644 --- a/pkg/result/processors/invalid_issue_test.go +++ b/pkg/result/processors/invalid_issue_test.go @@ -31,6 +31,21 @@ func TestInvalidIssue_Process(t *testing.T) { {FromLinter: "typecheck"}, }, }, + { + desc: "keep only typecheck issues if any exist", + issues: []result.Issue{ + {FromLinter: "typecheck"}, + { + FromLinter: "example", + Pos: token.Position{ + Filename: "test.go", + }, + }, + }, + expected: []result.Issue{ + {FromLinter: "typecheck"}, + }, + }, { desc: "Go file", issues: []result.Issue{