1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Support suppressing all issues with @psalm-suppress all (#2584)

* Support suppressing all issues using @psalm-suppress all

* Document @psalm-suppress all
This commit is contained in:
Pavel Batečko 2020-01-12 16:38:32 +01:00 committed by Matthew Brown
parent c586b6458d
commit 87debfe954
4 changed files with 65 additions and 0 deletions

View File

@ -91,6 +91,8 @@ function addString(?string $s) {
}
```
`@psalm-suppress all` can be used to suppress all issues instead of listing them individually.
### `@psalm-assert`, `@psalm-assert-if-true` and `@psalm-assert-if-false`
See [Adding assertions](adding_assertions.md).

View File

@ -75,6 +75,8 @@ function (int $a) : string {
}
```
If you wish to suppress all issues, you can use `@psalm-suppress all` instead of multiple annotations.
## Using a baseline file
If you have a bunch of errors and you don't want to fix them all at once, Psalm can now grandfather-in errors in existing code, while ensuring that new code doesn't have those same sorts of errors.

View File

@ -145,6 +145,16 @@ class IssueBuffer
}
}
$suppress_all_position = array_search('all', $suppressed_issues);
if ($suppress_all_position !== false) {
if (\is_int($suppress_all_position)) {
self::$used_suppressions[$file_path][$suppress_all_position] = true;
}
return true;
}
$reporting_level = $config->getReportingLevelForIssue($e);
if ($reporting_level === Config::REPORT_SUPPRESS) {

View File

@ -55,6 +55,44 @@ class IssueSuppressionTest extends TestCase
$this->analyzeFile('somefile.php', new \Psalm\Context());
}
/**
* @return void
*/
public function testUnusedSuppressAllOnFunction()
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile(
'somefile.php',
'<?php
/** @psalm-suppress all */
function foo(): string {
return "foo";
}'
);
$this->analyzeFile('somefile.php', new \Psalm\Context());
}
/**
* @return void
*/
public function testUnusedSuppressAllOnStatement()
{
$this->expectException(\Psalm\Exception\CodeException::class);
$this->expectExceptionMessage('UnusedPsalmSuppress');
$this->addFile(
'somefile.php',
'<?php
/** @psalm-suppress all */
print("foo");'
);
$this->analyzeFile('somefile.php', new \Psalm\Context());
}
/**
* @return void
*/
@ -242,6 +280,19 @@ class IssueSuppressionTest extends TestCase
return new DateTime();
}',
],
'suppressAllStatementIssues' => [
'<?php
/** @psalm-suppress all */
strlen(123, 456, 789);',
],
'suppressAllFunctionIssues' => [
'<?php
/** @psalm-suppress all */
function foo($a)
{
strlen(123, 456, 789);
}',
],
];
}