rubocop 1.57.0 → 1.57.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 +4 -4
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +9 -5
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +21 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +32 -12
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d38c0bf9376bd86de4bdf5561b74b11e895bc90ac263a8c29520afec2fb7d0b0
         | 
| 4 | 
            +
              data.tar.gz: 5e624dd813953b2058306d07986c19d55fa170fa8f3960844c4d62f2f87b3277
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dee188b376a118be4c08956361312fc91bf4e55cdadfa8129611f8a3b19fef80fb8241658778a5f6fb042336ba4137c6c64d2a65189ad00567730934e3dcde74
         | 
| 7 | 
            +
              data.tar.gz: 4dbf33a643a4f945d3564426b49338d463a55e734812d8c3113df04aa430577c2142b7685990bdd12915e537a1add4b181dd96488632dd89a544a33c5f712944
         | 
| @@ -182,7 +182,7 @@ module RuboCop | |
| 182 182 | 
             
                      return unless rhs.source.start_with?('.', '&.')
         | 
| 183 183 |  | 
| 184 184 | 
             
                      node = semantic_alignment_node(node)
         | 
| 185 | 
            -
                      return unless node&.loc&.selector
         | 
| 185 | 
            +
                      return unless node&.loc&.selector && node.loc.dot
         | 
| 186 186 |  | 
| 187 187 | 
             
                      node.loc.dot.join(node.loc.selector)
         | 
| 188 188 | 
             
                    end
         | 
| @@ -227,7 +227,11 @@ module RuboCop | |
| 227 227 | 
             
                      return unless (block_node = node.each_descendant(:block, :numblock).first)
         | 
| 228 228 | 
             
                      return unless block_node.multiline? && block_node.parent.call_type?
         | 
| 229 229 |  | 
| 230 | 
            -
                       | 
| 230 | 
            +
                      if node.receiver.call_type?
         | 
| 231 | 
            +
                        node.receiver
         | 
| 232 | 
            +
                      else
         | 
| 233 | 
            +
                        block_node.parent
         | 
| 234 | 
            +
                      end
         | 
| 231 235 | 
             
                    end
         | 
| 232 236 |  | 
| 233 237 | 
             
                    def first_call_has_a_dot(node)
         | 
| @@ -4,8 +4,8 @@ module RuboCop | |
| 4 4 | 
             
              module Cop
         | 
| 5 5 | 
             
                module Lint
         | 
| 6 6 | 
             
                  # Checks for redundant safe navigation calls.
         | 
| 7 | 
            -
                  # Use cases where a constant is `nil` are rare | 
| 8 | 
            -
                  # when the receiver is a constant.
         | 
| 7 | 
            +
                  # Use cases where a constant, named in camel case for classes and modules is `nil` are rare,
         | 
| 8 | 
            +
                  # and an offense is not detected when the receiver is a snake case constant.
         | 
| 9 9 | 
             
                  #
         | 
| 10 10 | 
             
                  # For all receivers, the `instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`,
         | 
| 11 11 | 
             
                  # and `equal?` methods are checked by default.
         | 
| @@ -26,7 +26,7 @@ module RuboCop | |
| 26 26 | 
             
                  #
         | 
| 27 27 | 
             
                  # @example
         | 
| 28 28 | 
             
                  #   # bad
         | 
| 29 | 
            -
                  #    | 
| 29 | 
            +
                  #   CamelCaseConst&.do_something
         | 
| 30 30 | 
             
                  #
         | 
| 31 31 | 
             
                  #   # bad
         | 
| 32 32 | 
             
                  #   do_something if attrs&.respond_to?(:[])
         | 
| @@ -40,7 +40,7 @@ module RuboCop | |
| 40 40 | 
             
                  #   end
         | 
| 41 41 | 
             
                  #
         | 
| 42 42 | 
             
                  #   # good
         | 
| 43 | 
            -
                  #    | 
| 43 | 
            +
                  #   CamelCaseConst.do_something
         | 
| 44 44 | 
             
                  #
         | 
| 45 45 | 
             
                  #   # good
         | 
| 46 46 | 
             
                  #   while node.is_a?(BeginNode)
         | 
| @@ -67,13 +67,16 @@ module RuboCop | |
| 67 67 |  | 
| 68 68 | 
             
                    NIL_SPECIFIC_METHODS = (nil.methods - Object.new.methods).to_set.freeze
         | 
| 69 69 |  | 
| 70 | 
            +
                    SNAKE_CASE = /\A[[:digit:][:upper:]_]+\z/.freeze
         | 
| 71 | 
            +
             | 
| 70 72 | 
             
                    # @!method respond_to_nil_specific_method?(node)
         | 
| 71 73 | 
             
                    def_node_matcher :respond_to_nil_specific_method?, <<~PATTERN
         | 
