rubocop-performance 1.20.0 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afce4fa4bdd79fa5f4429edcdb3fa157f94be3f2526630db7d342c56fd5d741b
4
- data.tar.gz: 833a0a5c44c55a7e30640c7658f54e5a28c5a362add04c60b434fa9f58b61136
3
+ metadata.gz: 1687f31268dd621e7a4e82fb11b5ae6927f208936df7b7136b5a80a1d4cfe547
4
+ data.tar.gz: f8bf3aaa6084017f9aa368440e57f3e752f203d801132b8cad848634dd5ecb3d
5
5
  SHA512:
6
- metadata.gz: 62dea0dda6f9fc634e7d7d418ba980bb106d698db3d7242da2c81c9abc49124748dc553bf413e9281fe6969d1b29ef991d58e2e2a6211c759f27cbe36a99cfe4
7
- data.tar.gz: 046a795365aa47793e3afa36cc0685cc44851573210669945a8b6bda73d8edcb38ca6acc522d17009ea722a6c84e68c21ddc759181ba1840cac7c566e76b0220
6
+ metadata.gz: 7d5e072526c9a1ef7f5636b24845ec09b83548a1e06cf6b12b6b5cabdf4524d536dbc06e3e007f344a2584a6014d29ae19f29be80574a730b88b961d7f33d358
7
+ data.tar.gz: f10756696005feffe81f9bd471f52f11d69ac193036f65bffe5be7e4d1bb0a95990ccfa9a6278b2128377efc4d2097a74e5b8f896f56ac7c12856f78b9447a83
@@ -34,6 +34,12 @@ module RuboCop
34
34
  protected public public_constant module_function
35
35
  ].freeze
36
36
 
37
+ TWO_ARGUMENTS_METHOD = :alias_method
38
+ MULTIPLE_ARGUMENTS_METHODS = %i[
39
+ attr_accessor attr_reader attr_writer private private_constant
40
+ protected public public_constant module_function
41
+ ].freeze
42
+
37
43
  # NOTE: `attr` method is not included in this list as it can cause false positives in Nokogiri API.
38
44
  # And `attr` may not be used because `Style/Attr` registers an offense.
39
45
  # https://github.com/rubocop/rubocop-performance/issues/278
@@ -47,26 +53,42 @@ module RuboCop
47
53
  respond_to? send singleton_method __send__
48
54
  ] + COMMAND_METHODS).freeze
49
55
 
50
- # rubocop:disable Metrics/CyclomaticComplexity
51
56
  def on_send(node)
52
57
  return if COMMAND_METHODS.include?(node.method_name) && node.receiver
53
- return unless (first_argument = node.first_argument)
54
- return unless first_argument.str_type? || first_argument.dstr_type?
55
58
 
56
- first_argument_value = first_argument.value
57
- return if first_argument_value.include?(' ') || first_argument_value.include?('::')
59
+ string_arguments(node).each do |string_argument|
60
+ string_argument_value = string_argument.value
61
+ next if string_argument_value.include?(' ') || string_argument_value.include?('::')
62
+
63
+ register_offense(string_argument, string_argument_value)
64
+ end
65
+ end
58
66
 
59
- replacement = argument_replacement(first_argument, first_argument_value)
67
+ private
60
68
 
61
- message = format(MSG, symbol_arg: replacement, string_arg: first_argument.source)
69
+ def string_arguments(node)
70
+ arguments = if node.method?(TWO_ARGUMENTS_METHOD)
71
+ [node.first_argument, node.arguments[1]]
72
+ elsif MULTIPLE_ARGUMENTS_METHODS.include?(node.method_name)
73
+ node.arguments
74
+ else
75
+ [node.first_argument]
76
+ end
62
77
 
63
- add_offense(first_argument, message: message) do |corrector|
64
- corrector.replace(first_argument, replacement)
78
+ arguments.compact.filter do |argument|
79
+ argument.str_type? || argument.dstr_type?
65
80
  end
66
81
  end
67
- # rubocop:enable Metrics/CyclomaticComplexity
68
82
 
69
- private
83
+ def register_offense(argument, argument_value)
84
+ replacement = argument_replacement(argument, argument_value)
85
+
86
+ message = format(MSG, symbol_arg: replacement, string_arg: argument.source)
87
+
88
+ add_offense(argument, message: message) do |corrector|
89
+ corrector.replace(argument, replacement)
90
+ end
91
+ end
70
92
 
71
93
  def argument_replacement(node, value)
72
94
  if node.str_type?
@@ -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.20.0'
7
+ STRING = '1.20.1'
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.20.0
4
+ version: 1.20.1
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: 2023-12-16 00:00:00.000000000 Z
13
+ date: 2023-12-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop