class RuboCop::Cop::InternalAffairs::StyleDetectedApiUse
end
add_offense(node) if offense?
def on_send(node)
end
end
correct_style_detected
else
opposite_style_detected
add_offense(node)
if offense?
def on_send(node)
# good
end
opposite_style_detected
add_offense(node)
return unless offense?
def on_send(node)
end
end
correct_style_detected
else
add_offense(node)
if offense?
def on_send(node)
end
correct_style_detected
return add_offense(node) if opposite_style_detected
def on_send(node)
# bad
@example
should not be used as predicates either.
used too, and vice versa. The ‘xxx_style_detected` methods
`unrecognized_style_detected` or `no_acceptable_style!` should be
`ambiguous_style_detected`, `conflicting_styles_detected`,
then `opposite_style_detected`, `unexpected_style_detected`,
`ConfigurableEnforcedStyle`. If `correct_style_detected` is used
Checks for correct use of the style_detected API provided by
def negative_without_positive?
def negative_without_positive? negative_style_detected_methods_called && !correct_style_detected_called end
def on_if(node)
def on_if(node) traverse_condition(node.condition) do |cond| add_offense(cond, message: MSG_FOR_CONDITIONAL_USE) if style_detected_api_used?(cond) end end
def on_investigation_end
def on_investigation_end return if style_detected_called return unless correct_style_detected_called ^ negative_style_detected_methods_called add_global_offense(MSG_FOR_POSITIVE_WITHOUT_NEGATIVE) if positive_without_negative? add_global_offense(MSG_FOR_NEGATIVE_WITHOUT_POSITIVE) if negative_without_positive? end
def on_new_investigation
def on_new_investigation @correct_style_detected_called = false @negative_style_detected_methods_called = false @style_detected_called = false end
def on_send(node)
def on_send(node) if correct_style_detected_check(node) @correct_style_detected_called = true elsif negative_style_detected_method_check(node) || no_acceptable_style_check(node) @negative_style_detected_methods_called = true elsif style_detected_check(node) @style_detected_called = true end end
def positive_without_negative?
def positive_without_negative? correct_style_detected_called && !negative_style_detected_methods_called end
def style_detected_api_used?(node)
def style_detected_api_used?(node) correct_style_detected_check(node) || negative_style_detected_method_check(node) || no_acceptable_style_check(node) || style_detected_check(node) end
def traverse_condition(condition, &block)
def traverse_condition(condition, &block) yield condition if condition.send_type? condition.each_child_node { |child| traverse_condition(child, &block) } end