Skip to content

Commit

Permalink
Merge pull request rubocop#6209 from sunny/ignore-keyword-arguments-i…
Browse files Browse the repository at this point in the history
…n-rails-delegate

[Fix rubocop#6142] Ignore keyword arguments in `Rails/Delegate`
  • Loading branch information
koic authored Aug 29, 2018
2 parents 00fe34e + 5c56e20 commit 6140ba6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [#6192](https://github.com/rubocop-hq/rubocop/issues/6192): Make `Style/RedundantBegin` aware of stabby lambdas. ([@drenmi][])
* [#6208](https://github.com/rubocop-hq/rubocop/pull/6208): Ignore assignment methods in `Naming/PredicateName`. ([@sunny][])
* [#6196](https://github.com/rubocop-hq/rubocop/issues/6196): Fix incorrect autocorrect for `Style/EmptyCaseCondition` when using `return` in `when` clause and assigning the return value of `case`. ([@koic][])
* [#6142](https://github.com/rubocop-hq/rubocop/issues/6142): Ignore keyword arguments in `Rails/Delegate`. ([@sunny][])

### Changes

Expand Down
9 changes: 7 additions & 2 deletions lib/rubocop/cop/rails/delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ def trivial_delegate?(def_node)
def arguments_match?(arg_array, body)
argument_array = body.arguments

arg_array == argument_array ||
arg_array.map(&:children) == argument_array.map(&:children)
return false if arg_array.size != argument_array.size

arg_array.zip(argument_array).all? do |arg, argument|
arg.arg_type? &&
argument.lvar_type? &&
arg.children == argument.children
end
end

def method_name_matches?(method_name, body)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/delegate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def fox(a, baz)
RUBY
end

it 'ignores trivial delegate with mismatched keyword arguments' do
expect_no_offenses(<<-RUBY.strip_indent)
def fox(foo:)
bar.fox(foo)
end
RUBY
end

it 'ignores trivial delegate with other prefix' do
expect_no_offenses(<<-RUBY.strip_indent)
def fox_foo
Expand Down

0 comments on commit 6140ba6

Please sign in to comment.