class Rufo::Formatter
def initialize(code, **options)
def initialize(code, **options) @code = code @tokens = Ripper.lex(code).reverse! @sexp = Ripper.sexp(code) unless @sexp raise ::Rufo::SyntaxError.new end @indent = 0 @line = 0 @column = 0 @last_was_newline = false @output = "" # The column of a `obj.method` call, so we can align # calls to that dot @dot_column = nil # Heredocs list, associated with calls ([heredoc, tilde]) @heredocs = [] # Current node, to be able to associate it to heredocs @current_node = nil # The current heredoc being printed @current_heredoc = nil # The current hash or call or method that has hash-like parameters @current_hash = nil # Position of comments that occur at the end of a line @comments_positions = [] # Associate a line to an index inside @comments_position # becuase when aligning something to the left of a comment # we need to adjust the relative comment @line_to_comments_position_index = {} # Position of assignments @assignments_positions = [] # Hash keys positions @hash_keys_positions = [] # Settings @indent_size = options.fetch(:indent_size, 2) @align_comments = options.fetch(:align_comments, true) @align_assignments = options.fetch(:align_assignments, true) @align_hash_keys = options.fetch(:align_hash_keys, true) end