Class: SyntaxTree::CLI::Debug

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

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

Defined Under Namespace

Classes: NonIdempotentFormatError

Instance Method Summary collapse

Instance Method Details

#failureObject



94
95
96
# File 'lib/syntax_tree/cli.rb', line 94

def failure
  warn("The listed files could not be formatted idempotently.")
end

#run(filepath, source) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/syntax_tree/cli.rb', line 78

def run(filepath, source)
  warning = "[#{Color.yellow("warn")}] #{filepath}"
  formatted = SyntaxTree.format(source)

  if formatted != SyntaxTree.format(formatted)
    raise NonIdempotentFormatError
  end
rescue StandardError
  warn(warning)
  raise
end

#successObject



90
91
92
# File 'lib/syntax_tree/cli.rb', line 90

def success
  puts("All files can be formatted idempotently.")
end