Class: Scelint::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/scelint/cli.rb

Overview

SCELint CLI

Instance Method Summary collapse

Instance Method Details

#lint(*paths) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/scelint/cli.rb', line 15

def lint(*paths)
  paths = ['.'] if paths.nil? || paths.empty?
  lint = Scelint::Lint.new(paths, logger: logger)

  count = lint.files.count

  if count.zero?
    logger.error 'No SCE data found.'
    exit 0
  end

  lint.errors.each do |error|
    logger.error error
  end

  lint.warnings.each do |warning|
    logger.warn warning
  end

  lint.notes.each do |note|
    logger.info note
  end

  message = "Checked #{count} files."
  if lint.errors.empty?
    message += '  No errors.'
    exit_code = 0
  else
    message += "  #{lint.errors.count} errors."
    exit_code = 1
  end

  unless lint.warnings.empty?
    message += "  #{lint.warnings.count} warnings."
    exit_code = 1 if options[:strict]
  end

  message += " #{lint.notes.count} notes." unless lint.notes.empty?

  logger.info message
  exit exit_code
rescue => e
  logger.fatal e.message
end