Class: RuboCop::Cop::Homebrew::SimpleTernary Private

Inherits:
Base
  • Object
show all
Includes:
SimpleExpression
Defined in:
rubocops/simple_ternary.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Keep the condition and both branches of a ternary simple.

Examples:

# bad
ready? && enabled? ? queue : fallback

# good
if ready? && enabled?
  queue
else
  fallback
end

Constant Summary collapse

MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"Use `if`/`else` for this complex ternary."

Constants included from SimpleExpression

RuboCop::Cop::Homebrew::SimpleExpression::MAX_VALUE_PARTS

Instance Method Summary collapse

Methods included from SimpleExpression

#integer_literal?, #literal_or_reference?, #static_expression?

Instance Method Details

#on_if(node) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::IfNode)


27
28
29
30
31
32
33
# File 'rubocops/simple_ternary.rb', line 27

def on_if(node)
  return unless node.ternary?

  node.each_child_node do |part|
    add_offense(part) if excessive_logic?(part)
  end
end