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



150
151
152
# File 'lib/syntax_tree/cli.rb', line 150

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

#run(item) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/syntax_tree/cli.rb', line 132

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



146
147
148
# File 'lib/syntax_tree/cli.rb', line 146

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