Skip to content
Permalink
Browse files

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

* Support suppressing all issues using @psalm-suppress all

* Document @psalm-suppress all
  • Loading branch information
ShiraNai7 authored and muglug committed Jan 12, 2020
1 parent c586b64 commit 87debfe954b2f754029e6e4097fbc83f586f5508
@@ -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 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = [])
}
}

$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 @@ public function testIssueSuppressedOnStatement()
$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 @@ function verify_return_type(): DateTime {
return new DateTime();
}',
],
'suppressAllStatementIssues' => [
'<?php
/** @psalm-suppress all */
strlen(123, 456, 789);',
],
'suppressAllFunctionIssues' => [
'<?php
/** @psalm-suppress all */
function foo($a)
{
strlen(123, 456, 789);
}',
],
];
}

0 comments on commit 87debfe

Please sign in to comment.
You can’t perform that action at this time.