Class: SyntaxTree::CLI::Debug

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

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

Instance Method Summary collapse

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

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

#failureObject



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

#successObject



145
146
147
# File 'lib/syntax_tree/cli.rb', line 145

def success
  puts("All files can be formatted idempotently.")
end