Skip to content

Make SA9003 less noisy #321

Open
Open

Description

@dominikh

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.

Activity

  1. Deleplace commented on Aug 26, 2020

    @Deleplace
    Contributor

    Indeed I often use empty branch comments for documentation.

  2. TafThorne commented on Feb 26, 2021

    @TafThorne

    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.

  3. dominikh commented on Oct 16, 2021

    @dominikh
    OwnerAuthor

    Does anyone have data on true positives of this check? Does it actually catch bugs?

  4. ainar-g commented on Oct 18, 2021

    @ainar-g

    @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.

  5. mvdan commented on Mar 28, 2022

    @mvdan
    Contributor

    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:

    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.

  6. added a commit that references this issue on Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions