Sha256: 1dd479dbf3f05cd549308e0121b643f811bffbdd37ddeef9221eebad475cbfb7

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'colored'
##
# CoffeeLint Checker looks for smells in your Coffeescript code
#
# @author dmasur
class CoffeeLintChecker
  ##
  # Gives the Checkresult
  #
  # @return [Hash] Checkresult
  # @author dmasur
  def result
    @shell_output = begin
      config_file = File.exists?("clint_config.json") ? '-f clint_config.json' : ''
      `coffeelint -r . #{config_file}`
    rescue Errno::ENOENT
      "CoffeeLint not found"
    end
    { type: :coffeelint, check_output: output, status: status }
  end

  private

  def output
    violation_count > 0 ? @shell_output : ''
  end

  ##
  # Gives the Check Status
  #
  # @return [String] Checkstatus
  # @author dmasur
  def status
    return 'No CoffeeScript Files found' if @shell_output == ""
    @violations = violation_count
    if @violations > 0
      print_violations
    elsif @violations == 0
      'OK'.green
    else
      'N/A'
    end
  end

  def violation_count
    @violations ||= @shell_output.scan(/(\d*) errors? and (\d*) warnings? in .+ files?/).flatten.
      map(&:to_i).inject(0){ |sum, value| sum += value }
  end

  def print_violations
    color_violations
    "#{@violations} Style Violations"
  end
  ##
  # Color Code Validation Count
  #
  # @return [String] Colored Validation Count
  # @author dmasur
  def color_violations
    color = :red
    color = :yellow if @violations.between?(1, 9)
    @violations = @violations.to_s.send color
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake_check-0.3.0 lib/rake_check/coffee_lint_checker.rb