Class: Overcommit::Hook::PreCommit::PhpCs
- Defined in:
- lib/overcommit/hook/pre_commit/php_cs.rb
Overview
Runs ‘phpcs` against any modified PHP files.
Constant Summary collapse
- MESSAGE_REGEX =
Parse ‘phpcs` csv mode output
/^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/
- MESSAGE_TYPE_CATEGORIZER =
lambda do |type| 'error'.include?(type) ? :error : :warning end
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#parse_messages(messages) ⇒ Object
Transform the CSV output into a tidy human readable message.
- #run ⇒ Object
Methods inherited from Base
#applicable_files, #command, #description, #enabled?, #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
#parse_messages(messages) ⇒ Object
Transform the CSV output into a tidy human readable message
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/overcommit/hook/pre_commit/php_cs.rb', line 36 def () output = [] .map do || .scan(MESSAGE_REGEX).map do |file, line, type, msg| type = MESSAGE_TYPE_CATEGORIZER.call(type) text = " #{file}:#{line}\n #{msg}" output << Overcommit::Hook::Message.new(type, file, line.to_i, text) end end output end |
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/overcommit/hook/pre_commit/php_cs.rb', line 12 def run = [] applicable_files.each do |file| result = execute(command, args: [file]) if result.status rows = result.stdout.split("\n") # Discard the csv header rows.shift # Push each of the errors in the particular file into the array rows.map do |row| << row end end end return :pass if .empty? () end |