Sha256: ccd494f4f598b58892948716638637b866630fad4dc38020c8419a54e0f9fd34
Contents?: true
Size: 802 Bytes
Versions: 1
Compression:
Stored size: 802 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop # This module does auto-correction of nodes that could become grammatically # different after the correction. If the code change would alter the # abstract syntax tree, it is not done. module AutocorrectUnlessChangingAST def autocorrect(node) c = correction(node) new_source = rewrite_node(node) # Make the correction only if it doesn't change the AST. fail CorrectionNotPossible if node != SourceParser.parse(new_source).ast @corrections << c end def rewrite_node(node) processed_source = SourceParser.parse(node.loc.expression.source) c = correction(processed_source.ast) Corrector.new(processed_source.buffer, [c]).rewrite end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.22.0 | lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb |