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
277 278 279 |
# File 'lib/syntax_tree/cli.rb', line 277 def failure warn("The listed files could not be formatted idempotently.") end |
#run(item) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/syntax_tree/cli.rb', line 249 def run(item) handler = item.handler warning = "[#{Color.yellow("warn")}] #{item.filepath}" formatted = handler.format( item.source, .print_width, options: . ) double_formatted = handler.format( formatted, .print_width, options: . ) raise NonIdempotentFormatError if formatted != double_formatted rescue StandardError warn(warning) raise end |
#success ⇒ Object
273 274 275 |
# File 'lib/syntax_tree/cli.rb', line 273 def success puts("All files can be formatted idempotently.") end |