Class: Overcommit::Hook::PreCommit::PhpLint
- Defined in:
- lib/overcommit/hook/pre_commit/php_lint.rb
Overview
Runs ‘php -l` against any modified PHP files.
Constant Summary collapse
- MESSAGE_REGEX =
Sample String rubocop:disable Layout/LineLength
PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
rubocop:enable Layout/LineLength
/^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/.freeze
Instance Attribute Summary
Attributes inherited from Base
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
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/overcommit/hook/pre_commit/php_lint.rb', line 12 def run # A list of error messages = [] # Exit status for all of the runs. Should be zero! exit_status_sum = 0 # Run for each of our applicable files applicable_files.each do |file| result = execute(command, args: [file]) output = result.stdout.chomp exit_status_sum += result.status if result.status # `php -l` returns with a leading newline, and we only need the first # line, there is usually some redundancy << output.lstrip.split("\n").first end end # If the sum of all lint status is zero, then none had exit status return :pass if exit_status_sum == 0 # No messages is great news for us return :pass if .empty? # Return the list of message objects ( , MESSAGE_REGEX ) end |