Sha256: 6fabd9b66edc511a034636da43c5a0767c8002f2d2b65da64c13533b810295e8

Contents?: true

Size: 920 Bytes

Versions: 19

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Runs `pylint` against any modified Python files.
  #
  # @see http://www.pylint.org/
  class Pylint < Base
    MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<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, args: 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

19 entries across 19 versions & 2 rubygems

Version Path
overcommit-0.58.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.57.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.56.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.55.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.54.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.54.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-jeygeethanmedia-0.53.1.2 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-jeygeethanmedia-0.53.1.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-jeygeethanmedia-0.53.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.53.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.52.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.52.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.51.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.50.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.49.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.49.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.48.1 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.48.0 lib/overcommit/hook/pre_commit/pylint.rb
overcommit-0.47.0 lib/overcommit/hook/pre_commit/pylint.rb