Module: Rubocop::Cop::SafeAssignment

Included in:
Lint::AssignmentInCondition, Rubocop::Cop::Style::ParenthesesAroundCondition
Defined in:
lib/rubocop/cop/mixin/safe_assignment.rb

Overview

Common functionality for safe assignment. By safe assignment we mean putting parentheses around an assignment to indicate "I know I'm using an assignment as a condition. It's not a mistake."

Instance Method Summary collapse

Instance Method Details

#safe_assignment?(node) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/rubocop/cop/mixin/safe_assignment.rb', line 9

def safe_assignment?(node)
  node.type == :begin && node.children.size == 1 &&
    Util::EQUALS_ASGN_NODES.include?(node.children[0].type)
end

#safe_assignment_allowed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rubocop/cop/mixin/safe_assignment.rb', line 14

def safe_assignment_allowed?
  cop_config['AllowSafeAssignment']
end