Skip to content

Commit

Permalink
Workaround for Performance/RedundantEqualityComparisonBlock when us…
Browse files Browse the repository at this point in the history
…ing JRuby 9.2

This commits prevent the following build error when using JRuby 9.2.

```console
% ruby -v
jruby 9.2.17.0 (2.5.8) 2021-03-29 84d363da97 Java HotSpot(TM) 64-Bit
Server VM 25.271-b09 on 1.8.0_271-b09 +jit [darwin-x86_64]

% bundle exec rspec ./spec/rubocop/cop/style/parallel_assignment_spec.rb
(snip)

Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 34110
...............................................F..F.........F................

Failures:

  1) RuboCop::Cop::Style::ParallelAssignment behaves like allowed allows
  assignment of: obj.attr1, ary[0] = ary[0], obj.attr1
     Failure/Error: expect(actual_annotations.to_s).to eq(source)

       expected: "obj.attr1, ary[0] = ary[0], obj.attr1"
            got: "obj.attr1, ary[0] = ary[0],
            obj.attr1^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use
            parallel assignment.\n"

       (compared using ==)

       Diff:
       @@ -1 +1 @@
       -obj.attr1, ary[0] = ary[0], obj.attr1
       +obj.attr1, ary[0] = ary[0],
       obj.attr1^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use
       parallel assignment.
(snip)

Finished in 2.29 seconds (files took 4.04 seconds to load)
77 examples, 3 failures

Failed examples:

rspec ./spec/rubocop/cop/style/parallel_assignment_spec.rb[1:42:1] #
RuboCop::Cop::Style::ParallelAssignment behaves like allowed allows
assignment of: obj.attr1, ary[0] = ary[0], obj.attr1
rspec ./spec/rubocop/cop/style/parallel_assignment_spec.rb[1:43:1] #
RuboCop::Cop::Style::ParallelAssignment behaves like allowed allows
assignment of: ary[0], ary[1], ary[2] = ary[1], ary[2], ary[0]
rspec ./spec/rubocop/cop/style/parallel_assignment_spec.rb[1:40:1] #
RuboCop::Cop::Style::ParallelAssignment behaves like allowed allows
assignment of: a[0], a[1] = a[1], a[0]
```

It's supposed to be a JRuby's issue for `array.any?(item)`, it needs to be investigated.
  • Loading branch information
koic committed Mar 31, 2021
1 parent 8c2efd0 commit f2a1784
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rubocop/cop/style/parallel_assignment.rb
Expand Up @@ -164,7 +164,12 @@ def dependency?(lhs, rhs)
# Does `rhs` access the same value which is assigned by `lhs`?
def accesses?(rhs, lhs)
if lhs.method?(:[]=)
matching_calls(rhs, lhs.receiver, :[]).any?(lhs.arguments)
# FIXME: Workaround `rubocop:disable` comment for JRuby.
# rubocop:disable Performance/RedundantEqualityComparisonBlock
matching_calls(rhs, lhs.receiver, :[]).any? do |args|
args == lhs.arguments
end
# rubocop:enable Performance/RedundantEqualityComparisonBlock
else
access_method = lhs.method_name.to_s.chop.to_sym
matching_calls(rhs, lhs.receiver, access_method).any?
Expand Down

0 comments on commit f2a1784

Please sign in to comment.