| 72 74 | 
             
                      (csend _ :respond_to? (sym %NIL_SPECIFIC_METHODS))
         | 
| 73 75 | 
             
                    PATTERN
         | 
| 74 76 |  | 
| 77 | 
            +
                    # rubocop:disable Metrics/AbcSize
         | 
| 75 78 | 
             
                    def on_csend(node)
         | 
| 76 | 
            -
                      unless node.receiver.const_type?
         | 
| 79 | 
            +
                      unless node.receiver.const_type? && !node.receiver.source.match?(SNAKE_CASE)
         | 
| 77 80 | 
             
                        return unless check?(node) && allowed_method?(node.method_name)
         | 
| 78 81 | 
             
                        return if respond_to_nil_specific_method?(node)
         | 
| 79 82 | 
             
                      end
         | 
| @@ -81,6 +84,7 @@ module RuboCop | |
| 81 84 | 
             
                      range = range_between(node.loc.dot.begin_pos, node.source_range.end_pos)
         | 
| 82 85 | 
             
                      add_offense(range) { |corrector| corrector.replace(node.loc.dot, '.') }
         | 
| 83 86 | 
             
                    end
         | 
| 87 | 
            +
                    # rubocop:enable Metrics/AbcSize
         | 
| 84 88 |  | 
| 85 89 | 
             
                    private
         | 
| 86 90 |  | 
| @@ -27,10 +27,11 @@ module RuboCop | |
| 27 27 |  | 
| 28 28 | 
             
                    # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
         | 
| 29 29 | 
             
                    def on_hash(node)
         | 
| 30 | 
            -
                      return if  | 
| 30 | 
            +
                      return if node.pairs.empty? || node.pairs.any?(&:hash_rocket?)
         | 
| 31 31 | 
             
                      return unless (parent = node.parent)
         | 
| 32 | 
            -
                      return unless (kwsplat = node.each_ancestor(:kwsplat).first)
         | 
| 33 32 | 
             
                      return if parent.call_type? && !merge_method?(parent)
         | 
| 33 | 
            +
                      return unless (kwsplat = node.each_ancestor(:kwsplat).first)
         | 
| 34 | 
            +
                      return if allowed_double_splat_receiver?(kwsplat)
         | 
| 34 35 |  | 
| 35 36 | 
             
                      add_offense(kwsplat) do |corrector|
         | 
| 36 37 | 
             
                        autocorrect(corrector, node, kwsplat)
         | 
| @@ -40,6 +41,14 @@ module RuboCop | |
| 40 41 |  | 
| 41 42 | 
             
                    private
         | 
| 42 43 |  | 
| 44 | 
            +
                    def allowed_double_splat_receiver?(kwsplat)
         | 
| 45 | 
            +
                      return false unless kwsplat.children.first.call_type?
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      root_receiver = root_receiver(kwsplat.children.first)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                      !root_receiver&.hash_type?
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
             | 
| 43 52 | 
             
                    def autocorrect(corrector, node, kwsplat)
         | 
| 44 53 | 
             
                      corrector.remove(kwsplat.loc.operator)
         | 
| 45 54 | 
             
                      corrector.remove(opening_brace(node))
         | 
| @@ -51,6 +60,15 @@ module RuboCop | |
| 51 60 | 
             
                      autocorrect_merge_methods(corrector, merge_methods, kwsplat)
         | 
| 52 61 | 
             
                    end
         | 
| 53 62 |  | 
| 63 | 
            +
                    def root_receiver(node)
         | 
| 64 | 
            +
                      receiver = node.receiver
         | 
| 65 | 
            +
                      if receiver&.receiver
         | 
| 66 | 
            +
                        root_receiver(receiver)
         | 
| 67 | 
            +
                      else
         | 
| 68 | 
            +
                        receiver
         | 
| 69 | 
            +
                      end
         | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
             | 
| 54 72 | 
             
                    def select_merge_method_nodes(kwsplat)
         | 
| 55 73 | 
             
                      extract_send_methods(kwsplat).select do |node|
         | 
| 56 74 | 
             
                        merge_method?(node)
         | 
| @@ -84,7 +102,7 @@ module RuboCop | |
| 84 102 | 
             
                    end
         | 
| 85 103 |  | 
| 86 104 | 
             
                    def extract_send_methods(kwsplat)
         | 
| 87 | 
            -
                       | 
| 105 | 
            +
                      kwsplat.each_descendant(:send, :csend)
         | 
| 88 106 | 
             
                    end
         | 
| 89 107 |  | 
| 90 108 | 
             
                    def convert_to_new_arguments(node)
         | 
| @@ -5,17 +5,21 @@ module RuboCop | |
| 5 5 | 
             
                module Style
         | 
