rubocop-performance 1.13.0 → 1.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 874ce36b942ed539ead8c3329a7dd6831224459a286c2b3189605775e725fc60
4
- data.tar.gz: 584a851432d98e548151baa8afc1f9a30d5dcca05f8eae0d86c68f17bf933f34
3
+ metadata.gz: cc8de809f0aa167f08fd75ed2f7047fabc37b06b12a0c59e4647530b18fb6d99
4
+ data.tar.gz: df849a7c117eb44d8851969031cda6d5927e2f271ad41bc3689212bad6b9e2e1
5
5
  SHA512:
6
- metadata.gz: 102cccbb3be2ba55702a2e7aff3c56c6325c80481d269f87921ca1d16a79fa12830c6f080f49bacdebf4b5726e4f4c42af2527c13a4abac5aae0cf4544fb018e
7
- data.tar.gz: 23c8beebceef175caf7e226a136bb3eaff500b71f5e3e26cba9fee9a84e36aa7a3b315b11216844b7980a421a82fff7a5346560ef1418f58fbe5261599fe4dec
6
+ metadata.gz: 24c72e01dfa6cfe35b3c93e1c83d63aaa0362dff7bc4ed234b8b6f8c1a434927a945b077273ec84c95be86d70e050f28e18dad27ffc9c72350f49c7ff3477b4a
7
+ data.tar.gz: 3340644f87ea108d8f7022756ff5cdf442b0d2951cd9ea351bb0a4012c2d0721dc921b1402e8b5f952899015b51c402cdbcab5e785d764f4655aa068c71be6b3
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-21 Bozhidar Batsov
1
+ Copyright (c) 2012-22 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -38,8 +38,9 @@ module RuboCop
38
38
 
39
39
  block_arg = def_node.arguments.find(&:blockarg_type?)
40
40
  return unless block_arg
41
+ return unless (block_arg_name = block_arg.loc.name)
41
42
 
42
- block_arg_name = block_arg.loc.name.source.to_sym
43
+ block_arg_name = block_arg_name.source.to_sym
43
44
  return if reassigns_block_arg?(def_node, block_arg_name)
44
45
 
45
46
  add_offense(node) do |corrector|
@@ -3,18 +3,16 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of
6
+ # This cop is used to identify usages of `array.compact.flatten.map { |x| x.downcase }`.
7
+ # Each of these methods (`compact`, `flatten`, `map`) will generate a new intermediate array
8
+ # that is promptly thrown away. Instead it is faster to mutate when we know it's safe.
9
+ #
7
10
  # @example
8
11
  # # bad
9
12
  # array = ["a", "b", "c"]
10
13
  # array.compact.flatten.map { |x| x.downcase }
11
14
  #
12
- # Each of these methods (`compact`, `flatten`, `map`) will generate a
13
- # new intermediate array that is promptly thrown away. Instead it is
14
- # faster to mutate when we know it's safe.
15
- #
16
- # @example
17
- # # good.
15
+ # # good
18
16
  # array = ["a", "b", "c"]
19
17
  # array.compact!
20
18
  # array.flatten!
@@ -58,17 +58,17 @@ module RuboCop
58
58
 
59
59
  add_offense(range) do |corrector|
60
60
  corrector.replace(map_node.loc.selector, 'filter_map')
61
- remove_compact_method(corrector, node, node.parent)
61
+ remove_compact_method(corrector, map_node, node, node.parent)
62
62
  end
63
63
  end
64
64
 
65
65
  private
66
66
 
67
- def remove_compact_method(corrector, compact_node, chained_method)
67
+ def remove_compact_method(corrector, map_node, compact_node, chained_method)
68
68
  compact_method_range = compact_node.loc.selector
69
69
 
70
70
  if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && chained_method.dot? &&
71
- !map_method_and_compact_method_on_same_line?(compact_node) &&
71
+ !map_method_and_compact_method_on_same_line?(map_node, compact_node) &&
72
72
  !invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
73
73
  compact_method_range = compact_method_with_final_newline_range(compact_method_range)
74
74
  else
@@ -78,11 +78,7 @@ module RuboCop
78
78
  corrector.remove(compact_method_range)
79
79
  end
80
80
 
81
- def map_method_and_compact_method_on_same_line?(compact_node)
82
- return false unless compact_node.children.first.respond_to?(:send_node)
83
-
84
- map_node = compact_node.children.first.send_node
85
-
81
+ def map_method_and_compact_method_on_same_line?(map_node, compact_node)
86
82
  compact_node.loc.selector.line == map_node.loc.selector.line
87
83
  end
88
84
 
@@ -27,8 +27,11 @@ module RuboCop
27
27
 
28
28
  MSG = 'Use `%<symbol_arg>s` instead of `%<string_arg>s`.'
29
29
 
30
+ # NOTE: `attr` method is not included in this list as it can cause false positives in Nokogiri API.
31
+ # And `attr` may not be used because `Style/Attr` registers an offense.
32
+ # https://github.com/rubocop/rubocop-performance/issues/278
30
33
  RESTRICT_ON_SEND = %i[
31
- alias_method attr attr_accessor attr_reader attr_writer autoload autoload?
34
+ alias_method attr_accessor attr_reader attr_writer autoload autoload?
32
35
  class_variable_defined? const_defined? const_get const_set const_source_location
33
36
  define_method instance_method method_defined? private_class_method? private_method_defined?
34
37
  protected_method_defined? public_class_method public_instance_method public_method_defined?
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Performance
5
5
  # This module holds the RuboCop Performance version information.
6
6
  module Version
7
- STRING = '1.13.0'
7
+ STRING = '1.13.3'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-12-25 00:00:00.000000000 Z
13
+ date: 2022-03-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.3.0
144
+ rubygems_version: 3.3.3
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Automatic performance checking tool for Ruby code.