Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
5
Help us understand the problem. What is going on with this article?
@ie4

Commit時にSyntaxCheckする

More than 3 years have passed since last update.

syntaxerror.jpg

HookScript(prepare-commit-msg)を使う

phpの場合、以下のようにすると、
Commit前にsyntaxチェックを行い、エラーがある場合は、Commitせずにエラー表示して抜けてくれる。

.git/hooks/prepare-commit-msg
#!/bin/bash

errFlg=0

while read file ; do
        php -l $file >/dev/null
        if [ $? != 0 ]; then
                errFlg=1
        fi
done < <( git diff --cached --name-only | egrep "\.php$" )

exit $errFlg

$ cat test.php 
<?php

print "hello world!" // <- ;忘れ

$ 
$ 
$ php -l test.php 
PHP Parse error:  syntax error, unexpected $end in test.php on line 6

Parse error: syntax error, unexpected $end in test.php on line 6
Errors parsing test.php
$ 
$ 
$ git diff --stat
 test.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ 
$ 
$ git commit -am 'commit test'
PHP Parse error:  syntax error, unexpected $end in test.php on line 6
$ 
$ 
$ git diff --stat
 test.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ 
5
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ie4
IoTっぽい記事多めです。
iotlt
IoT縛りの勉強会です。 毎月イベントを実施しているので是非遊びに来てください! 登壇者を中心にQiitaでも情報発信していきます。 https://iotlt.connpass.com

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
5
Help us understand the problem. What is going on with this article?