| 6 6 | 
             
                  # Checks for RuntimeError as the argument of raise/fail.
         | 
| 7 7 | 
             
                  #
         | 
| 8 | 
            -
                  # It checks for code like this:
         | 
| 9 | 
            -
                  #
         | 
| 10 8 | 
             
                  # @example
         | 
| 11 | 
            -
                  #   #  | 
| 9 | 
            +
                  #   # bad
         | 
| 12 10 | 
             
                  #   raise RuntimeError, 'message'
         | 
| 13 | 
            -
                  #
         | 
| 14 | 
            -
                  #   # Bad
         | 
| 15 11 | 
             
                  #   raise RuntimeError.new('message')
         | 
| 16 12 | 
             
                  #
         | 
| 17 | 
            -
                  #   #  | 
| 13 | 
            +
                  #   # good
         | 
| 18 14 | 
             
                  #   raise 'message'
         | 
| 15 | 
            +
                  #
         | 
| 16 | 
            +
                  #   # bad - message is not a string
         | 
| 17 | 
            +
                  #   raise RuntimeError, Object.new
         | 
| 18 | 
            +
                  #   raise RuntimeError.new(Object.new)
         | 
| 19 | 
            +
                  #
         | 
| 20 | 
            +
                  #   # good
         | 
| 21 | 
            +
                  #   raise Object.new.to_s
         | 
| 22 | 
            +
                  #
         | 
| 19 23 | 
             
                  class RedundantException < Base
         | 
| 20 24 | 
             
                    extend AutoCorrector
         | 
| 21 25 |  | 
| @@ -30,26 +34,42 @@ module RuboCop | |
| 30 34 | 
             
                      fix_exploded(node) || fix_compact(node)
         | 
| 31 35 | 
             
                    end
         | 
| 32 36 |  | 
| 37 | 
            +
                    private
         | 
| 38 | 
            +
             | 
| 33 39 | 
             
                    def fix_exploded(node)
         | 
| 34 40 | 
             
                      exploded?(node) do |command, message|
         | 
| 35 41 | 
             
                        add_offense(node, message: MSG_1) do |corrector|
         | 
| 36 | 
            -
                           | 
| 37 | 
            -
                            corrector.replace(node, "#{command}(#{message.source})")
         | 
| 38 | 
            -
                          else
         | 
| 39 | 
            -
                            corrector.replace(node, "#{command} #{message.source}")
         | 
| 40 | 
            -
                          end
         | 
| 42 | 
            +
                          corrector.replace(node, replaced_exploded(node, command, message))
         | 
| 41 43 | 
             
                        end
         | 
| 42 44 | 
             
                      end
         | 
| 43 45 | 
             
                    end
         | 
| 44 46 |  | 
| 47 | 
            +
                    def replaced_exploded(node, command, message)
         | 
| 48 | 
            +
                      arg = string_message?(message) ? message.source : "#{message.source}.to_s"
         | 
| 49 | 
            +
                      arg = node.parenthesized? ? "(#{arg})" : " #{arg}"
         | 
| 50 | 
            +
                      "#{command}#{arg}"
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    def string_message?(message)
         | 
| 54 | 
            +
                      message.str_type? || message.dstr_type? || message.xstr_type?
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
             | 
| 45 57 | 
             
                    def fix_compact(node)
         | 
| 46 58 | 
             
                      compact?(node) do |new_call, message|
         | 
| 47 59 | 
             
                        add_offense(node, message: MSG_2) do |corrector|
         | 
| 48 | 
            -
                          corrector.replace(new_call, message | 
| 60 | 
            +
                          corrector.replace(new_call, replaced_compact(message))
         | 
| 49 61 | 
             
                        end
         | 
| 50 62 | 
             
                      end
         | 
| 51 63 | 
             
                    end
         | 
| 52 64 |  | 
| 65 | 
            +
                    def replaced_compact(message)
         | 
| 66 | 
            +
                      if string_message?(message)
         | 
| 67 | 
            +
                        message.source
         | 
| 68 | 
            +
                      else
         | 
| 69 | 
            +
                        "#{message.source}.to_s"
         | 
| 70 | 
            +
                      end
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
             | 
| 53 73 | 
             
                    # @!method exploded?(node)
         | 
| 54 74 | 
             
                    def_node_matcher :exploded?, <<~PATTERN
         | 
| 55 75 | 
             
                      (send nil? ${:raise :fail} (const {nil? cbase} :RuntimeError) $_)
         | 
    
        data/lib/rubocop/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rubocop
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.57. | 
| 4 | 
            +
              version: 1.57.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Bozhidar Batsov
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire:
         | 
| 11 11 | 
             
            bindir: exe
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2023-10- | 
| 13 | 
            +
            date: 2023-10-13 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: base64
         |