Rubocop: false offense for Style/CommentedKeyword

Created on 19 Oct 2017  路  7Comments  路  Source: rubocop-hq/rubocop

Expected behavior

I expect rubocop to allow literal octothorpes and interpolated strings in method arguments.

Actual behavior

An offense was generated for an interpolated string in a method argument. The offense claims this is a comment, which triggered a violation of the Style/CommentedKeyword cop.

Steps to reproduce the problem

  1. Define a method with an octothorpe in a string as a default method argument.
  2. Run $ rubocop
  3. An offense similar to the screenshot below should get generated.

rubocop v0 51 0 - style commentedkeyword

RuboCop version

0.51.0

Most helpful comment

Hm. I'm guessing this cop uses a regular expression instead of checking for comments outside the AST. 馃槄

We should add an internal affairs cop that bans this. Seems to be the source of a lot of bugs

All 7 comments

I have another example of a false positive:

image

Hm. I'm guessing this cop uses a regular expression instead of checking for comments outside the AST. 馃槄

Hm. I'm guessing this cop uses a regular expression instead of checking for comments outside the AST. 馃槄

We should add an internal affairs cop that bans this. Seems to be the source of a lot of bugs

@backus True. And I guess we don't review these things very carefully. 馃槅

Same problem here.

app/helpers/bootstrap/alert_helper.rb:49:40: C: Do not place comments on the same line as the def keyword.
    def alert_link(name = nil, path = '#', options = {}, &block)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^

Also here:

def self.tap_paths(name, taps = Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"])

same for # inside Regexp:

foo.rb:2:20: C: Do not place comments on the same line as the def keyword.
  def foo(type = /^#{self.bar}_/)
Was this page helpful?
0 / 5 - 0 ratings