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

Fails to Recognize PHPStan Baseline During Commit Workflow #1114

Open
AgostinaGallo opened this issue Nov 16, 2023 · 0 comments
Open

Fails to Recognize PHPStan Baseline During Commit Workflow #1114

AgostinaGallo opened this issue Nov 16, 2023 · 0 comments

Comments

@AgostinaGallo
Copy link

AgostinaGallo commented Nov 16, 2023

Q A
Version v2.2.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

I am encountering an issue when trying to commit changes. Despite having added errors to the PHPStan baseline and successfully running vendor/bin/phpstan and vendor/bin/grumphp run, GrumPHP fails during the commit process, reporting errors that should have been ignored.

My configuration

# grumphp.yml
grumphp:
    parallel:
        enabled: true
        max_workers: 32
    fixer:
        enabled: true
        fix_by_default: true
    tasks:
      phpmd:
        whitelist_patterns:
          - /^app\/Http\/Controllers\/(.*)/
          - /^app\/Http\/Middleware\/(.*)/
          - /^app\/Exceptions\/(.*)/
        exclude: ['vendor/','database/seeders/','bootstrap/','public/','storage/','app/Http/Controllers/Testing/', 'tests/']
        report_format: ansi
        ruleset: ['phpmd_ruleset.xml']
        triggered_by: ['php']
      phpstan:
        autoload_file: ~
        configuration: phpstan.neon
        level: 9
        force_patterns: []
        ignore_patterns: []
        triggered_by: ['php']
        memory_limit: "-1"
        use_grumphp_paths: true
      phpcsfixer:
        allow_risky: true
        cache_file: .php-cs-fixer.cache
        config: .php-cs-fixer.php
        rules: []
        using_cache: true
        config_contains_finder: true
        verbose: true
        diff: false
        triggered_by: ['php']

Expected Behavior: I expect GrumPHP to recognize the baseline file and exclude the errors that have been marked as allowed in PHPStan. The baseline file is correctly generated, and the phpstan.neon configuration seems to be in order.

Actual Behavior: GrumPHP is not honoring the PHPStan baseline during the commit process, leading to the detection of errors that should have been ignored based on the baseline file. This issue seems to be specific to the interaction between GrumPHP and PHPStan during the commit workflow.

Steps to reproduce:

  1. Configure GrumPHP with PHPStan and generate a PHPStan baseline.
  2. Introduce errors to a file, add it to the baseline, and attempt to commit.
  3. Observe GrumPHP failing to recognize the baseline during the commit process.

My actions

Run GrumPHP with commit:

git commit -m "Commit message'"

GrumPHP detected a pre-commit command.
GrumPHP is sniffing your code!

Running tasks with priority 0!
==============================

Running task 1/3: phpmd...
Running task 2/3: phpstan...
Running task 3/3: phpcsfixer...

Running task 1/3: phpmd... ✔
Running task 2/3: phpstan... ✘
Running task 3/3: phpcsfixer... ✔

             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
         ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
       ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
  ▄███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 █▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄███████                       ██████████
     ███████▀  ▀▀▀▀▀▄      ▄▀▀▀▀▀     █████ ▀
      ▐████      ▐██        ▐██        ████▌
      ████▌                            ███
       ▌██▌           ▄▄ ▄▄           ▐███
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███
         ██▄ ▐███████████████████████████
        █▀███████████▀     ▀▀███████████
          ██████████▄███████▄███████████
         ▐█████████████████████████████
          █████████████████████████████
           ██ █████████████████████▐██▀
            ▀ ▐███████████████████▌ ▐▀
                ████▀████████▀▐███
                 ▀█▌  ▐█████  ██▌
                        ██▀   ▐▀

       ██████████████████████████████████
       █░░░░░░▀█▀░░░░░░▀█░░░░░░▀█▀░░░░░▀█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░░░░░▄█░░▄▄▄▄▄█
       █░░▐█▌░░█░░░██░░░█░░░░████░░░░░░░█
       █░░░█░░░█▄░░░░░░▄█░░░░████▄░░░░░▄█
       ██████████████████████████████████


phpstan
=======

------- -------------------------------------------------------------------------------------------------------- 
  Line    Http\Controllers\Controller.php
 ------- --------------------------------------------------------------------------------------------------------
(lots of errors)

 [ERROR] Found 182 errors
To skip commit checks, add -n or --no-verify flag to commit command

Run GrumPHP:

vendor/bin/grumphp run

GrumPHP is sniffing your code!

Running tasks with priority 0!
==============================

Running task 1/3: phpmd...
Running task 2/3: phpstan...
Running task 3/3: phpcsfixer... ✔
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
         ▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
  ▄▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄████████▀▀▀▀▀                 ██████████
     ███████▀                         ██████▀
      ▐████      ██▌          ██       ████▌
        ▐█▌                            ███
         █▌           ▄▄ ▄▄           ▐███
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███
         ██▄ ▐███████████████████████████
        █▀█████████▌▀▀▀▀▀▀▀▀▀██████████▌▐
          ███████████▄▄▄▄▄▄▄███████████▌
         ▐█████████████████████████████
          █████████████████████████████
           ██ █████████████████████▐██▀
            ▀ ▐███████████████████▌ ▐▀
                ████▀████████▀▐███
                 ▀█▌  ▐█████  ▐█▌
                        ██▀   ▐▀
       _    _ _                         _ _
      / \  | | |   __ _  ___   ___   __| | |
     / _ \ | | |  / _` |/ _ \ / _ \ / _` | |
    / ___ \| | | | (_| | (_) | (_) | (_| |_|
   /_/   \_\_|_|  \__, |\___/ \___/ \__,_(_)

Additional Context

I have verified that PHPStan runs successfully with the generated baseline, and no errors are reported when directly executing vendor/bin/phpstan.
My phpstan.neon config located in root:

includes:
   - ./vendor/nunomaduro/larastan/extension.neon
   - phpstan-baseline.neon

parameters:

   paths:
       - app
       - config
       - database
       - routes
       - tests

   # Level 9 is the highest level
   level: 8

   excludePaths:
   - app/Http/Controllers/Testing/*
   - database/factories/*
   - database/seeders/*
   - bootstrap/*
   - public/*
   - resources/*
   - routes/tests
   - storage/*
   - phpmd_ruleset.xml
   - phpmd.baseline.xml
   - pdepend.xml
   - phpunit.xml

   checkMissingIterableValueType: false
   reportUnmatchedIgnoredErrors: false

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

No branches or pull requests

2 participants