mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +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:
parent
c586b6458d
commit
87debfe954
@ -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).
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user