You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While there may be valid use-cases for declaring an error interface in an if statement before the if expression and then not immediately checking it, I think the common expectation/use is that people are immediately checking the errors they're declaring.
Proposal
Add a flag like the existing -blank for if declares. Maybe -ifdeclares
When checking if declares, errcheck should
identify all errors declared in the if statement before the if expression
produce a warning/failure if the if-expression doesn't contain all of those errors
Open Question
Should this be enabled by default? Maybe we can run the check across stdlib as a test.
Test case
The following Go file should produce a warning/failure when if-declares are checked
Problem Statement
A common pattern of if-statement declarations is to declare an error and then check it.
e.g.
I saw someone surprised that errcheck didn't catch the following bug
While there may be valid use-cases for declaring an
error
interface in an if statement before the if expression and then not immediately checking it, I think the common expectation/use is that people are immediately checking the errors they're declaring.Proposal
-blank
for if declares. Maybe-ifdeclares
Open Question
Should this be enabled by default? Maybe we can run the check across stdlib as a test.
Test case
The following Go file should produce a warning/failure when if-declares are checked
The text was updated successfully, but these errors were encountered: