1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Merge pull request #8502 from kkmuffme/option-to-only-report-errors-for-passed-file

add hideAllErrorsExceptPassedFiles config option
This commit is contained in:
orklah 2022-09-25 13:02:00 +02:00 committed by GitHub
commit 313ebf428b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -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`. 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 #### cacheDirectory
```xml ```xml
<psalm <psalm

View File

@ -295,6 +295,11 @@ class Config
*/ */
public $hide_external_errors = false; public $hide_external_errors = false;
/**
* @var bool
*/
public $hide_all_errors_except_passed_files = false;
/** @var bool */ /** @var bool */
public $allow_includes = true; public $allow_includes = true;
@ -926,6 +931,7 @@ class Config
'useDocblockPropertyTypes' => 'use_docblock_property_types', 'useDocblockPropertyTypes' => 'use_docblock_property_types',
'throwExceptionOnError' => 'throw_exception', 'throwExceptionOnError' => 'throw_exception',
'hideExternalErrors' => 'hide_external_errors', 'hideExternalErrors' => 'hide_external_errors',
'hideAllErrorsExceptPassedFiles' => 'hide_all_errors_except_passed_files',
'resolveFromConfigFile' => 'resolve_from_config_file', 'resolveFromConfigFile' => 'resolve_from_config_file',
'allowFileIncludes' => 'allow_includes', 'allowFileIncludes' => 'allow_includes',
'strictBinaryOperands' => 'strict_binary_operands', 'strictBinaryOperands' => 'strict_binary_operands',
@ -1567,6 +1573,13 @@ class Config
$project_analyzer = ProjectAnalyzer::getInstance(); $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(); $codebase = $project_analyzer->getCodebase();
if (!$this->hide_external_errors) { if (!$this->hide_external_errors) {

View File

@ -204,6 +204,11 @@ class ProjectAnalyzer
*/ */
public $provide_completion = false; public $provide_completion = false;
/**
* @var list<string>
*/
public $check_paths_files = [];
/** /**
* @var array<string,string> * @var array<string,string>
*/ */
@ -1178,6 +1183,7 @@ class ProjectAnalyzer
if (is_dir($path)) { if (is_dir($path)) {
$this->checkDirWithConfig($path, $this->config, true); $this->checkDirWithConfig($path, $this->config, true);
} elseif (is_file($path)) { } elseif (is_file($path)) {
$this->check_paths_files[] = $path;
$this->codebase->addFilesToAnalyze([$path => $path]); $this->codebase->addFilesToAnalyze([$path => $path]);
$this->config->hide_external_errors = $this->config->isInProjectDirs($path); $this->config->hide_external_errors = $this->config->isInProjectDirs($path);
} }