mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add better reporting for errors
This commit is contained in:
parent
1413ccd111
commit
f760ab6707
@ -1111,7 +1111,8 @@ class Config
|
||||
$any_file_path_matched = false;
|
||||
|
||||
foreach ($dependent_files as $dependent_file_path) {
|
||||
if (($project_analyzer->full_run || $codebase->analyzer->canReportIssues($dependent_file_path))
|
||||
if (($codebase->analyzer->canReportIssues($dependent_file_path)
|
||||
|| $project_analyzer->canReportIssues($dependent_file_path))
|
||||
&& !$this->mustBeIgnored($dependent_file_path)
|
||||
) {
|
||||
$any_file_path_matched = true;
|
||||
|
@ -18,6 +18,10 @@ class FileBasedPluginAdapter implements Plugin\PluginEntryPointInterface
|
||||
|
||||
public function __construct(string $path, Config $config, Codebase $codebase)
|
||||
{
|
||||
if (!$path) {
|
||||
throw new \UnexpectedValueException('$path cannot be empty');
|
||||
}
|
||||
|
||||
$this->path = $path;
|
||||
$this->config = $config;
|
||||
$this->codebase = $codebase;
|
||||
|
@ -122,6 +122,11 @@ class ProjectAnalyzer
|
||||
*/
|
||||
public $onchange_line_limit;
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $project_files;
|
||||
|
||||
const TYPE_COMPACT = 'compact';
|
||||
const TYPE_CONSOLE = 'console';
|
||||
const TYPE_PYLINT = 'pylint';
|
||||
@ -204,6 +209,26 @@ class ProjectAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
$project_files = [];
|
||||
|
||||
foreach ($this->config->getProjectDirectories() as $dir_name) {
|
||||
$file_extensions = $this->config->getFileExtensions();
|
||||
|
||||
$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);
|
||||
|
||||
foreach ($file_paths as $file_path) {
|
||||
if ($this->config->isInProjectDirs($file_path)) {
|
||||
$project_files[$file_path] = $file_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->config->getProjectFiles() as $file_path) {
|
||||
$project_files[$file_path] = $file_path;
|
||||
}
|
||||
|
||||
$this->project_files = $project_files;
|
||||
|
||||
$this->output_format = $output_format;
|
||||
self::$instance = $this;
|
||||
}
|
||||
@ -323,6 +348,16 @@ class ProjectAnalyzer
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canReportIssues($file_path)
|
||||
{
|
||||
return isset($this->project_files[$file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $base_dir
|
||||
* @param bool $is_diff
|
||||
@ -361,36 +396,18 @@ class ProjectAnalyzer
|
||||
echo 'Scanning files...' . "\n";
|
||||
}
|
||||
|
||||
$all_files_to_scan = [];
|
||||
|
||||
foreach ($this->config->getProjectDirectories() as $dir_name) {
|
||||
$file_extensions = $this->config->getFileExtensions();
|
||||
|
||||
$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);
|
||||
|
||||
foreach ($file_paths as $file_path) {
|
||||
if ($this->config->isInProjectDirs($file_path)) {
|
||||
$all_files_to_scan[$file_path] = $file_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->config->getProjectFiles() as $file_path) {
|
||||
$all_files_to_scan[$file_path] = $file_path;
|
||||
}
|
||||
|
||||
if ($diff_files === null
|
||||
|| $deleted_files === null
|
||||
|| count($diff_files) > 200
|
||||
|| $this->codebase->find_unused_code) {
|
||||
$this->codebase->scanner->addFilesToDeepScan($all_files_to_scan);
|
||||
$this->codebase->scanner->addFilesToDeepScan($this->project_files);
|
||||
}
|
||||
|
||||
if ($diff_files === null
|
||||
|| $deleted_files === null
|
||||
|| count($diff_files) > 200
|
||||
) {
|
||||
$this->codebase->analyzer->addFiles($all_files_to_scan);
|
||||
$this->codebase->analyzer->addFiles($this->project_files);
|
||||
|
||||
$this->config->initializePlugins($this);
|
||||
|
||||
|
@ -19,8 +19,19 @@ class TestConfig extends Config
|
||||
|
||||
$this->base_dir = getcwd() . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->project_files = new Config\ProjectFileFilter(true);
|
||||
$this->project_files->addDirectory($this->base_dir . 'src');
|
||||
$this->project_files = Config\ProjectFileFilter::loadFromXMLElement(
|
||||
new \SimpleXMLElement(
|
||||
'<?xml version="1.0"?>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<ignoreFiles>
|
||||
<directory name="src/Psalm/Internal/Stubs" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>'
|
||||
),
|
||||
$this->base_dir,
|
||||
true
|
||||
);
|
||||
|
||||
$this->collectPredefinedConstants();
|
||||
$this->collectPredefinedFunctions();
|
||||
|
Loading…
Reference in New Issue
Block a user