Sha256: 6f3052a8e57c421a0d665f39ad98c4177aec0b33a399ac60c8143da51fcc9264
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Style # This cop check for uses of Object#freeze on immutable objects. # # @example # # bad # CONST = 1.freeze # # # good # CONST = 1 class RedundantFreeze < Cop include FrozenStringLiteral MSG = 'Do not freeze immutable objects, as freezing them has no ' \ 'effect.'.freeze def on_send(node) return unless node.receiver && node.method?(:freeze) && immutable_literal?(node.receiver) add_offense(node, :expression) end def autocorrect(node) lambda do |corrector| corrector.remove(node.loc.dot) corrector.remove(node.loc.selector) end end private def immutable_literal?(node) return true if node.immutable_literal? FROZEN_STRING_LITERAL_TYPES.include?(node.type) && frozen_string_literals_enabled? end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems