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



133
134
135
# File 'lib/syntax_tree/cli.rb', line 133

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

#run(item) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/syntax_tree/cli.rb', line 117

def run(item)
  handler = item.handler

  warning = "[#{Color.yellow("warn")}] #{item.filepath}"
  formatted = handler.format(item.source)

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

#successObject



129
130
131
# File 'lib/syntax_tree/cli.rb', line 129

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