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 Attribute Summary

Attributes inherited from Action

#options

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from SyntaxTree::CLI::Action

Instance Method Details

#failureObject



175
176
177
# File 'lib/syntax_tree/cli.rb', line 175

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

#run(item) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/syntax_tree/cli.rb', line 157

def run(item)
  handler = item.handler

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

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

#successObject



171
172
173
# File 'lib/syntax_tree/cli.rb', line 171

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