Sha256: 0598fa599a77a68dc193c1d027cb20dbaa0230b2132c5ffc7525998af41491c0

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

module Overcommit::Hook::PreCommit
  # Runs `php -l` against any modified PHP files.
  class PhpLint < Base
    # Sample String
    # rubocop:disable Metrics/LineLength
    #   PHP Parse error:  syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
    # rubocop:enable Metrics/LineLength
    MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/

    def run
      # A list of error messages
      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
          messages << 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 messages.empty?

      # Return the list of message objects
      extract_messages(
        messages,
        MESSAGE_REGEX
      )
    end
  end
end

Version data entries

10 entries across 8 versions & 2 rubygems

Version Path
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/php_lint.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/php_lint.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/php_lint.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.46.0 lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.45.0 lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.44.0 lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.43.0 lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.42.0 lib/overcommit/hook/pre_commit/php_lint.rb
overcommit-0.41.0 lib/overcommit/hook/pre_commit/php_lint.rb