Class: RuboCop::Node::Builder

Inherits:
Parser::Builders::Default
  • Object
show all
Defined in:
lib/rubocop/ast_node/builder.rb

Overview

‘RuboCop::Builder` is an AST builder that is utilized to let `Parser` generate ASTs with RuboCop::Node.

Examples:

buffer = Parser::Source::Buffer.new('(string)')
buffer.source = 'puts :foo'

builder = RuboCop::Builder.new
parser = Parser::CurrentRuby.new(builder)
root_node = parser.parse(buffer)

Instance Method Summary collapse

Instance Method Details

#n(type, children, source_map) ⇒ Node

Generates RuboCop::Node from the given information.

Returns:

  • (Node)

    the generated node



20
21
22
# File 'lib/rubocop/ast_node/builder.rb', line 20

def n(type, children, source_map)
  Node.new(type, children, location: source_map)
end

#string_value(token) ⇒ Object

TODO: Figure out what to do about literal encoding handling… More details here github.com/whitequark/parser/issues/283



26
27
28
# File 'lib/rubocop/ast_node/builder.rb', line 26

def string_value(token)
  value(token)
end