Sha256: 5f3f38c828e5a35fd3a3be8e2d8d482910068867933ab6140e655369a3d683c7
Contents?: true
Size: 1.34 KB
Versions: 19
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module Overcommit::Hook::PreCommit # Runs `php-cs-fixer` against any modified PHP files. class PhpCsFixer < Base MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/ def run messages = [] feedback = '' # Exit status for all of the runs. Should be zero! exit_status_sum = 0 applicable_files.each do |file| result = execute(command, args: [file]) output = result.stdout.chomp exit_status_sum += result.status if result.status messages = output.lstrip.split("\n") end end unless messages.empty? feedback = parse_messages(messages) end :pass if exit_status_sum == 0 :pass if feedback.empty? feedback end def parse_messages(messages) output = [] messages.map do |message| message.scan(MESSAGE_REGEX).map do |file, violated_rules| type = :error unless violated_rules.nil? type = :warning end text = if type == :error "Cannot process #{file}: Syntax error" else "#{file} has been fixed" end output << Overcommit::Hook::Message.new(type, file, 0, text) end end output end end end
Version data entries
19 entries across 19 versions & 2 rubygems