Skip to content

Commit

Permalink
Merge pull request #13034 from koic/fix_a_false_positive_for_layout_s…
Browse files Browse the repository at this point in the history
…pace_around_operators

[Fix #13033] Fix a false positive for `Layout/SpaceAroundOperators`
  • Loading branch information
koic authored Jul 9, 2024
2 parents a71c653 + 3395b6a commit 357ff41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +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][])
3 changes: 3 additions & 0 deletions lib/rubocop/cop/layout/space_around_operators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def check_operator(type, operator, right_operand)
with_space = range_with_surrounding_space(operator)
return if with_space.source.start_with?("\n")

comment = processed_source.comment_at_line(operator.line)
return if comment && with_space.last_column == comment.loc.column

offense(type, operator, with_space, right_operand) do |msg|
add_offense(operator, message: msg) do |corrector|
autocorrect(corrector, with_space, right_operand)
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/layout/space_around_operators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
expect_no_offenses('x = 2/3r')
end

it 'accepts multiple spaces between an operator and a tailing comment' do
expect_no_offenses(<<~RUBY)
foo + # comment
bar
RUBY
end

it 'accepts scope operator' do
expect_no_offenses('@io.class == Zlib::GzipWriter')
end
Expand Down

0 comments on commit 357ff41

Please sign in to comment.