Skip to content

Commit

Permalink
Merge pull request rubocop#13011 from koic/fix_an_error_for_style_sup…
Browse files Browse the repository at this point in the history
…er_arguments

[Fix rubocop#13010] Fix an error for `Style/SuperArguments`
  • Loading branch information
koic authored Jun 26, 2024
2 parents 399f356 + 22d390e commit 2b8ef67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_super_arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13010](https://github.com/rubocop/rubocop/issues/13010): Fix an error for `Style/SuperArguments` when the hash argument is or-assigned. ([@koic][])
5 changes: 5 additions & 0 deletions lib/rubocop/cop/style/super_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def block_arg_same?(def_node, def_arg, super_arg)
# https://bugs.ruby-lang.org/issues/20505
def block_reassigned?(def_node, block_arg_name)
def_node.each_node(*ASSIGN_TYPES).any? do |assign_node|
# TODO: Since `Symbol#name` is supported from Ruby 3.0, the inheritance check for
# `AST::Node` can be removed when requiring Ruby 3.0+.
lhs = assign_node.node_parts[0]
next if lhs.is_a?(AST::Node) && !lhs.respond_to?(:name)

assign_node.name == block_arg_name
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cop/style/super_arguments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ def bar(b:)
RUBY
end

it 'registers an offense when the hash argument is or-assigned' do
expect_offense(<<~RUBY)
def foo(options, &block)
options[:key] ||= default
super(options, &block)
^^^^^^^^^^^^^^^^^^^^^^ Call `super` without arguments and parentheses when the signature is identical.
end
RUBY

expect_correction(<<~RUBY)
def foo(options, &block)
options[:key] ||= default
super
end
RUBY
end

it 'registers no offense when calling super in a dsl method' do
expect_no_offenses(<<~RUBY)
describe 'example' do
Expand Down

0 comments on commit 2b8ef67

Please sign in to comment.