lib/rubocop/cop/style/and_or.rb in rubocop-0.20.0 vs lib/rubocop/cop/style/and_or.rb in rubocop-0.20.1

- old
+ new

@@ -3,10 +3,12 @@ module Rubocop module Cop module Style # This cop checks for uses of *and* and *or*. class AndOr < Cop + include AutocorrectUnlessChangingAST + MSG = 'Use `%s` instead of `%s`.' OPS = { 'and' => '&&', 'or' => '||' } def on_and(node) @@ -26,23 +28,9 @@ if op == op_type add_offense(node, :operator, format(MSG, OPS[op], op)) end - end - - def autocorrect(node) - c = correction(node) - new_source = rewrite_node(node, c) - - # Make the correction only if it doesn't change the AST. - @corrections << c if node == SourceParser.parse(new_source).ast - end - - def rewrite_node(node, correction) - processed_source = SourceParser.parse(node.loc.expression.source) - c = correction(processed_source.ast) - Corrector.new(processed_source.buffer, [c]).rewrite end def correction(node) lambda do |corrector| replacement = (node.type == :and ? '&&' : '||')