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>.+)\"/.freeze
- 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?, #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
#parse_messages(messages) ⇒ Object
Transform the CSV output into a tidy human readable message
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/overcommit/hook/pre_commit/php_cs.rb', line 29 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 |
# File 'lib/overcommit/hook/pre_commit/php_cs.rb', line 12 def run = [] result = execute(command, args: applicable_files) if result.status = result.stdout.split("\n") # Discard the csv header .shift end return :fail if .empty? && !result.success? return :pass if .empty? () end |