Sha256: 809b369a2c477fbd1dbc425790e010140c363a6c7974eb9fb2cdaf01c1e4137a

Contents?: true

Size: 737 Bytes

Versions: 2

Compression:

Stored size: 737 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Runs `jsl` against any modified JavaScript files.
  #
  # @see http://www.javascriptlint.com/
  class Jsl < Base
    MESSAGE_REGEX = /(?<file>.+)\((?<line>\d+)\):(?<type>[^:]+)/

    MESSAGE_TYPE_CATEGORIZER = lambda do |type|
      type =~ /warning/ ? :warning : :error
    end

    def run
      file_flags = applicable_files.map { |file| ['-process', file] }
      result = execute(command + file_flags.flatten)
      return :pass if result.success?

      # example message:
      #   path/to/file.js(1): lint warning: Error message
      extract_messages(
        result.stdout.split("\n").grep(MESSAGE_REGEX),
        MESSAGE_REGEX,
        MESSAGE_TYPE_CATEGORIZER
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
overcommit-0.27.0 lib/overcommit/hook/pre_commit/jsl.rb
overcommit-0.26.0 lib/overcommit/hook/pre_commit/jsl.rb