Sha256: 9f6f11322fb126aaa02fb72597116cd140ef02f055747a849c5bbe77c2d8b246
Contents?: true
Size: 1.06 KB
Versions: 19
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # This cop 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 behaviour changed by # auto-correction. # # @example # # # bad # CONST ||= 1 # # # good # CONST = 1 # class OrAssignmentToConstant < Base extend AutoCorrector MSG = 'Avoid using or-assignment with constants.' 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 end end end end
Version data entries
19 entries across 19 versions & 4 rubygems