Sha256: fc4f9d84ae7b2fc206983284bf7999170d3c63b4c9e4d592e7fbee226e3b497f

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'colorize'

module Guard
  module Sass
    module Lint
      class Runner
        def initialize(file, linter)
          @file = file
          @linter = linter
        end

        def run
          display_result @linter.lint(@file)
        end

        def display_result(result_data)
          result_data.each do |data|
            if data['warningCount'] > 0 || data['errorCount'] > 0
              puts "⌕ #{data['filePath']}"
              data['messages'].each { |msg| puts format_message(msg) }
            end
          end

          puts clean_message if result_data.empty?
        end

        private

        def format_message(data)
          location = [sprintf("%4d", data['line']), sprintf("%-4d", data['column'])].join(':')
          rule = sprintf("%-25s", "(#{data['ruleId']})")
          message = "  #{rule} #{location} - #{data['message']}"
          case data['severity']
          when 1
            message.green
          when 2
            message.yellow
          else
            message
          end
        end

        def clean_message
          ['✓'.green, @file].join(' ')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
guard-sass-lint-0.1.2 lib/guard/sass/lint/runner.rb
guard-sass-lint-0.1.1 lib/guard/sass/lint/runner.rb
guard-sass-lint-0.1.0 lib/guard/sass/lint/runner.rb