lib/coffeelint.rb in coffeelint-0.2.5 vs lib/coffeelint.rb in coffeelint-0.2.6
- old
+ new
@@ -1,6 +1,7 @@
require "coffeelint/version"
+require 'coffeelint/cmd'
require 'execjs'
require 'coffee-script'
require 'json'
module Coffeelint
@@ -20,10 +21,14 @@
def self.green(str, pretty_output = true)
pretty_output ? Coffeelint.colorize(str, 32) : str
end
+ def self.yellow(str, pretty_output = true)
+ pretty_output ? Coffeelint.colorize(str, 33) : str
+ end
+
def self.context
coffeescriptSource = File.read(CoffeeScript::Source.path)
bootstrap = <<-EOF
window = {
CoffeeScript: CoffeeScript,
@@ -55,22 +60,41 @@
retval
end
def self.display_test_results(name, errors, pretty_output = true)
good = pretty_output ? "\u2713" : 'Passed'
+ warn = pretty_output ? "\u26A1" : 'Warn'
bad = pretty_output ? "\u2717" : 'Failed'
if errors.length == 0
puts " #{good} " + Coffeelint.green(name, pretty_output)
return true
else
- puts " #{bad} " + Coffeelint.red(name, pretty_output)
+ failed = false
+ if errors.any? {|e| e["level"] == "error"}
+ failed = true
+ puts " #{bad} " + Coffeelint.red(name, pretty_output)
+ else
+ puts " #{warn} " + Coffeelint.yellow(name, pretty_output)
+ end
+
errors.each do |error|
- print " #{bad} "
- print Coffeelint.red(error["lineNumber"], pretty_output)
- puts ": #{error["message"]}, #{error["context"]}."
+ disp = "##{error["lineNumber"]}"
+ if error["lineNumberEnd"]
+ disp += "-#{error["lineNumberEnd"]}"
+ end
+
+ print " "
+ if error["level"] == "warn"
+ print warn + " "
+ print Coffeelint.yellow(disp, pretty_output)
+ else
+ print bad + " "
+ print Coffeelint.red(disp, pretty_output)
+ end
+ puts ": #{error["message"]}. #{error["context"]}."
end
- return false
+ return failed
end
end
def self.run_test(file, config = {})
pretty_output = config.has_key?(:pretty_output) ? config.delete(:pretty_output) : true