Skip to content

Commit 357ff41

Browse files
authored
Merge pull request #13034 from koic/fix_a_false_positive_for_layout_space_around_operators
[Fix #13033] Fix a false positive for `Layout/SpaceAroundOperators`
2 parents a71c653 + 3395b6a commit 357ff41

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#13033](https://github.com/rubocop/rubocop/issues/13033): Fix a false positive for `Layout/SpaceAroundOperators` when using multiple spaces between an operator and a tailing comment. ([@koic][])

lib/rubocop/cop/layout/space_around_operators.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ def check_operator(type, operator, right_operand)
180180
with_space = range_with_surrounding_space(operator)
181181
return if with_space.source.start_with?("\n")
182182

183+
comment = processed_source.comment_at_line(operator.line)
184+
return if comment && with_space.last_column == comment.loc.column
185+
183186
offense(type, operator, with_space, right_operand) do |msg|
184187
add_offense(operator, message: msg) do |corrector|
185188
autocorrect(corrector, with_space, right_operand)

spec/rubocop/cop/layout/space_around_operators_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
expect_no_offenses('x = 2/3r')
4141
end
4242

43+
it 'accepts multiple spaces between an operator and a tailing comment' do
44+
expect_no_offenses(<<~RUBY)
45+
foo + # comment
46+
bar
47+
RUBY
48+
end
49+
4350
it 'accepts scope operator' do
4451
expect_no_offenses('@io.class == Zlib::GzipWriter')
4552
end

0 commit comments

Comments
 (0)