Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept super within ranges for Layout/SpaceAroundKeyword cop #11331

Merged
merged 1 commit into from Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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