Skip to content

simple: S1008 suggests to remove comments from if()s that are specifically written to make a comment stand out #1488

Closed
@artem-anisimov-0x7f

Description

@artem-anisimov-0x7f

Sometimes it makes sense to have code organised this way:

if cond {
    // explain a rather non-obvious condition checked by this if()
    return true
}
// I expect more cases to appear where I need to return true,
// but for now the above case is the only one.
return false

Gosimple's check S1008 suggests to replace this with a plain return cond.

If a conditional if smth { return true } has comments inside, then do not suggest to fold it with the code that follows.

Activity

Dynom

Dynom commented on Apr 4, 2024

@Dynom

Wouldn't this be a prime candidate to use the ignore tag's?

e.g.: //lint:ignore S1008 explain a rather non-obvious condition checked by this if() ?

artem-anisimov-0x7f

artem-anisimov-0x7f commented on Apr 4, 2024

@artem-anisimov-0x7f
Author

Of course not. //lint:ignore is positively ugly.

Dynom

Dynom commented on Apr 4, 2024

@Dynom

To have the linter assume that when there are comments in place it's "OK", you already add comments. Adding a prefix to be more explicit about it instead of assuming sounds much more robust to me. Plus it allows you to find it in the future, something you've already planned for.

Dynom

Dynom commented on Apr 4, 2024

@Dynom

Either way, reads like a dupe of #704

added 2 commits that reference this issue on Jun 1, 2024
1216812
66e5045
added a commit that references this issue on Jan 23, 2025
5aa6ff2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Dynom@dominikh@artem-anisimov-0x7f

      Issue actions

        simple: S1008 suggests to remove comments from if()s that are specifically written to make a comment stand out · Issue #1488 · dominikh/go-tools