class RuboCop::Cop::Style::CommentedKeyword

end
y
class X # :nodoc:
# good
end
statement
if condition
# good
def x; end # comment
# bad
end
statement
class X # comment
# bad
end # end if
statement
if condition
# bad
@example
are allowed.
(‘:nodoc:`, `:yields:`, `rubocop:disable` and `rubocop:todo`)
Note that some comments
These keywords are: `begin`, `class`, `def`, `end`, `module`.
This cop checks for comments put on the same line as some keywords.

def line(comment)

def line(comment)
  comment.location.expression.source_line
end

def offensive?(comment)

def offensive?(comment)
  line = line(comment)
  KEYWORD_REGEXES.any? { |r| r.match?(line) } &&
    ALLOWED_COMMENT_REGEXES.none? { |r| r.match?(line) }
end

def on_new_investigation

def on_new_investigation
  processed_source.comments.each do |comment|
    next unless (match = line(comment).match(/(?<keyword>\S+).*#/))
    if offensive?(comment)
      add_offense(comment, message: format(MSG, keyword: match[:keyword]))
    end
  end
end