Skip to content

Commit 53433c4

Browse files
koicbbatsov
authored andcommitted
Fix a false negative for Layout/LeadingCommentSpace
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 `#--`.
1 parent ce93abd commit 53433c4

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/layout/leading_comment_space.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LeadingCommentSpace < Base
5757

5858
def on_new_investigation
5959
processed_source.comments.each do |comment|
60-
next unless /\A#+[^#\s=+-]/.match?(comment.text)
60+
next unless /\A(?!#\+\+|#--)(#+[^#\s=])/.match?(comment.text)
6161
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
6262
next if doxygen_comment_style?(comment)
6363
next if gemfile_ruby_comment?(comment)

spec/rubocop/cop/layout/leading_comment_space_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@
143143
RUBY
144144
end
145145

146+
it 'registers an offense when using `#+` or `#-` as they are not RDoc comments' do
147+
expect_offense(<<~RUBY)
148+
#+
149+
^^ Missing space after `#`.
150+
#-
151+
^^ Missing space after `#`.
152+
RUBY
153+
154+
expect_correction(<<~RUBY)
155+
# +
156+
# -
157+
RUBY
158+
end
159+
146160
it 'registers an offense when starting `:`' do
147161
expect_offense(<<~RUBY)
148162
#:nodoc:

0 commit comments

Comments
 (0)