Class: Overcommit::Hook::PreCommit::Dogma

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

Overview

Runs ‘dogma` against any modified ex files.

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/overcommit/hook/pre_commit/dogma.rb', line 8

def run
  result = execute command
  return :pass if result.success?

  messages = []
  # example message:
  #  == web/channels/user_socket.ex ==
  #  26: LineLength: Line length should not exceed 80 chars (was 83).
  #  1: ModuleDoc: Module Sample.UserSocket is missing a @moduledoc.
  output = result.stdout.chomp.match(/(==.+)/m)

  if output
    output.captures.first.split(/\n\n/).each do |error_group|
      errors = error_group.split /\n/
      file = errors.shift.gsub /[ =]/, ''
      errors.each do |error|
        line = error.split(': ').first
        messages << Overcommit::Hook::Message.new(:error, file, line, "#{file}: #{error}")
      end
    end
  end

  messages
end