Sha256: 29fdf244b67163cc78e1674c4799e7fb94b2056d716ecd399e173ed7c3781e10

Contents?: true

Size: 876 Bytes

Versions: 2

Compression:

Stored size: 876 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Runs `pylint` against any modified Python files.
  #
  # @see http://www.pylint.org/
  class Pylint < Base
    MESSAGE_REGEX = /^(?<file>.+):(?<line>\d+):(?<type>[CEFRW])/

    # Classify 'E' and 'F' message codes as errors,
    # everything else as warnings.
    #   http://pylint.readthedocs.org/en/latest/tutorial.html#getting-started
    MESSAGE_TYPE_CATEGORIZER = lambda do |type|
      'EF'.include?(type) ? :error : :warning
    end

    def run
      result = execute(command + applicable_files)
      return :pass if result.success?

      output = result.stdout.chomp

      # example message:
      #   path/to/file.py:64:C: Missing function docstring (missing-docstring)
      extract_messages(
        output.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/pylint.rb
overcommit-0.26.0 lib/overcommit/hook/pre_commit/pylint.rb