lib/rubocop/cop/style/negated_if.rb in rubocop-0.51.0 vs lib/rubocop/cop/style/negated_if.rb in rubocop-0.52.0

- old
+ new

@@ -8,94 +8,86 @@ # # - both # - prefix # - postfix # - # @example - # - # # EnforcedStyle: both + # @example EnforcedStyle: both (default) # # enforces `unless` for `prefix` and `postfix` conditionals # - # # good - # - # unless foo - # bar - # end - # # # bad # # if !foo # bar # end # # # good # - # bar unless foo + # unless foo + # bar + # end # # # bad # # bar if !foo # - # @example + # # good # - # # EnforcedStyle: prefix + # bar unless foo + # + # @example EnforcedStyle: prefix # # enforces `unless` for just `prefix` conditionals # - # # good + # # bad # - # unless foo + # if !foo # bar # end # - # # bad + # # good # - # if !foo + # unless foo # bar # end # # # good # # bar if !foo # - # @example - # - # # EnforcedStyle: postfix + # @example EnforcedStyle: postfix # # enforces `unless` for just `postfix` conditionals # - # # good - # - # bar unless foo - # # # bad # # bar if !foo # # # good # + # bar unless foo + # + # # good + # # if !foo # bar # end class NegatedIf < Cop include ConfigurableEnforcedStyle include NegativeConditional - MSG = 'Favor `%s` over `%s` for negative conditions.'.freeze - def on_if(node) return if node.elsif? || node.ternary? return if correct_style?(node) check_negative_conditional(node) end + def autocorrect(node) + negative_conditional_corrector(node) + end + private def message(node) - format(MSG, node.inverse_keyword, node.keyword) - end - - def autocorrect(node) - negative_conditional_corrector(node) + format(MSG, inverse: node.inverse_keyword, current: node.keyword) end def correct_style?(node) style == :prefix && node.modifier_form? || style == :postfix && !node.modifier_form?