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

add hideAllErrorsExceptPassedFiles config option #8502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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