mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fix #199 - allow classes to suppress PropertyNotSetInConstructor warnings
This commit is contained in:
parent
439a1ddc97
commit
eee8442af6
@ -639,7 +639,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
|||||||
$this->fq_class_name . ' or in any private methods called in the constructor',
|
$this->fq_class_name . ' or in any private methods called in the constructor',
|
||||||
$error_location
|
$error_location
|
||||||
),
|
),
|
||||||
$this->source->getSuppressedIssues()
|
array_merge($this->source->getSuppressedIssues(), $storage->suppressed_issues)
|
||||||
)) {
|
)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,13 @@ class CommentChecker
|
|||||||
$info->deprecated = true;
|
$info->deprecated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($comments['specials']['psalm-suppress'])) {
|
||||||
|
/** @var string $suppress_entry */
|
||||||
|
foreach ($comments['specials']['psalm-suppress'] as $suppress_entry) {
|
||||||
|
$info->suppressed_issues[] = preg_split('/[\s]+/', $suppress_entry)[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($comments['specials']['property'])) {
|
if (isset($comments['specials']['property'])) {
|
||||||
/** @var string $property */
|
/** @var string $property */
|
||||||
foreach ($comments['specials']['property'] as $line_number => $property) {
|
foreach ($comments['specials']['property'] as $line_number => $property) {
|
||||||
|
@ -19,4 +19,9 @@ class ClassLikeDocblockComment
|
|||||||
* @var array<int, array{name:string, type:string}>
|
* @var array<int, array{name:string, type:string}>
|
||||||
*/
|
*/
|
||||||
public $properties = [];
|
public $properties = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
public $suppressed_issues = [];
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,11 @@ class ClassLikeStorage
|
|||||||
*/
|
*/
|
||||||
public $deprecated = false;
|
public $deprecated = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
public $suppressed_issues = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -217,6 +217,8 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
|||||||
}
|
}
|
||||||
|
|
||||||
$storage->deprecated = $docblock_info->deprecated;
|
$storage->deprecated = $docblock_info->deprecated;
|
||||||
|
|
||||||
|
$storage->suppressed_issues = $docblock_info->suppressed_issues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,6 +407,16 @@ class PropertyTypeTest extends TestCase
|
|||||||
|
|
||||||
class E extends \Exception{}',
|
class E extends \Exception{}',
|
||||||
],
|
],
|
||||||
|
'notSetInEmptyConstructor' => [
|
||||||
|
'<?php
|
||||||
|
/** @psalm-suppress PropertyNotSetInConstructor */
|
||||||
|
class A {
|
||||||
|
/** @var int */
|
||||||
|
public $a;
|
||||||
|
|
||||||
|
public function __construct() { }
|
||||||
|
}',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user