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 collapse
-
#print_width ⇒ Object
readonly
Returns the value of attribute print_width.
Instance Method Summary collapse
- #failure ⇒ Object
-
#initialize(print_width:) ⇒ Debug
constructor
A new instance of Debug.
- #run(item) ⇒ Object
- #success ⇒ Object
Constructor Details
#initialize(print_width:) ⇒ Debug
Returns a new instance of Debug.
127 128 129 |
# File 'lib/syntax_tree/cli.rb', line 127 def initialize(print_width:) @print_width = print_width end |
Instance Attribute Details
#print_width ⇒ Object (readonly)
Returns the value of attribute print_width.
125 126 127 |
# File 'lib/syntax_tree/cli.rb', line 125 def print_width @print_width end |
Instance Method Details
#failure ⇒ Object
149 150 151 |
# File 'lib/syntax_tree/cli.rb', line 149 def failure warn("The listed files could not be formatted idempotently.") end |
#run(item) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/syntax_tree/cli.rb', line 131 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
145 146 147 |
# File 'lib/syntax_tree/cli.rb', line 145 def success puts("All files can be formatted idempotently.") end |