class SyntaxTree::CLI::Debug

An action of the CLI that formats the source twice to check if the first format is not idempotent.

Public Instance Methods

failure() click to toggle source
# File lib/syntax_tree/cli.rb, line 277
def failure
  warn("The listed files could not be formatted idempotently.")
end
run(item) click to toggle source
# File lib/syntax_tree/cli.rb, line 249
def run(item)
  handler = item.handler
  warning = "[#{Color.yellow("warn")}] #{item.filepath}"

  formatted =
    handler.format(
      item.source,
      options.print_width,
      options: options.formatter_options
    )

  double_formatted =
    handler.format(
      formatted,
      options.print_width,
      options: options.formatter_options
    )

  raise NonIdempotentFormatError if formatted != double_formatted
rescue StandardError
  warn(warning)
  raise
end
success() click to toggle source
# File lib/syntax_tree/cli.rb, line 273
def success
  puts("All files can be formatted idempotently.")
end