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:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1687f31268dd621e7a4e82fb11b5ae6927f208936df7b7136b5a80a1d4cfe547
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f8bf3aaa6084017f9aa368440e57f3e752f203d801132b8cad848634dd5ecb3d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
                    private
         
     | 
| 
       60 
68 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
       64 
     | 
    
         
            -
                         
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
      
 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?
         
     | 
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2023-12-25 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: rubocop
         
     |