Skip to content

Commit

Permalink
Accept super within ranges for Layout/SpaceAroundKeyword cop
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Dec 25, 2022
1 parent 43cd246 commit 5dfb66e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
@@ -0,0 +1 @@
* [#8751](https://github.com/rubocop/rubocop/issues/8751): Accept `super` within ranges for `Layout/SpaceAroundKeyword` cop. ([@fatkodima][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/space_around_keyword.rb
Expand Up @@ -256,7 +256,7 @@ def preceded_by_operator?(node, _range)
# regular dotted method calls bind more tightly than operators
# so we need to climb up the AST past them
node.each_ancestor do |ancestor|
return true if ancestor.and_type? || ancestor.or_type?
return true if ancestor.and_type? || ancestor.or_type? || ancestor.range_type?
return false unless ancestor.send_type?
return true if ancestor.operator_method?
end
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Expand Up @@ -653,6 +653,20 @@ def verify_section
expect(File.read('example.rb')).to eq(corrected)
end

it 'corrects `Layout/SpaceAroundKeyword` with `Layout/SpaceInsideRangeLiteral`' do
source = <<~RUBY
def method
1..super
end
RUBY
create_file('example.rb', source)
expect(
cli.run(['-a', '--only', 'Layout/SpaceAroundKeyword,Layout/SpaceInsideRangeLiteral'])
).to eq(0)
expect($stdout.string).to include('no offenses detected')
expect(File.read('example.rb')).to eq(source)
end

it 'corrects LineEndConcatenation offenses leaving the ' \
'RedundantInterpolation offense unchanged' do
# If we change string concatenation from plus to backslash, the string
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/layout/space_around_keyword_spec.rb
Expand Up @@ -172,6 +172,10 @@
# Layout/SpaceAroundBlockParameters
it_behaves_like 'accept before', '|', 'loop { |x|break }'

# Layout/SpaceInsideRangeLiteral
it_behaves_like 'accept before', '..', '1..super.size'
it_behaves_like 'accept before', '...', '1...super.size'

# Layout/SpaceAroundOperators
it_behaves_like 'accept before', '=', 'a=begin end'
it_behaves_like 'accept before', '==', 'a==begin end'
Expand Down

0 comments on commit 5dfb66e

Please sign in to comment.