class RuboCop::Cop::Style::MissingElse
end
# the content of ‘else` branch will be determined by Style/EmptyElse
else
statement
when condition
case var
# good
end
# the content of `else` branch will be determined by Style/EmptyElse
else
statement
if condition
# good
end
statement
when condition
case var
# bad
end
statement
if condition
# bad
# warn when an `if` or `case` expression is missing an `else` branch.
@example EnforcedStyle: both (default)
end
# the content of `else` branch will be determined by Style/EmptyElse
else
statement
if condition
# good
end
statement
if condition
# good
end
# the content of `else` branch will be determined by Style/EmptyElse
else
statement
when condition
case var
# good
end
statement
when condition
case var
# bad
# warn when a `case` expression is missing an `else` branch.
@example EnforcedStyle: case
end
# the content of `else` branch will be determined by Style/EmptyElse
else
statement
when condition
case var
# good
end
statement
when condition
case var
# good
end
# the content of `else` branch will be determined by Style/EmptyElse
else
statement
if condition
# good
end
statement
if condition
# bad
# warn when an `if` expression is missing an `else` branch.
@example EnforcedStyle: if
Supported styles are: if, case, both.
Checks for `if` expressions that do not have an `else` branch.
def case_style?
def case_style? style == :case end
def check(node)
def check(node) return if node.else? if empty_else_cop_enabled? if empty_else_style == :empty add_offense(node) elsif empty_else_style == :nil add_offense(node) end end add_offense(node) end
def empty_else_config
def empty_else_config config.for_cop('Style/EmptyElse') end
def empty_else_cop_enabled?
def empty_else_cop_enabled? empty_else_config.fetch('Enabled') end
def empty_else_style
def empty_else_style return unless empty_else_config.key?('EnforcedStyle') empty_else_config['EnforcedStyle'].to_sym end
def if_style?
def if_style? style == :if end
def message(node)
def message(node) template = case empty_else_style when :empty MSG_NIL when :nil MSG_EMPTY else MSG end format(template, type: node.type) end
def on_case(node)
def on_case(node) return if if_style? check(node) end
def on_normal_if_unless(node)
def on_normal_if_unless(node) return if case_style? return if unless_else_cop_enabled? && node.unless? check(node) end
def unless_else_config
def unless_else_config config.for_cop('Style/UnlessElse') end
def unless_else_cop_enabled?
def unless_else_cop_enabled? unless_else_config.fetch('Enabled') end