Sha256: 0401cbf1ed2636c3c1bc24a12f6397d061ca85c19294d1b70f46bc3b8ece53f2

Contents?: true

Size: 851 Bytes

Versions: 12

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Runs `coffeelint` against any modified CoffeeScript files.
  #
  # @see http://www.coffeelint.org/
  class CoffeeLint < Base
    MESSAGE_REGEX = /
      ^(?<file>.+)
      ,(?<line>\d*),\d*
      ,(?<type>\w+)
      ,(?<msg>.+)$
    /x.freeze

    MESSAGE_TYPE_CATEGORIZER = lambda do |type|
      type.include?('w') ? :warning : :error
    end

    def run
      result = execute(command, args: applicable_files)
      parse_messages(result.stdout)
    end

    private

    def parse_messages(output)
      output.scan(MESSAGE_REGEX).map do |file, line, type, msg|
        line = line.to_i
        type = MESSAGE_TYPE_CATEGORIZER.call(type)
        text = "#{file}:#{line}:#{type} #{msg}"
        Overcommit::Hook::Message.new(type, file, line, text)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
overcommit-0.67.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.66.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.65.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.64.1 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.64.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.63.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.62.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.61.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.60.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.59.1 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-0.59.0 lib/overcommit/hook/pre_commit/coffee_lint.rb
overcommit-jeygeethanmedia-0.58.0 lib/overcommit/hook/pre_commit/coffee_lint.rb