phpro / grumphp

A PHP code-quality tool
MIT License
4.11k stars 429 forks source link

Phpparser excludes filename from error message #1046

Closed rubenflush closed 1 year ago

rubenflush commented 1 year ago
Q A
Version 1.12.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets -

When an error is found by the phpparser task, it will show an error message indicating the problem. However, the file path without filename is used instead of the filename which makes it harder to fix the problem.

My configuration

# grumphp.yml
grumphp:
  tasks:
    phpparser:
      visitors:
        declare_strict_types: ~

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml

composer require --dev phpro/grumphp
composer require nikic/php-parser

mkdir -p src/resources
echo "<?php" > src/resources/nl.php
git add .

# Run GrumPHP:
./vendor/bin/grumphp run

Result:

[ERROR] src/resources: No "declare(strict_types = 1)" found in file!

Expected result:

[ERROR] src/resources/nl.php: No "declare(strict_types = 1)" found in file!
veewee commented 1 year ago

Thanks for reporting. This should be an easy fix. Do you wanna give it a try?

My hunch is that this line is not correct: https://github.com/phpro/grumphp/blob/6c3ca70a9185e76f3e914ddfcbcf4c7f541326a2/src/Parser/Php/Visitor/AbstractVisitor.php#L30