Class: Tailor::Rulers::IndentationSpacesRuler::ArgumentAlignment

Inherits:
Object
  • Object
show all
Includes:
AstXml
Defined in:
lib/tailor/rulers/indentation_spaces_ruler/argument_alignment.rb

Overview

Determines whether arguments spread across lines are correctly aligned.

Function calls with parentheses could be determined easily from the lexed line only but we need to support calls without parentheses too.

Instance Method Summary collapse

Methods included from AstXml

#ast_hash_node?, #ast_node_has_children?, #build_xml, #position_node?, #xml_array_node, #xml_create_node, #xml_document, #xml_hash_node, #xml_position_node

Constructor Details

#initialize(file_name) ⇒ ArgumentAlignment

Returns a new instance of ArgumentAlignment.



18
19
20
21
# File 'lib/tailor/rulers/indentation_spaces_ruler/argument_alignment.rb', line 18

def initialize(file_name)
  @ast = build_xml(Ripper::SexpBuilder.new(File.read(file_name)).parse)
  @lex = Ripper.lex(File.read(file_name))
end

Instance Method Details

#expected_column(lineno, should_be_at) ⇒ Object



23
24
25
26
# File 'lib/tailor/rulers/indentation_spaces_ruler/argument_alignment.rb', line 23

def expected_column(lineno, should_be_at)
  column = call_column(lineno) || declaration_column(lineno)
  correct_for_literals(lineno, column) || should_be_at
end