grumphp icon indicating copy to clipboard operation
grumphp copied to clipboard

Git Blacklist example does not work

Open Jamesking56 opened this issue 1 year ago • 1 comments

Q A
Version 2.6.0
Bug? yes
New feature? no
Question? no
Documentation? yes
Related tickets

My configuration

# grumphp.yml
grumphp:
    tasks:
        git_blacklist:
            keywords:
                - "die\\("
                - "dd\\("
                - "var_dump\\("
                - "exit;"
                - "file_put_contents\\("
            triggered_by: ['php']
            regexp_type: G

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml
composer require --dev phpro/grumphp

# Your actions
# Please add the steps on how to reproduce the issue here.
Add config file from above

# Run GrumPHP:
git add -A && git commit -m"Test"
# or
./vendor/bin/grumphp run

Result:

git_blacklist
=============

Something went wrong:
fatal: -e option, 'die\(': Unmatched ( or \(

This config matches the config in the docs here: https://github.com/phpro/grumphp/blob/v2.x/doc/tasks/git_blacklist.md

Jamesking56 avatar Aug 19 '24 13:08 Jamesking56

You might need to escape the character twice to make sure it is escaped in both yaml and next in your git cli command.

An alternative solution is to use: https://github.com/phpro/grumphp/blob/v2.x/doc/tasks/phpparser.md

Or phpstan with https://github.com/ekino/phpstan-banned-code.

Both use PHP's AST to figure out if it's allowed or not which is less error prone on input like dump[space]( Whilst the blacklist task only checks for a regex match.

(It has been reported in https://github.com/phpro/grumphp/issues/1139 as well.)

veewee avatar Aug 30 '24 06:08 veewee

Closing this issue because of inactivity.

Feel free to improve the documentation.

veewee avatar Nov 26 '24 12:11 veewee