From b1c0c2d8a1a482491b6219cb6fd77b1e1de4c8d4 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:10:27 +0200 Subject: [PATCH 1/2] add hideAllErrorsExceptPassedFiles config option for files only (not directories, since that wouldn't make practical sense) --- src/Psalm/Config.php | 13 +++++++++++++ src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index c97021c5ed3..72d7ae02b4c 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -295,6 +295,11 @@ class Config */ public $hide_external_errors = false; + /** + * @var bool + */ + public $hide_all_errors_except_passed_files = false; + /** @var bool */ public $allow_includes = true; @@ -926,6 +931,7 @@ private static function fromXmlAndPaths( 'useDocblockPropertyTypes' => 'use_docblock_property_types', 'throwExceptionOnError' => 'throw_exception', 'hideExternalErrors' => 'hide_external_errors', + 'hideAllErrorsExceptPassedFiles' => 'hide_all_errors_except_passed_files', 'resolveFromConfigFile' => 'resolve_from_config_file', 'allowFileIncludes' => 'allow_includes', 'strictBinaryOperands' => 'strict_binary_operands', @@ -1567,6 +1573,13 @@ public function reportIssueInFile(string $issue_type, string $file_path): bool $project_analyzer = ProjectAnalyzer::getInstance(); + // if the option is set and at least one file is passed via CLI + if ($this->hide_all_errors_except_passed_files + && $project_analyzer->check_paths_files + && !in_array($file_path, $project_analyzer->check_paths_files, true)) { + return false; + } + $codebase = $project_analyzer->getCodebase(); if (!$this->hide_external_errors) { diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 40b3316df2a..21cc4ca0893 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -204,6 +204,11 @@ class ProjectAnalyzer */ public $provide_completion = false; + /** + * @var list + */ + public $check_paths_files = []; + /** * @var array */ @@ -1178,6 +1183,7 @@ public function checkPaths(array $paths_to_check): void if (is_dir($path)) { $this->checkDirWithConfig($path, $this->config, true); } elseif (is_file($path)) { + $this->check_paths_files[] = $path; $this->codebase->addFilesToAnalyze([$path => $path]); $this->config->hide_external_errors = $this->config->isInProjectDirs($path); } From b68ac865e1ab2ed97d9e83471c3795b93b7d3c7f Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Sat, 24 Sep 2022 10:44:12 +0200 Subject: [PATCH 2/2] add docs --- docs/running_psalm/configuration.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/running_psalm/configuration.md b/docs/running_psalm/configuration.md index f24d4542cc8..6a7f4856bc2 100644 --- a/docs/running_psalm/configuration.md +++ b/docs/running_psalm/configuration.md @@ -400,6 +400,14 @@ Useful in testing, this makes Psalm throw a regular-old exception when it encoun ``` Whether or not to show issues in files that are used by your project files, but which are not included in ``. Defaults to `false`. +#### hideAllErrorsExceptPassedFiles +```xml + +``` +Whether or not to report issues only for files that were passed explicitly as arguments in CLI. This means any files that are loaded with require/include will not report either, if not set in CLI. Useful if you want to only check errors in a single or selected files. Defaults to `false`. + #### cacheDirectory ```xml