phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

Issue with EsLint task's parameter "whitelist" #799

Closed Szadeck closed 4 years ago

Szadeck commented 4 years ago
Q A
Version GrumPHP 0.19.1
Bug? yes
New feature? no
Question? no
Documentation? no

I have an issue using ESLint as a normal task with grumphp. I reproduced the documentation steps with the whitelist parameter set to : - /src\/(.*)/ I have a file.js in rootDir/src/ and i'm launching "php vendor/bin/grumphp run" to test. My ESLint step is simply skiped as follow:

Running task 1/4: phpcs... ✔ Running task 2/4: phpmd... ✔ Running task 3/4: eslint... Running task 4/4: phpunit... ✔

But when i run ESlint as standalone: _"nodemodules/.bin/eslint -c conf/eslintrc.yml src"

It works perfectly.

Even when i try to leave the whitelist blank, which is suppose to run every file that match my "triggered_by" parameter in my rootdir, as i read the doc "This is a list of regex patterns that will filter files to validate. With this option you can skip files like tests. This option is used in relation with the parameter triggeredby." . But here again i got my task skipped the same way. The example given is not working too if i didn't miss something. Reading the source code :

 $files = $context
            ->getFiles()
            ->paths($config['whitelist_patterns'] ?? [])
            ->extensions($config['triggered_by']);

        if (0 === \count($files)) {
            return TaskResult::createSkipped($this, $context);
        }

Maybe the issue come from getFiles which brings me 0 files and got skipped from the check.

My configuration

# grumphp.yml
---
grumphp:
    tasks:
        phpcs:
            standard: [PEAR]
            severity: ~
            error_severity: 1
            warning_severity: ~
            tab_width: ~
            report: full
            report_width: ~
            whitelist_patterns: [src]
            encoding: ~
            ignore_patterns: []
            sniffs: []
            triggered_by: [php]
            exclude: ['PEAR.COMMENTING.FILECOMMENT', 'Generic.ControlStructures.InlineControlStructure']
        phpmd:
            whitelist_patterns: [src]
            exclude: []
            ruleset: ['cleancode', 'codesize', 'naming']
            triggered_by: ['php']
        eslint:
            bin: node_modules/.bin/eslint
            triggered_by: [js, jsx, ts, tsx, vue]
            whitelist_patterns: 
                - /src\/(.*)/
            config: conf/eslintrc.yml
            debug: false
            format: ~
            max_warnings: ~
            no_eslintrc: false
            quiet: false
        phpunit:
            config_file: conf/phpunit-conf.xml
            testsuite: ~
            group: []
            always_execute: false

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.
After installing nodeJs, npm and eslint ->
php vendor/bin/grumphp git:init
mkdir src
touch example_file.js
# Run GrumPHP:
git add -A && git commit -m"Test"
# or
./vendor/bin/grumphp run

Result:

Running task 1/4: phpcs... ✔
Running task 2/4: phpmd... ✔
Running task 3/4: eslint...
Running task 4/4: phpunit... ✔
Szadeck commented 4 years ago

Found the answer, this is not a bug anymore but a documentation issue:

Was running grump with "php ./vendor/bin/grumphp run" as explained in "https://github.com/phpro/grumphp/blob/master/doc/commands.md#run" and it never worked but on a random commit grump trigerred himself with the git hook and eslint finally appeared.

I checked the hook and found that it wasn't running this exec, it was runnning "vendor/phpro/grumphp-shim/grumphp". So i tried and it works perfectly.