lib/coffeelint.rb in coffeelint-1.11.0 vs lib/coffeelint.rb in coffeelint-1.14.0

- old
+ new

@@ -41,41 +41,53 @@ EOF coffeelintSource = File.read(Coffeelint.path) ExecJS.compile(coffeescriptSource + bootstrap + coffeelintSource) end - def self.lint(script, config = {}) + def self.lint(script, config = {}, context = Coffeelint.context) fname = config.fetch(:config_file, CoffeeLint::Config.locate) config.merge!(CoffeeLint::Config.parse(fname)) unless fname.nil? - Coffeelint.context.call('window.coffeelint.lint', script, config) + context.call('window.coffeelint.lint', script, config) end - def self.lint_file(filename, config = {}) - Coffeelint.lint(File.read(filename), config) + def self.lint_file(filename, config = {}, context = Coffeelint.context) + Coffeelint.lint(File.read(filename), config, context) end - def self.lint_dir(directory, config = {}) + def self.lint_dir(directory, config = {}, context = Coffeelint.context) retval = {} - Dir.glob("#{directory}/**/*.coffee") do |name| - retval[name] = Coffeelint.lint_file(name, config) + filtered_path = filter(directory) + + Dir.glob(filtered_path) do |name| + retval[name] = Coffeelint.lint_file(name, config, context) yield name, retval[name] if block_given? end retval end + def self.filter(directory) + Dir.glob("#{directory}/**/*.coffee") - Dir.glob("#{directory}/**/{#{ignored_paths}}") + end + + def self.ignored_paths + if File.exist?(".coffeelintignore") + File.read(".coffeelintignore").lines.map(&:chomp).join(",") + else + [] + end + 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' + failure_count = 0 if errors.length == 0 puts " #{good} " + Coffeelint.green(name, pretty_output) - return true else - no_failures = true if errors.any? {|e| e["level"] == "error"} - no_failures = false puts " #{bad} " + Coffeelint.red(name, pretty_output) else puts " #{warn} " + Coffeelint.yellow(name, pretty_output) end @@ -88,30 +100,28 @@ print " " if error["level"] == "warn" print warn + " " print Coffeelint.yellow(disp, pretty_output) else + failure_count += 1 print bad + " " print Coffeelint.red(disp, pretty_output) end puts ": #{error["message"]}. #{error["context"]}." end - return no_failures end + return failure_count end def self.run_test(file, config = {}) pretty_output = config.has_key?(:pretty_output) ? config.delete(:pretty_output) : true - result = Coffeelint.lint_file(file, config) - Coffeelint.display_test_results(file, result, pretty_output) + errors = Coffeelint.lint_file(file, config) + Coffeelint.display_test_results(file, errors, pretty_output) end def self.run_test_suite(directory, config = {}) pretty_output = config.has_key?(:pretty_output) ? config.delete(:pretty_output) : true - errors_count = 0 - Coffeelint.lint_dir(directory, config) do |name, errors| - errors_count += errors.count - result = Coffeelint.display_test_results(name, errors, pretty_output) - end - errors_count + Coffeelint.lint_dir(directory, config).map do |name, errors| + Coffeelint.display_test_results(name, errors, pretty_output) + end.inject(0, :+) end end