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
191 192 193 |
# File 'lib/syntax_tree/cli.rb', line 191 def failure warn("The listed files could not be formatted idempotently.") end |
#run(item) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/syntax_tree/cli.rb', line 163 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
187 188 189 |
# File 'lib/syntax_tree/cli.rb', line 187 def success puts("All files can be formatted idempotently.") end |