class RuboCop::Cop::Style::RedundantFreeze
This cop check for uses of Object#freeze on immutable objects.
@example
# bad CONST = 1.freeze # good CONST = 1
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_freeze.rb, line 28 def autocorrect(node) lambda do |corrector| corrector.remove(node.loc.dot) corrector.remove(node.loc.selector) end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_freeze.rb, line 20 def on_send(node) return unless node.receiver && node.method?(:freeze) && (immutable_literal?(node.receiver) || operation_produces_immutable_object?(node.receiver)) add_offense(node) end
Private Instance Methods
immutable_literal?(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_freeze.rb, line 37 def immutable_literal?(node) node = strip_parenthesis(node) return true if node.immutable_literal? FROZEN_STRING_LITERAL_TYPES.include?(node.type) && frozen_string_literals_enabled? end
strip_parenthesis(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_freeze.rb, line 46 def strip_parenthesis(node) if node.begin_type? && node.children.first node.children.first else node end end