Sha256: 90659b83ce3ca78128c5a121d7b63249303ebf375b9543e8752c2643a3910ecb

Contents?: true

Size: 927 Bytes

Versions: 9

Compression:

Stored size: 927 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])/.freeze

    # 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

9 entries across 9 versions & 2 rubygems

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