Sha256: d0e8c662140835581a7f3f7d0c3d6c2fa8280423d5607bc2806b7b8d743e4941

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Before Ruby 3.0, interpolated strings followed the frozen string literal
      # magic comment which sometimes made it necessary to explicitly unfreeze them.
      # Ruby 3.0 changed interpolated strings to always be unfrozen which makes
      # unfreezing them redundant.
      #
      # @example
      #   # bad
      #   +"#{foo} bar"
      #
      #   # bad
      #   "#{foo} bar".dup
      #
      #   # good
      #   "#{foo} bar"
      #
      class RedundantInterpolationUnfreeze < Base
        include FrozenStringLiteral
        extend AutoCorrector
        extend TargetRubyVersion

        MSG = "Don't unfreeze interpolated strings as they are already unfrozen."

        RESTRICT_ON_SEND = %i[+@ dup].freeze

        minimum_target_ruby_version 3.0

        def on_send(node)
          return if node.arguments?
          return unless (receiver = node.receiver)
          return unless receiver.dstr_type?
          return if uninterpolated_string?(receiver) || uninterpolated_heredoc?(receiver)

          add_offense(node.loc.selector) do |corrector|
            corrector.remove(node.loc.selector)
            corrector.remove(node.loc.dot) unless node.unary_operation?
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.69.2 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.69.1 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.69.0 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.68.0 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.67.0 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb
rubocop-1.66.1 lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb