Skip to content
Draft
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
16 changes: 12 additions & 4 deletions errorlint/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
l := LintFmtErrorfCalls(pass.Fset, *pass.TypesInfo, checkErrorfMulti)
lints = append(lints, l...)
}

// Resolve conflicts between type assertion and error comparison diagnostics
lints = resolveConflicts(lints, extInfo)

sort.Sort(ByPosition(lints))

for _, l := range lints {
Expand Down Expand Up @@ -78,11 +82,15 @@ func newTypesInfoExt(pass *analysis.Pass) *TypesInfoExt {
}
stack := []ast.Node{file}
ast.Inspect(file, func(n ast.Node) bool {
nodeParent[n] = stack[len(stack)-1]
if n == nil {
stack = stack[:len(stack)-1]
} else {
if n != nil && len(stack) > 0 {
// Only set parent if the node is not the same as the current stack top
// This prevents self-references that cause infinite loops
if n != stack[len(stack)-1] {
nodeParent[n] = stack[len(stack)-1]
}
stack = append(stack, n)
} else if n == nil {
stack = stack[:len(stack)-1]
}
return true
})
Expand Down
7 changes: 6 additions & 1 deletion errorlint/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAllowedComparisons(t *testing.T) {

func TestIssueRegressions(t *testing.T) {
analyzer := NewAnalyzer()
analysistest.Run(t, analysistest.TestData(), analyzer, "issues")
analysistest.Run(t, analysistest.TestData(), analyzer, "issues/lint")
}

func TestErrorComparisonFixes(t *testing.T) {
Expand All @@ -53,3 +53,8 @@ func TestErrorTypeAssertionFixes(t *testing.T) {
analyzer := NewAnalyzer()
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), analyzer, "errorassert")
}

func TestIssueFixRegressions(t *testing.T) {
analyzer := NewAnalyzer()
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), analyzer, "issues/fix")
}
Loading