Skip to content

Commit

Permalink
Suppress RuboCop Performance 1.9's offenses
Browse files Browse the repository at this point in the history
This commit suppresss new `Performance/BlockGivenWithExplicitBlock` and
`Performance/Sum` offenses.

```console
Offenses:

lib/rubocop/ast/node.rb:225:51: C:
Performance/BlockGivenWithExplicitBlock: Check block argument explicitly
instead of using block_given?.
        return to_enum(__method__, *types) unless block_given?
                                                  ^^^^^^^^^^^^
(snip)

lib/rubocop/ast/node_pattern/lexer.rb:55:36: C: [Corrected]
Performance/Sum: Use sum { ... } instead of map { ... }.sum.
          flag = options.each_char.map { |c| REGEXP_OPTIONS[c] }.sum
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
  • Loading branch information
koic authored and marcandre committed Nov 22, 2020
1 parent dd6cf59 commit 6dad540
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def node_parts
# @return [self] if a block is given
# @return [Enumerator] if no block is given
def each_ancestor(*types, &block)
return to_enum(__method__, *types) unless block_given?
return to_enum(__method__, *types) unless block

visit_ancestors(types, &block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/array_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArrayNode < Node

# @deprecated Use `values.each` (a.k.a. `children.each`)
def each_value(&block)
return to_enum(__method__) unless block_given?
return to_enum(__method__) unless block

values.each(&block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/case_match_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def keyword

# @deprecated Use `in_pattern_branches.each`
def each_in_pattern(&block)
return in_pattern_branches.to_enum(__method__) unless block_given?
return in_pattern_branches.to_enum(__method__) unless block

in_pattern_branches.each(&block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/case_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def keyword

# @deprecated Use `when_branches.each`
def each_when(&block)
return when_branches.to_enum(__method__) unless block_given?
return when_branches.to_enum(__method__) unless block

when_branches.each(&block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/const_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def relative?
# s(:const, :Foo), then
# s(:const, s(:const, :Foo), :Bar)
def each_path(&block)
return to_enum(__method__) unless block_given?
return to_enum(__method__) unless block

descendants = []
last = self
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/hash_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def keys
# @return [self] if a block is given
# @return [Enumerator] if no block is given
def each_key(&block)
return pairs.map(&:key).to_enum unless block_given?
return pairs.map(&:key).to_enum unless block

pairs.map(&:key).each(&block)

Expand All @@ -81,7 +81,7 @@ def values
# @return [self] if a block is given
# @return [Enumerator] if no block is given
def each_value(&block)
return pairs.map(&:value).to_enum unless block_given?
return pairs.map(&:value).to_enum unless block

pairs.map(&:value).each(&block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/if_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def branches

# @deprecated Use `branches.each`
def each_branch(&block)
return branches.to_enum(__method__) unless block_given?
return branches.to_enum(__method__) unless block

branches.each(&block)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/mixin/descendence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def child_nodes
# @return [self] if a block is given
# @return [Enumerator] if no block is given
def each_descendant(*types, &block)
return to_enum(__method__, *types) unless block_given?
return to_enum(__method__, *types) unless block

visit_descendants(types, &block)

Expand Down Expand Up @@ -94,7 +94,7 @@ def descendants
# @return [self] if a block is given
# @return [Enumerator] if no block is given
def each_node(*types, &block)
return to_enum(__method__, *types) unless block_given?
return to_enum(__method__, *types) unless block

yield self if types.empty? || types.include?(type)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/when_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def conditions

# @deprecated Use `conditions.each`
def each_condition(&block)
return conditions.to_enum(__method__) unless block_given?
return conditions.to_enum(__method__) unless block

conditions.each(&block)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def init_with(coder) #:nodoc:
# Yields its argument and any descendants, depth-first.
#
def self.descend(element, &block)
return to_enum(__method__, element) unless block_given?
return to_enum(__method__, element) unless block

yield element

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node_pattern/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def emit_comment
def emit_regexp
body = ss[1]
options = ss[2]
flag = options.each_char.map { |c| REGEXP_OPTIONS[c] }.sum
flag = options.each_char.sum { |c| REGEXP_OPTIONS[c] }

emit(:tREGEXP) { Regexp.new(body, flag) }
end
Expand Down

0 comments on commit 6dad540

Please sign in to comment.