Sha256: 5951895600ff076ca36238defd473e429dcb561f536dbf4613229b40cdb16ae6

Contents?: true

Size: 851 Bytes

Versions: 2

Compression:

Stored size: 851 Bytes

Contents

require_relative '../cli/silencer'

Reek::CLI::Silencer.silently stderr: true, stdout: true do
  require 'unparser'
end

module Reek
  module AST
    #
    # Formats snippets of syntax tree back into Ruby source code.
    #
    # @api private
    class SexpFormatter
      # Formats the given sexp.
      #
      # @param [AST::Node, #to_s] sexp - The expression to format
      #
      # @return [String] a formatted string representation.
      #
      # :reek:DuplicateMethodCall { max_calls: 2 } is ok for lines.first
      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-3.3.1 lib/reek/ast/sexp_formatter.rb
reek-3.3.0 lib/reek/ast/sexp_formatter.rb