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
145 146 147 |
# File 'lib/syntax_tree/cli.rb', line 145 def failure warn("The listed files could not be formatted idempotently.") end |
#run(item) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/syntax_tree/cli.rb', line 127 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
141 142 143 |
# File 'lib/syntax_tree/cli.rb', line 141 def success puts("All files can be formatted idempotently.") end |