Class: Overcommit::Hook::PreCommit::RuboCop

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/rubo_cop.rb

Overview

Runs ‘rubocop` against any modified Ruby files.

Constant Summary collapse

GENERIC_MESSAGE_TYPE_CATEGORIZER =
lambda do |type|
  type.match?(/^warn/) ? :warning : :error
end
COP_MESSAGE_TYPE_CATEGORIZER =
lambda do |type|
  type.include?('W') ? :warning : :error
end

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/overcommit/hook/pre_commit/rubo_cop.rb', line 16

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

  generic_messages = extract_messages(
    result.stderr.split("\n"),
    /^(?<type>[a-z]+)/i,
    GENERIC_MESSAGE_TYPE_CATEGORIZER,
  )

  cop_messages = extract_messages(
    result.stdout.split("\n"),
    /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):[^ ]+ (?<type>[^ ]+)/,
    COP_MESSAGE_TYPE_CATEGORIZER,
  )

  generic_messages + cop_messages
end