Skip to content

class Crystal::Formatter
inherits Crystal::Visitor

Class methods

.format(source, filename = nil)

View source

.new(source)

View source

Methods

#abstract_def?(node)

View source

#accept_assign_value(value, check_align = false)

View source

#accept_assign_value_after_equals(value, check_align = false)

View source

#align_comment(line, i, comment_column, max_column)

View source

#align_comments(lines)

Align series of successive comments

View source

#align_info(lines, info, max_size)

View source

#align_infos(lines, align_infos)

Align series of successive inline when/else (in a case), or hash literals (the left side of the =>)

View source

#assign?(exp)

View source

#assign_length(exp)

View source

#at_skip?

The parser transforms def foo(@x); end to def foo(x); @x = x; end so if we find an instance var we later need to skip the first expressions in the body

View source

#check(*token_types)

View source

#check_assign_align(before_column, exp)

View source

#check_assign_length(exp)

View source

#check_close_paren

View source

#check_end

View source

#check_hash_info(hash, key, start_line, start_column, middle_column)

View source

#check_keyword(*keywords)

View source

#check_macro_whitespace

View source

#check_open_paren

View source

#clear_object(node)

View source

#consume_newlines(next_comes_end = false)

View source

#decrement_line

View source

#end_visit_any(node)

View source

#find_assign_chunk(expressions, last, i)

View source

#find_last_info(align_infos, base, i)

View source

#find_max_column(lines, base, max)

View source

#finish

View source

#finish_args(has_parentheses, has_newlines, ends_with_newline, found_comment, column)

View source

#finish_list(suffix, has_newlines, found_comment, found_first_newline, write_space_at_end)

View source

#fix_heredocs(lines, heredoc_fixes)

View source

#format_alias_or_typedef(node, keyword, value)

View source

#format_args(args : Array, has_parentheses, named_args = nil, block_arg = nil, needed_indent = @indent + 2, do_consume_newlines = false)

View source

#format_args_simple(args, needed_indent, do_consume_newlines)

View source

#format_binary(node, token, alternative)

View source

#format_block(node, needs_space)

View source

#format_block_arg(block_arg, needed_indent)

View source

#format_block_args(args, node)

View source

#format_call_args(node : ASTNode, has_parentheses, base_indent)

View source

#format_control_expression(node, keyword)

View source

#format_def_arg

View source

#format_def_args(node : Def | Macro)

View source

#format_def_args(args : Array, block_arg, splat_index, variadic, double_splat)

View source

#format_doc_comments(lines)

View source

#format_elsif(node_else, keyword)

View source

#format_end(column)

View source

#format_hash_entry(hash, entry)

View source

#format_if_at_cond(node, keyword, check_end = true)

View source

#format_literal_elements(elements, prefix, suffix)

View source

#format_macro_body(node)

View source

#format_macro_contents(node, macro_node_line)

View source

#format_macro_end

View source

#format_macro_if_epilogue(node, macro_state, check_end = true)

View source

#format_multi_assign_values(values)

View source

#format_named_args(args, named_args, needed_indent)

View source

#format_named_argument_name(name)

View source

#format_named_tuple_entry(hash, entry)

View source

#format_nested(node, indent = @indent, write_end_line = true, write_indent = true)

View source

#format_nested_with_end(node, column = @indent, write_end_line = true)

View source

#format_parenthesized_args(args, named_args = nil)

View source

#format_regex_modifiers

View source

#format_type_vars(type_vars, splat_index)

View source

#format_when(case_node, node, is_last, align_number)

View source

#format_while_or_until(node, keyword)

View source

#increment_line

View source

#increment_lines(count)

View source

#indent

View source

#indent(indent : Int

View source

#indent : Int32

View source

#indent(node : ASTNode)

View source

#indent=(indent)

View source

#inside_call_or_assign

View source

#inside_cond

View source

#inside_enum : Int32

View source

#inside_enum=(inside_enum)

View source

#inside_lib : Int32

View source

#inside_lib=(inside_lib)

View source

#inside_macro

View source

#inside_macro?

View source

#inside_struct_or_union : Int32

View source

#inside_struct_or_union=(inside_struct_or_union)

View source

#jump_semicolon

View source

#last?(index, collection)

View source

#needs_two_lines?(node, next_node)

View source

#needs_two_lines?(node)

View source

#next_macro_token

View source

#next_string_array_token

View source

#next_string_token

View source

#next_token

View source

#next_token_skip_space

View source

#next_token_skip_space_or_newline

View source

#no_indent(node : ASTNode)

View source

#no_indent

View source

#no_rstrip_lines : Set(Int32)

View source

#outside_macro

View source

#remove_to_skip(node, to_skip)

View source

#reset_macro_state

View source

#skip_semicolon

View source

#skip_semicolon_or_space

View source

#skip_semicolon_or_space_or_newline

View source

#skip_space(write_comma : Bool = false, consume_newline : Bool = true)

View source

#skip_space(indent : Int32, write_comma = false)

View source

