Problem/Motivation

https://www.drupal.org/docs/develop/development-tools/phpstan/handling-u... gives the example

parameters:
  ignoreErrors:
    # new static() is a best practice in Drupal, so we cannot fix that.
    - "#^Unsafe usage of new static#"

Yet does not document how to add that. I attempted to put that in module root as phpstan.neon and 2nd attempt as phpstan.neon.dist but both still result in test failure for phpstan via gitlab ci

Steps to reproduce

Add the above to a contrib module.

Proposed resolution

Update documentation to explain how to add.

Remaining tasks

Update documentation.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/A

Comments

scott_euser created an issue. See original summary.

mondrake’s picture

Wouldn’t it be possible for the GitlabCI template to fallback to core’s phpstan.neon.dist if the
contrib module does not include a phpstan.neon file?

scott_euser’s picture

Just checked how that would work: phpstan then actually throws errors if an ignore error is in place yet no occurrences of the error are actually found.

scott_euser’s picture

Status: Active » Fixed

Okay turns out if I copy the full phpstan.neon.dist from core and remove the ignoreErrors that do not apply to my contrib module, it works fine:

# This file is copied from ./core/phpstan.neon.dist then set to only
# ignore errors applicable to this project rather than all errors ignored
# from Core as phpstan throws errors when ignore lines here are unused.

# Configuration file for PHPStan static code checking, see https://phpstan.org .
# PHPStan is triggered on Drupal CI in commit-code-check.sh.
includes:
  - phar://phpstan.phar/conf/bleedingEdge.neon

parameters:
  level: 1

  paths:
    - .

  ignoreErrors:
    # new static() is a best practice in Drupal, so we cannot fix that.
    - "#^Unsafe usage of new static#"

I will update the documentation page to clarify.

mondrake’s picture

Just checked how that would work: phpstan then actually throws errors if an ignore error is in place yet no occurrences of the error are actually found.

Darn. You're right.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

fathershawn’s picture

I'll also add it to the docs, but you can add reportUnmatchedIgnoredErrors: false to your neon file and it won't squeak about ignored errors that didn't happen.

mondrake’s picture

#7 right, but that would still require a custom neon file. Here my point was NOT to have one, and still fallback to core's one.