From b7fe9900d5933ffdbdeeb2b10877fd2764cb8bb8 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 8 Aug 2024 10:37:22 +0200 Subject: [PATCH] Do not report nonexistent paths in ignoreErrors if `reportUnmatchedIgnoredErrors: false` --- .github/workflows/e2e-tests.yml | 4 ++++ .../ignoreReportUnmatchedFalse.neon | 12 ++++++++++++ src/Command/CommandHelper.php | 5 +++++ src/DependencyInjection/NeonAdapter.php | 2 +- .../ValidateIgnoredErrorsExtension.php | 4 +++- 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 e2e/bad-exclude-paths/ignoreReportUnmatchedFalse.neon diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index c5fb603271..aeb7efb6fc 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -247,6 +247,10 @@ jobs: cp -r tmp-node-modules node_modules OUTPUT=$(../../bin/phpstan analyse -c ignoreNonexistentExcludePath.neon) echo "$OUTPUT" + - script: | + cd e2e/bad-exclude-paths + OUTPUT=$(../../bin/phpstan analyse -c ignoreReportUnmatchedFalse.neon) + echo "$OUTPUT" steps: - name: "Checkout" diff --git a/e2e/bad-exclude-paths/ignoreReportUnmatchedFalse.neon b/e2e/bad-exclude-paths/ignoreReportUnmatchedFalse.neon new file mode 100644 index 0000000000..2206595e61 --- /dev/null +++ b/e2e/bad-exclude-paths/ignoreReportUnmatchedFalse.neon @@ -0,0 +1,12 @@ +includes: + - ../../conf/bleedingEdge.neon + +parameters: + level: 8 + paths: + - src + reportUnmatchedIgnoredErrors: false + ignoreErrors: + - + message: '#aaa#' + path: tests diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index ffe9fba6bd..dee834e30b 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -355,6 +355,11 @@ public static function begin( $errorOutput->writeLineFormatted($error); $errorOutput->writeLineFormatted(''); } + + $errorOutput->writeLineFormatted('To ignore non-existent paths in ignoreErrors,'); + $errorOutput->writeLineFormatted('set reportUnmatchedIgnoredErrors: false in your configuration file.'); + $errorOutput->writeLineFormatted(''); + throw new InceptionNotSuccessfulException(); } catch (InvalidExcludePathsException $e) { $errorOutput->writeLineFormatted(sprintf('Invalid %s in excludePaths:', count($e->getErrors()) === 1 ? 'entry' : 'entries')); diff --git a/src/DependencyInjection/NeonAdapter.php b/src/DependencyInjection/NeonAdapter.php index 85ef82cda2..0a43ab25c6 100644 --- a/src/DependencyInjection/NeonAdapter.php +++ b/src/DependencyInjection/NeonAdapter.php @@ -31,7 +31,7 @@ class NeonAdapter implements Adapter { - public const CACHE_KEY = 'v27-optional-path'; + public const CACHE_KEY = 'v28-ignore-errors'; private const PREVENT_MERGING_SUFFIX = '!'; diff --git a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php index c4635af70a..fea4461b45 100644 --- a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php +++ b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php @@ -136,7 +136,9 @@ public function getRegistry(): OperatorTypeSpecifyingExtensionRegistry } } - if ($noImplicitWildcard) { + $reportUnmatched = (bool) $builder->parameters['reportUnmatchedIgnoredErrors']; + + if ($noImplicitWildcard && $reportUnmatched) { foreach ($ignoreErrors as $ignoreError) { if (!is_array($ignoreError)) { continue;