#skip_space_or_newline(last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)

View source

#skip_space_or_newline(indent : Int32, last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)

View source

#skip_space_write_line

View source

#slash_is_not_regex!

View source

#slash_is_regex!

View source

#space_newline?

View source

#space_slash_newline?

View source

#subformat(source)

View source

#subformat_nesting : Int32

View source

#subformat_nesting=(subformat_nesting)

View source

#to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
View source

#vars=(vars)

View source

#visit(node : Union)

View source

#visit(node : If)

View source

#visit(node : Unless)

View source

#visit(node : While)

View source

#visit(node : MacroIf)

View source

#visit(node : MacroExpression)

View source

#visit(node : Until)

View source

#visit(node : Def)

View source

#visit(node : FunDef)

View source

#visit(node : MacroVerbatim)

View source

#visit(node : Macro)

View source

#visit(node : SymbolLiteral)

View source

#visit(node : Generic)

View source

#visit(node : CharLiteral)

View source

#visit(node : NumberLiteral)

View source

#visit(node : BoolLiteral)

View source

#visit(node : NilLiteral)

View source

#visit(node : Nop)

View source

#visit(node : Expressions)

View source

#visit(node : StringLiteral)

View source

#visit(node : RegexLiteral)

View source

#visit(node : ArrayLiteral)

View source

#visit(node : TupleLiteral)

View source

#visit(node : HashLiteral)

View source

#visit(node : RangeLiteral)

View source

#visit(node : Path)

View source

#visit(node : MacroFor)

View source

#visit(node : MacroVar)

View source

#visit(node : InstanceSizeOf)

View source

#visit(node : OffsetOf)

View source

#visit(node : PointerOf)

View source

#visit(node : Underscore)

View source

#visit(node : MultiAssign)

View source

#visit(node : Alias)

View source

#visit(node : TypeDef)

View source

#visit(node : ProcPointer)

View source

#visit(node : ProcLiteral)

View source

#visit(node : ExternalVar)

View source

#visit(node : Out)

View source

#visit(node : Metaclass)

View source

#visit(node : Block)

View source

#visit(node : When)

View source

#visit(node : SizeOf)

View source

#visit(node : TypeOf)

View source

#visit(node : Include)

View source

#visit(node : Extend)

View source

#visit(node : LibDef)

View source

#visit(node : EnumDef)

View source

#visit(node : TypeDeclaration)

View source

#visit(node : Return)

View source

#visit(node : Break)

View source

#visit(node : Next)

View source

#visit(node : Yield)

View source

#visit(node : Case)

View source

#visit(node : ImplicitObj)

View source

#visit(node : Select)

View source

#visit(node : Annotation)

View source

#visit(node : Cast)

View source

#visit(node : NilableCast)

View source

#visit(node : Rescue)

View source

#visit(node : Asm)

View source

#visit(node : Assign)

View source

#visit(node : Not)

View source

#visit(node : And)

View source

#visit(node : Or)

View source

#visit(node : RespondsTo)

View source

#visit(node : IsA)

View source

#visit(node : NamedArgument)

View source

#visit(node : Call)

View source

#visit(node : ReadInstanceVar)

View source

#visit(node : Global)

View source

#visit(node : ClassVar)

View source

#visit(node : InstanceVar)

View source

#visit(node : Var)

View source

#visit(node : Self)

View source

#visit(node : ProcNotation)

View source

#visit(node : DoubleSplat)

View source

#visit(node : Splat)

View source

#visit(node : Arg)

View source

#visit(node : OpAssign)

View source

#visit(node : MacroLiteral)

View source

#visit(node : AsmOperand)

View source

#visit(node : ASTNode)

View source

#visit(node : FileNode)

View source

#visit(node : MacroId)

View source

#visit(node : MetaVar)

View source

#visit(node : Require)

View source

#visit(node : ClassDef)

View source

#visit(node : MagicConstant)

View source

#visit(node : ModuleDef)

View source

#visit(node : AnnotationDef)

View source

#visit_asm_parts(parts, colon_column, &) : Nil

View source

#visit_if_or_unless(node, keyword)

View source

#visit_splat(node, token)

View source

#visit_string_interpolation(node, token, line, column, old_indent, old_string_continuation, wrote_token = false)

View source

#write(obj)

View source

#write(string : String)

View source

#write_comment(needs_indent = true, consume_newline = true, next_comes_end = false)

View source

#write_indent(indent, node)

View source

#write_indent(indent)

View source

#write_indent

View source

#write_indent

View source

#write_keyword(keyword : Symbol)

View source

#write_keyword(before : String, keyword : Symbol)

View source

#write_keyword(before : String, keyword : Symbol, after : String)

View source

#write_keyword(keyword : Symbol, after : String, skip_space_or_newline = true)

View source

#write_line

View source

#write_token(before : String, type : Symbol, after : String)

View source

#write_token(before : String, type : Symbol)

View source

#write_token(type : Symbol, after : String)

View source

#write_token(type : Symbol)

View source