class RuboCop::Cop::Lint::OrAssignmentToConstant

Checks for unintended or-assignment to a constant.

Constants should always be assigned in the same location. And its value should always be the same. If constants are assigned in multiple locations, the result may vary depending on the order of `require`.

@safety

This cop is unsafe because code that is already conditionally
assigning a constant may have its behavior changed by autocorrection.

@example

# bad
CONST ||= 1

# good
CONST = 1

Constants

MSG

Public Instance Methods

on_or_asgn(node) click to toggle source
# File lib/rubocop/cop/lint/or_assignment_to_constant.rb, line 29
def on_or_asgn(node)
  lhs, _rhs = *node
  return unless lhs&.casgn_type?

  add_offense(node.loc.operator) do |corrector|
    corrector.replace(node.loc.operator, '=')
  end
end