Class: Reek::AST::SexpFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/ast/sexp_formatter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Formats snippets of syntax tree back into Ruby source code.

Class Method Summary collapse

Class Method Details

.format(sexp) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Formats the given sexp.

:reek:DuplicateMethodCall { max_calls: 2 } is ok for lines.first

Parameters:

  • sexp (AST::Node, #to_s)
    • The expression to format

Returns:

  • (String)

    a formatted string representation.



20
21
22
23
24
25
26
27
28
# File 'lib/reek/ast/sexp_formatter.rb', line 20

def self.format(sexp)
  return sexp.to_s unless sexp.is_a? ::Parser::AST::Node
  lines = Unparser.unparse(sexp).split "\n"
  case lines.length
  when 1 then lines.first
  when 2 then lines.join('; ')
  else [lines.first, lines.last].join(' ... ')
  end
end