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/CommentedKeyword has different definition of disable/todo comment format #12717

Closed
jonas054 opened this issue Feb 27, 2024 · 0 comments
Closed

Comments

@jonas054
Copy link
Collaborator

jonas054 commented Feb 27, 2024

This came out of the discussion in #12705.

For the inline disabling of cops in inspected code, RuboCop allows many variations of the # rubocop:disable and # rubocop:todo comments when it comes to the use of whitespace.

The Style/CommentedKeyword cop, which reports on end-of-line comments next to certain keywords, makes exceptions for these special comments and don't report offenses for them. The problem is that the cop's definition of the comments is quite strict regarding whitespace, and it deviates from what other parts of RuboCop defines as acceptable syntax for them.

Expected behavior

The same definition of # rubocop:disable and # rubocop:todo should be used everywhere.

Actual behavior

Style/CommentedKeyword reports and corrects offenses if the spacing isn't # rubopcop:disable Dept/Cop.

Steps to reproduce the problem

Run rubocop --only Style/CommentedKeyword on the file

def my_method # rubocop: disable Metrics/MethodLength
end

An offense is reported.

RuboCop version

1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.0.0) [x86_64-linux]
jonas054 added a commit to jonas054/rubocop that referenced this issue Feb 27, 2024
…e/CommentedKeyword

To make sure we don't have a different, more strict definition of what
constitutes a rubocop:disable or rubocop:todo comment in the cop compared to
elsewhere in the code, use the definition implemented in DirectiveComment.

We also get the rubocop:enable comments included in this definition, but it's
not a problem if we allow those comments in the cop, as they don't make any
sense as end-of-line comments and are unlikely to occur.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant