Sha256: 06a91872ad86df481d8cb5e3ad01d03966e1556462d9810c3dcfc63d80d17058

Contents?: true

Size: 805 Bytes

Versions: 11

Compression:

Stored size: 805 Bytes

Contents

require_relative '../cli/silencer'

Reek::CLI::Silencer.silently do
  require 'unparser'
end

module Reek
  module AST
    #
    # Formats snippets of syntax tree back into Ruby source code.
    #
    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

11 entries across 11 versions & 1 rubygems

Version Path
reek-3.8.3 lib/reek/ast/sexp_formatter.rb
reek-3.8.2 lib/reek/ast/sexp_formatter.rb
reek-3.8.1 lib/reek/ast/sexp_formatter.rb
reek-3.8.0 lib/reek/ast/sexp_formatter.rb
reek-3.7.1 lib/reek/ast/sexp_formatter.rb
reek-3.7.0 lib/reek/ast/sexp_formatter.rb
reek-3.6.1 lib/reek/ast/sexp_formatter.rb
reek-3.6.0 lib/reek/ast/sexp_formatter.rb
reek-3.5.0 lib/reek/ast/sexp_formatter.rb
reek-3.4.1 lib/reek/ast/sexp_formatter.rb
reek-3.4.0 lib/reek/ast/sexp_formatter.rb