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
Empty branches can be bad, but they can also be used for useful things, such as documenting special cases. We can't look for the presence of comments, because the bad kind (forgotten error handling) usually also has comments.
I am now wondering if my comment at #301 (comment) should have been made here instead. Nevermind, I can give a hint so that anyone looking at this issue also takes a quick look at the thread in #301 as well.
@dominikh, the most common case where it does is when I start to write some code, get distracted and start working on a different part of code, and then forget that I changed the code in that first file in the first place. As long as the check has an exception for comment-only branches, I think that it's useful.
I have two false positives in a project where I want to explicitly document why I don't care about the else branch.
The only true positive I've seen recently is when the code inside a branch was commented out (due to a regression, a TODO, or some other reason where you don't want to outright delete the code) and it's been left in a weird state. For instance:
My instinct is that this kind of match is a true positive, because if the code is meant to be like that, then it really deserves a TODO-like comment explaining why it's in such a state. So I think it's fair game for the check to trigger if the branch only has comments which are commented out Go syntax.
Activity
Deleplace commentedon Aug 26, 2020
Indeed I often use empty branch comments for documentation.
dgryski commentedon Aug 27, 2020
Related, https://twitter.com/dgryski/status/1286304687134617602
TafThorne commentedon Feb 26, 2021
I am now wondering if my comment at #301 (comment) should have been made here instead. Nevermind, I can give a hint so that anyone looking at this issue also takes a quick look at the thread in #301 as well.
dominikh commentedon Oct 16, 2021
Does anyone have data on true positives of this check? Does it actually catch bugs?
ainar-g commentedon Oct 18, 2021
@dominikh, the most common case where it does is when I start to write some code, get distracted and start working on a different part of code, and then forget that I changed the code in that first file in the first place. As long as the check has an exception for comment-only branches, I think that it's useful.
mvdan commentedon Mar 28, 2022
I have two false positives in a project where I want to explicitly document why I don't care about the
elsebranch.The only true positive I've seen recently is when the code inside a branch was commented out (due to a regression, a TODO, or some other reason where you don't want to outright delete the code) and it's been left in a weird state. For instance:
https://github.com/cue-lang/cue/blob/da75cdf385d3eebfb2db363a9ad9447c70be58b1/cue/build/import.go#L94
My instinct is that this kind of match is a true positive, because if the code is meant to be like that, then it really deserves a TODO-like comment explaining why it's in such a state. So I think it's fair game for the check to trigger if the branch only has comments which are commented out Go syntax.
SA9003: disable by default