Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style/CommentAnnotation reports only first of multiple offending lines #5713

Closed
jdno opened this issue Mar 22, 2018 · 3 comments · Fixed by #8798
Closed

Style/CommentAnnotation reports only first of multiple offending lines #5713

jdno opened this issue Mar 22, 2018 · 3 comments · Fixed by #8798
Labels

Comments

@jdno
Copy link

jdno commented Mar 22, 2018

Good morning everyone,

I stumbled upon some unexpected behavior when working on a project. I created a minimal working example here.

I am working on a class that has multiple # TODO ... annotations. Something like this:

class ToBeDone
  ITEMS = [
    '', # TODO Item 1
    '', # TODO Item 2

    '', # TODO Item 3
  ].freeze
end

When running Rubocop, it reports a Style/CommentAnnotation offense, because the proper style would be # TODO: .... But it does that only for the first and third occurrence, and not for the second one.

jandavid@STS ~/D/j/rubocop-todo-bug> rubocop
Inspecting 2 files
C.

Offenses:

todo.rb:5:11: C: Style/CommentAnnotation: Annotation keywords like TODO should be all upper case, followed by a colon, and a space, then a note describing the problem.
    '', # TODO Item 1
          ^^^^^
todo.rb:8:11: C: Style/CommentAnnotation: Annotation keywords like TODO should be all upper case, followed by a colon, and a space, then a note describing the problem.
    '', # TODO Item 3
          ^^^^^

2 files inspected, 2 offenses detected

Even after fixing the first and third line, the second line is never reported as an offense. This also means that rubicon -a will never pick that line up and fix it automatically.

Expected behavior

When there are Style/CommentAnnotation in multiple lines that follow each other, Rubocop should report a violation for each individual line.

Actual behavior

When there are Style/CommentAnnotation in multiple lines that follow each other, only the first offense is reported.

Steps to reproduce the problem

Check out the minimal working example. Download the Gist as a ZIP, extract the archive, execute bundle if necessary and run rubocop in it.

RuboCop version

Include the output of rubocop -V. Here's an example:

jandavid@STS ~/D/j/rubocop-todo-bug> rubocop -V
0.54.0 (using Parser 2.5.0.4, running on ruby 2.5.0 x86_64-darwin17)
@Drenmi Drenmi added the bug label Mar 23, 2018
svendittmer added a commit to svendittmer/rubocop that referenced this issue Apr 17, 2018
@smackesey
Copy link

I can see this is closed but it appears to still be in effect. On rubocop 0.86:

# TODO a
# TODO b
# TODO c

Only marks the first line as problematic.

@marcandre marcandre reopened this Jun 25, 2020
@dmytro-savochkin
Copy link

I can see this is closed but it appears to still be in effect. On rubocop 0.86:

# TODO a
# TODO b
# TODO c

Only marks the first line as problematic.

I can't see a definitive way to detect whether a TODO on the second line is a new TODO or a continuation of the first line. For example, if we relax the code so it finds every first TODO (or any other keyword) on every line then it would break the following example from the specs:

# Example: There are three reviews, with ranks 1, 2, and 3. A new
# review is saved with rank 2. The two reviews that originally had
# ranks 2 and 3 will have their ranks increased to 3 and 4.

Here, it would correct the second line from review to REVIEW: .

IMHO in this case it's more important to stay safe then find more potential offenses. So I'd vote to keep it as it is.

@smackesey
Copy link

That makes sense. I think a note should be added to the docs explaining that the rule will only look at keywords in the first line of a paragraph (consecutive series of comment lines), because otherwise the behavior is confusing.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 25, 2020
bbatsov pushed a commit that referenced this issue Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants