Skip to content

Commit

Permalink
Merge pull request #8502 from kkmuffme/option-to-only-report-errors-f…
Browse files Browse the repository at this point in the history
…or-passed-file

add hideAllErrorsExceptPassedFiles config option
  • Loading branch information
orklah committed Sep 25, 2022
2 parents b55fc2b + b68ac86 commit 313ebf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/running_psalm/configuration.md
Expand Up @@ -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 `<projectFiles>`. Defaults to `false`.

#### hideAllErrorsExceptPassedFiles
```xml
<psalm
hideAllErrorsExceptPassedFiles="[bool]"
>
```
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
<psalm
Expand Down
13 changes: 13 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -204,6 +204,11 @@ class ProjectAnalyzer
*/
public $provide_completion = false;

/**
* @var list<string>
*/
public $check_paths_files = [];

/**
* @var array<string,string>
*/
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 313ebf4

Please sign in to comment.