Skip to content

Commit

Permalink
Fix a false negative for Layout/LeadingCommentSpace
Browse files Browse the repository at this point in the history
This PR fixes a false negative for `Layout/LeadingCommentSpace`
when using `#+` or `#-` as they are not RDoc comments.

They are followed by `+` or `-` twice, such as `#++` and `#--`.
  • Loading branch information
koic authored and bbatsov committed Aug 21, 2023
1 parent ce93abd commit 53433c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/leading_comment_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LeadingCommentSpace < Base

def on_new_investigation
processed_source.comments.each do |comment|
next unless /\A#+[^#\s=+-]/.match?(comment.text)
next unless /\A(?!#\+\+|#--)(#+[^#\s=])/.match?(comment.text)
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
next if doxygen_comment_style?(comment)
next if gemfile_ruby_comment?(comment)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/layout/leading_comment_space_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
RUBY
end

it 'registers an offense when using `#+` or `#-` as they are not RDoc comments' do
expect_offense(<<~RUBY)
#+
^^ Missing space after `#`.
#-
^^ Missing space after `#`.
RUBY

expect_correction(<<~RUBY)
# +
# -
RUBY
end

it 'registers an offense when starting `:`' do
expect_offense(<<~RUBY)
#:nodoc:
Expand Down

0 comments on commit 53433c4

Please sign in to comment.