Sha256: 081f9cfa36b66a2af361a8aa4cd4b72ccb4ca60a13a5300b2f8c6ab3215cd8c8

Contents?: true

Size: 768 Bytes

Versions: 28

Compression:

Stored size: 768 Bytes

Contents

module Overcommit::Hook::PreCommit
  # Runs `pyflakes` against any modified Python files.
  #
  # @see https://pypi.python.org/pypi/pyflakes
  class Pyflakes < Base
    MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/

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

      errors = get_messages(result.stderr, :error)
      warnings = get_messages(result.stdout, :warning)

      errors + warnings
    end

    private

    def get_messages(output, type)
      # example message:
      #   path/to/file.py:57: local variable 'x' is assigned to but never used
      extract_messages(
        output.split("\n").grep(MESSAGE_REGEX),
        MESSAGE_REGEX,
        proc { type }
      )
    end
  end
end

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
overcommit-0.33.0 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.32.0 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.32.0.rc1 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.31.0 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.30.0 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.29.1 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.29.0 lib/overcommit/hook/pre_commit/pyflakes.rb
overcommit-0.28.0 lib/overcommit/hook/pre_commit/pyflakes.rb