Skip to content

Commit

Permalink
[#5390] Allow exceptions to Style/InlineComment for RuboCop comments (#…
Browse files Browse the repository at this point in the history
…5697)

Previously if InlineComment was enabled, any RuboCop inline comments
which disabled a cop would require also disabling the InlineComment cop.
  • Loading branch information
jfelchner authored and bbatsov committed Mar 18, 2018
1 parent 3f81a25 commit 862a594
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* [#5637](https://github.com/bbatsov/rubocop/issues/5637): Fix error for `Layout/SpaceInsideArrayLiteralBrackets` when contains an array literal as an argument after a heredoc is started. ([@koic][])
* [#5498](https://github.com/bbatsov/rubocop/issues/5498): Correct IndentHeredoc message for Ruby 2.3 when using `<<~` operator with invalid indentation. ([@hamada14][])
* [#5610](https://github.com/bbatsov/rubocop/issues/5610): Use `gems.locked` or `Gemfile.lock` to determine the best `TargetRubyVersion` when it is not specified in the config. ([@roberts1000][])
* [#5390](https://github.com/bbatsov/rubocop/issues/5390): Allow exceptions to `Style/InlineComment` for inline comments which enable or disable rubocop cops. ([@jfelchner][])
* Add progress bar to offenses formatter. ([@drewpterry][])

## 0.53.0 (2018-03-05)
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/style/inline_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class InlineComment < Cop

def investigate(processed_source)
processed_source.each_comment do |comment|
next if comment_line?(processed_source[comment.loc.line - 1])
next if comment_line?(processed_source[comment.loc.line - 1]) ||
comment.text.match(/\A# rubocop:(enable|disable)/)

add_offense(comment)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/inline_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
RUBY
end

it 'does not register an offense for special rubocop inline comments' do
expect_no_offenses(<<-RUBY.strip_indent)
two = 1 + 1 # rubocop:disable Layout/ExtraSpacing
RUBY
end

it 'does not register an offense for a standalone comment' do
expect_no_offenses('# A standalone comment')
end
Expand Down

0 comments on commit 862a594

Please sign in to comment.