Skip to content

Commit

Permalink
Merge pull request #10694 from weirdan/suppress-unused-suppression-de…
Browse files Browse the repository at this point in the history
…tection-in-partial-and-cache-mode
  • Loading branch information
weirdan authored Feb 11, 2024
2 parents 5624533 + b3a44c5 commit 1d53427
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ final class Codebase

public bool $diff_methods = false;

/** whether or not we only checked a part of the codebase */
public bool $diff_run = false;

/**
* @var array<lowercase-string, string>
*/
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public function check(string $base_dir, bool $is_diff = false): void

$this->codebase->infer_types_from_usage = true;
} else {
$this->codebase->diff_run = true;
$this->progress->debug(count($diff_files) . ' changed files: ' . "\n");
$this->progress->debug(' ' . implode("\n ", $diff_files) . "\n");

Expand Down
75 changes: 44 additions & 31 deletions src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
use function usort;

use const DEBUG_BACKTRACE_IGNORE_ARGS;
use const PHP_EOL;
use const PSALM_VERSION;
use const STDERR;

Expand Down Expand Up @@ -650,39 +651,42 @@ public static function finish(
}

if ($codebase->config->find_unused_issue_handler_suppression) {
foreach ($codebase->config->getIssueHandlers() as $type => $handler) {
foreach ($handler->getFilters() as $filter) {
if ($filter->suppressions > 0 && $filter->getErrorLevel() == Config::REPORT_SUPPRESS) {
continue;
}
$issues_data['config'][] = new IssueData(
IssueData::SEVERITY_ERROR,
0,
0,
UnusedIssueHandlerSuppression::getIssueType(),
sprintf(
'Suppressed issue type "%s" for %s was not thrown.',
$type,
str_replace(
$codebase->config->base_dir,
'',
implode(', ', [...$filter->getFiles(), ...$filter->getDirectories()]),
if ($is_full && !$codebase->diff_run) {
foreach ($codebase->config->getIssueHandlers() as $type => $handler) {
foreach ($handler->getFilters() as $filter) {
if ($filter->suppressions > 0 && $filter->getErrorLevel() == Config::REPORT_SUPPRESS) {
continue;
}
$issues_data['config'][] = new IssueData(
IssueData::SEVERITY_ERROR,
0,
0,
UnusedIssueHandlerSuppression::getIssueType(),
sprintf(
'Suppressed issue type "%s" for %s was not thrown.',
$type,
str_replace(
$codebase->config->base_dir,
'',
implode(', ', [...$filter->getFiles(), ...$filter->getDirectories()]),
),
),
),
$codebase->config->source_filename ?? '',
'',
'',
'',
0,
0,
0,
0,
0,
0,
UnusedIssueHandlerSuppression::SHORTCODE,
UnusedIssueHandlerSuppression::ERROR_LEVEL,
);
$codebase->config->source_filename ?? '',
'',
'',
'',
0,
0,
0,
0,
0,
0,
UnusedIssueHandlerSuppression::SHORTCODE,
UnusedIssueHandlerSuppression::ERROR_LEVEL,
);
}
}
} else {
}
}

Expand Down Expand Up @@ -827,6 +831,15 @@ public static function finish(
echo "\n";
}
}

if ($codebase->config->find_unused_issue_handler_suppression && (!$is_full || $codebase->diff_run)) {
fwrite(
STDERR,
PHP_EOL . 'To whom it may concern: Psalm cannot detect unused issue handler suppressions when'
. PHP_EOL . 'analyzing individual files and folders or running in diff mode. Run on the full'
. PHP_EOL . 'project with diff mode off to enable unused issue handler detection.' . PHP_EOL,
);
}
}

if ($is_full && $start_time) {
Expand Down

0 comments on commit 1d53427

Please sign in to comment.