Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git Blacklist example does not work #1149

Open
Jamesking56 opened this issue Aug 19, 2024 · 1 comment
Open

Git Blacklist example does not work #1149

Jamesking56 opened this issue Aug 19, 2024 · 1 comment

Comments

@Jamesking56
Copy link

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

@veewee
Copy link
Contributor

veewee commented Aug 30, 2024

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 #1139 as well.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants