Class: SyntaxTree::CLI::Debug
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
Instance Method Summary collapse
Methods inherited from Action
Constructor Details
This class inherits a constructor from SyntaxTree::CLI::Action
Instance Method Details
#failure ⇒ Object
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, .print_width) if formatted != handler.format(formatted, .print_width) raise NonIdempotentFormatError end rescue StandardError warn(warning) raise end |
#success ⇒ Object
146 147 148 |
# File 'lib/syntax_tree/cli.rb', line 146 def success puts("All files can be formatted idempotently.") end |