Class: RuboCop::Cop::AutocorrectUnlessChangingAST::InlineBeginNodes

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb

Overview

'begin' nodes with a single child can be removed without changing the semantics of an AST. Canonicalizing an AST in this way can help us determine whether it has really changed in a meaningful way, or not. This means we can auto-correct in cases where we would otherwise refrain from doing so.

If any other simplifications can be done to an AST without changing its meaning, they should be added here (and the class renamed). This will make autocorrection more powerful across the board.

Instance Method Summary collapse

Instance Method Details

#on_begin(node) ⇒ Object



48
49
50
# File 'lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb', line 48

def on_begin(node)
  node.children.one? ? node.children[0] : node
end