From 02419b84a2809f9cbc0e88f3519c4f54eecfb4b0 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 31 Mar 2021 09:12:53 +0900 Subject: [PATCH] Workaround for `Performance/RedundantEqualityComparisonBlock` when using 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. --- lib/rubocop/cop/style/parallel_assignment.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/style/parallel_assignment.rb b/lib/rubocop/cop/style/parallel_assignment.rb index 86d72197170..bb6d1b31f34 100644 --- a/lib/rubocop/cop/style/parallel_assignment.rb +++ b/lib/rubocop/cop/style/parallel_assignment.rb @@ -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?