Why this matters
Global variables create hidden dependencies, making code harder to debug, maintain, and test. Use instance variables or constants instead.
Check for global variable usage (e.g., variables prefixed with `$`). Suggest using instance variables, constants, or dependency injection instead.
Global variables create hidden dependencies, making code harder to debug, maintain, and test. Use instance variables or constants instead.
Side-by-side examples engineers can pattern-match during review.
$counter = 0
def increment
$counter += 1
endclass Counter
def initialize
@counter = 0
end
def increment
@counter += 1
end
end
$counter = 0
def increment
$counter += 1
endclass Counter
def initialize
@counter = 0
end
def increment
@counter += 1
end
end
From the same buckets as this rule.