2018-02-18 01:53:17 +01:00
|
|
|
|
# Dealing with code issues
|
|
|
|
|
|
2018-02-27 23:25:35 +01:00
|
|
|
|
Psalm has a large number of [code issues](issues.md). Each project can specify its own reporting level for a given issue.
|
|
|
|
|
|
|
|
|
|
Code issue levels in Psalm fall into three categories:
|
2018-02-18 01:53:17 +01:00
|
|
|
|
<dl>
|
|
|
|
|
<dt>error</dt>
|
2018-03-17 10:48:56 +01:00
|
|
|
|
<dd>This will cause Psalm to print a message, and to ultimately terminate with a non-zero exit status</dd>
|
2018-02-18 01:53:17 +01:00
|
|
|
|
<dt>info</dt>
|
2018-03-17 10:48:56 +01:00
|
|
|
|
<dd>This will cause Psalm to print a message</dd>
|
2018-02-18 01:53:17 +01:00
|
|
|
|
<dt>suppress</dt>
|
2018-03-17 10:48:56 +01:00
|
|
|
|
<dd>This will cause Psalm to ignore the code issue entirely</dd>
|
2018-02-18 01:53:17 +01:00
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
The third category, `suppress`, is the one you will probably be most interested in, especially when introducing Psalm to a large codebase.
|
|
|
|
|
|
|
|
|
|
## Suppressing issues
|
|
|
|
|
|
|
|
|
|
There are two ways to suppress an issue – via the Psalm config or via a function docblock.
|
|
|
|
|
|
|
|
|
|
### Config suppression
|
|
|
|
|
|
|
|
|
|
You can use the `<issueHandlers>` tag in the config file to influence how issues are treated.
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<issueHandlers>
|
|
|
|
|
<MissingPropertyType errorLevel="suppress" />
|
|
|
|
|
|
|
|
|
|
<InvalidReturnType>
|
|
|
|
|
<errorLevel type="suppress">
|
|
|
|
|
<directory name="some_bad_directory" /> <!-- all InvalidReturnType issues in this directory are suppressed -->
|
|
|
|
|
<file name="some_bad_file.php" /> <!-- all InvalidReturnType issues in this file are suppressed -->
|
|
|
|
|
</errorLevel>
|
|
|
|
|
</InvalidReturnType>
|
|
|
|
|
</issueHandlers>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Docblock suppression
|
|
|
|
|
|
|
|
|
|
You can also use `@psalm-suppress IssueName` on a function's docblock to suppress Psalm issues e.g.
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
/**
|
|
|
|
|
* @psalm-suppress InvalidReturnType
|
|
|
|
|
*/
|
|
|
|
|
function (int $a) : string {
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
You can also suppress issues at the line level e.g.
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
/**
|
|
|
|
|
* @psalm-suppress InvalidReturnType
|
|
|
|
|
*/
|
|
|
|
|
function (int $a) : string {
|
|
|
|
|
/**
|
|
|
|
|
* @psalm-suppress InvalidReturnStatement
|
|
|
|
|
*/
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
|
|
|
|
```
|