Class: Overcommit::Hook::PreCommit::Reek

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

Overview

Runs ‘reek` against any modified Ruby files.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #description, #enabled?, #executable, #execute, #in_path?, #initialize, #install_command, #name, #quiet?, #required?, #run?, #run_and_transform, #skip?

Constructor Details

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

Instance Method Details

#cleanup_output(raw_output) ⇒ Object



25
26
27
# File 'lib/overcommit/hook/pre_commit/reek.rb', line 25

def cleanup_output(raw_output)
  raw_output.split("\n").grep(/^(.(?!warning))*$/)
end

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/overcommit/hook/pre_commit/reek.rb', line 4

def run
  result = execute(%W[#{executable} --single-line --no-color] + applicable_files)
  return :pass if result.success?

  output = cleanup_output(result.stdout + result.stderr)

  # Keep lines from the output for files that we actually modified
  error_lines, warning_lines = output.partition do |output_line|
    if (match = output_line.match(/^([^:]+):(\d+)/))
      file = match[1]
      line = match[2]
    end
    modified_lines(file).include?(line.to_i)
  end

  return :fail, error_lines.join("\n") unless error_lines.empty?

  [:warn, "Modified files have lints (on lines you didn't modify)\n" <<
      warning_lines.join("\n")]
end