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

Attributes inherited from Action

#options

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from SyntaxTree::CLI::Action

Instance Method Details

#failureObject



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,
      options.print_width,
      options: options.formatter_options
    )

  double_formatted =
    handler.format(
      formatted,
      options.print_width,
      options: options.formatter_options
    )

  raise NonIdempotentFormatError if formatted != double_formatted
rescue StandardError
  warn(warning)
  raise
end

#successObject



273
274
275
# File 'lib/syntax_tree/cli.rb', line 273

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