Skip to content

Commit

Permalink
Suppress Performance/MapMethodChain cop's offenses
Browse files Browse the repository at this point in the history
This PR suppresses the following `Performance/MapMethodChain` cop's offenses:

```console
$ bundle exec rubocop
(snip)

lib/rubocop/ast/node_pattern/node.rb:210:33: C: Performance/MapMethodChain:
Use map { |x| x.arity_range.minmax } instead of map method chain.
            min, max = children.map(&:arity_range).map(&:minmax).transpose.map(&:sum)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node_pattern/node.rb:226:39: C: Performance/MapMethodChain:
Use map { |x| x.arity_range.minmax } instead of map method chain.
            minima, maxima = children.map(&:arity_range).map(&:minmax).transpose
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/rubocop/ast/node_pattern/lexer_spec.rb:35:21: C: Performance/MapMethodChain:
Use map { |x| x.last.first } instead of map method chain.
      expect(tokens.map(&:last).map(&:first)).to eq \
                    ^^^^^^^^^^^^^^^^^^^^^^^^
spec/rubocop/ast/node_pattern/lexer_spec.rb:71:39: C: Performance/MapMethodChain:
Use map { |x| x.last.first } instead of map method chain.
      zz, percent_zz = tokens.last(2).map(&:last).map(&:first)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^
spec/rubocop/ast/node_pattern/lexer_spec.rb:81:21: C: Performance/MapMethodChain:
Use map { |x| x.last.first } instead of map method chain.
      expect(tokens.map(&:last).map(&:first)).to eq [:&]
                    ^^^^^^^^^^^^^^^^^^^^^^^^

163 files inspected, 5 offenses detected
```
  • Loading branch information
koic committed Aug 15, 2023
1 parent c1d777b commit f678818
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node_pattern/node.rb
Expand Up @@ -207,7 +207,7 @@ class Subsequence < Node
include ForbidInSeqHead

def arity
min, max = children.map(&:arity_range).map(&:minmax).transpose.map(&:sum)
min, max = children.map { |child| child.arity_range.minmax }.transpose.map(&:sum)
min == max ? min || 0 : min..max # NOTE: || 0 for empty case, where min == max == nil.
end

Expand All @@ -223,7 +223,7 @@ def in_sequence_head
# Node class for `{ ... }`
class Union < Node
def arity
minima, maxima = children.map(&:arity_range).map(&:minmax).transpose
minima, maxima = children.map { |child| child.arity_range.minmax }.transpose
min = minima.min
max = maxima.max
min == max ? min : min..max
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/ast/node_pattern/lexer_spec.rb
Expand Up @@ -32,7 +32,7 @@
let(:source) { '(array sym $int+ x)' }

it 'is parsed as `$ int + x`' do
expect(tokens.map(&:last).map(&:first)).to eq \
expect(tokens.map { |token| token.last.first }).to eq \
%i[( array sym $ int + x )]
end
end
Expand Down Expand Up @@ -68,7 +68,7 @@
it 'distinguishes them' do
types = tokens.map(&:first)
expect(types).to eq ([:tNODE_TYPE] * 2) + ([:tPARAM_CONST] * 7)
zz, percent_zz = tokens.last(2).map(&:last).map(&:first)
zz, percent_zz = tokens.last(2).map { |token| token.last.first }
expect(zz).to eq 'Zz'
expect(percent_zz).to eq 'Zz'
end
Expand All @@ -78,7 +78,7 @@
let(:source) { ':&' }

it 'is parsed as `:&`' do
expect(tokens.map(&:last).map(&:first)).to eq [:&]
expect(tokens.map { |token| token.last.first }).to eq [:&]
end
end
end

0 comments on commit f678818

Please sign in to comment.