Skip to content

Commit

Permalink
Fix that files passed via CLI but are not in projectFiles reported on…
Browse files Browse the repository at this point in the history
…ly a limited, random selection of errors instead of all - treat all files passed as CLI args as if they were in projectFiles
  • Loading branch information
kkmuffme committed Nov 15, 2023
1 parent 3cabd73 commit 90aba2b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -21,6 +21,7 @@
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\Analyzer\FileAnalyzer;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\CliUtils;
use Psalm\Internal\Composer;
use Psalm\Internal\EventDispatcher;
use Psalm\Internal\IncludeCollector;
Expand Down Expand Up @@ -1298,6 +1299,41 @@ private static function fromXmlAndPaths(
$config->project_files = ProjectFileFilter::loadFromXMLElement($config_xml->projectFiles, $base_dir, true);
}

// any paths passed via CLI should be added to the projectFiles
// as they're getting analyzed like if they are part of the project
// ProjectAnalyzer::getInstance()->check_paths_files is not populated at this point in time
$paths_to_check = CliUtils::getPathsToCheck(null);
if ($paths_to_check !== null) {
$paths_to_add_to_project_files = array();
foreach ($paths_to_check as $path) {
if ($config->isInProjectDirs($path)) {
continue;
}

$paths_to_add_to_project_files[] = $path;
}

if ($paths_to_add_to_project_files !== array() && !isset($config_xml->projectFiles)) {
if ($config_xml === null) {
$config_xml = new SimpleXMLElement('<psalm/>');
}
$config_xml->addChild('projectFiles');
}

if ($paths_to_add_to_project_files !== array()) {
foreach ($paths_to_add_to_project_files as $path) {
$child = $config_xml->projectFiles->addChild('file');
$child->addAttribute('name', $path);
}

$config->project_files = ProjectFileFilter::loadFromXMLElement(
$config_xml->projectFiles,
$base_dir,
true,
);
}
}

if (isset($config_xml->extraFiles)) {
$config->extra_files = ProjectFileFilter::loadFromXMLElement($config_xml->extraFiles, $base_dir, true);
}
Expand Down

0 comments on commit 90aba2b

Please sign in to comment.