class SyntaxTree::Formatter::Options

We want to minimize as much as possible the number of options that are available in syntax tree. For the most part, if users want non-default formatting, they should override the format methods on the specific nodes themselves. However, because of some history with prettier and the fact that folks have become entrenched in their ways, we decided to provide a small amount of configurability.

Attributes

disable_auto_ternary[R]
quote[R]
target_ruby_version[R]
trailing_comma[R]

Public Class Methods

new( quote: :default, trailing_comma: :default, disable_auto_ternary: :default, target_ruby_version: :default ) click to toggle source
# File lib/syntax_tree/formatter.rb, line 29
def initialize(
  quote: :default,
  trailing_comma: :default,
  disable_auto_ternary: :default,
  target_ruby_version: :default
)
  @quote =
    if quote == :default
      # We ship with a single quotes plugin that will define this
      # constant. That constant is responsible for determining the default
      # quote style. If it's defined, we default to single quotes,
      # otherwise we default to double quotes.
      defined?(SINGLE_QUOTES) ? "'" : "\""
    else
      quote
    end

  @trailing_comma =
    if trailing_comma == :default
      # We ship with a trailing comma plugin that will define this
      # constant. That constant is responsible for determining the default
      # trailing comma value. If it's defined, then we default to true.
      # Otherwise we default to false.
      defined?(TRAILING_COMMA)
    else
      trailing_comma
    end

  @disable_auto_ternary =
    if disable_auto_ternary == :default
      # We ship with a disable ternary plugin that will define this
      # constant. That constant is responsible for determining the default
      # disable ternary value. If it's defined, then we default to true.
      # Otherwise we default to false.
      defined?(DISABLE_AUTO_TERNARY)
    else
      disable_auto_ternary
    end

  @target_ruby_version =
    if target_ruby_version == :default
      # The default target Ruby version is the current version of Ruby.
      # This is really only used for very niche cases, and it shouldn't be
      # used by most users.
      SemanticVersion.new(RUBY_VERSION)
    else
      target_ruby_version
    end
end