diff --git a/bin/verify-inline-ignore.php b/bin/verify-inline-ignore.php new file mode 100644 index 0000000..f38ac47 --- /dev/null +++ b/bin/verify-inline-ignore.php @@ -0,0 +1,33 @@ +isFile() || $entry->getExtension() !== 'php') { + continue; + } + + $realpath = realpath($entry->getPathname()); + $contents = file_get_contents($realpath); + if (strpos($contents, '@phpstan-ignore-') !== false) { + $error = true; + echo $realpath . ' uses @phpstan-ignore-line, use \'@phpstan-ignore identifier (reason)\' instead' . PHP_EOL; + } + } +} + +if ($error) { + exit(1); +} else { + echo 'Ok, no non-identifier based inline ignore found' . PHP_EOL; + exit(0); +} + diff --git a/composer.json b/composer.json index 4194f81..3f85692 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "@check:tests", "@check:dependencies", "@check:collisions", + "@check:ignores", "@check:readme" ], "check:collisions": "detect-collisions src tests", @@ -67,6 +68,7 @@ "check:cs": "phpcs", "check:dependencies": "composer-dependency-analyser", "check:ec": "ec src tests", + "check:ignores": "php bin/verify-inline-ignore.php", "check:readme": "php bin/verify-readme-default-config.php", "check:tests": "phpunit -vvv tests", "check:types": "phpstan analyse -vvv --ansi", diff --git a/src/Rule/EnforceNativeReturnTypehintRule.php b/src/Rule/EnforceNativeReturnTypehintRule.php index 8d4f395..fab1dc6 100644 --- a/src/Rule/EnforceNativeReturnTypehintRule.php +++ b/src/Rule/EnforceNativeReturnTypehintRule.php @@ -255,7 +255,7 @@ private function getUnionTypehint( foreach ($type->getTypes() as $subtype) { $wrap = false; - if ($subtype instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection + if ($subtype instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType if ($this->phpVersion->getVersionId() < 80_200) { // DNF return null; } @@ -286,7 +286,7 @@ private function getIntersectionTypehint( bool $alwaysThrowsException ): ?string { - if (!$type instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection + if (!$type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType return null; } diff --git a/src/Rule/ForbidVariableTypeOverwritingRule.php b/src/Rule/ForbidVariableTypeOverwritingRule.php index 97443c5..acacbb9 100644 --- a/src/Rule/ForbidVariableTypeOverwritingRule.php +++ b/src/Rule/ForbidVariableTypeOverwritingRule.php @@ -85,7 +85,7 @@ private function generalize(Type $type): Type if ( $type->isConstantValue()->yes() || $type instanceof IntegerRangeType - || $type instanceof EnumCaseObjectType // @phpstan-ignore-line ignore instanceof warning + || $type instanceof EnumCaseObjectType // @phpstan-ignore phpstanApi.instanceofType ) { $type = $type->generalize(GeneralizePrecision::lessSpecific()); } @@ -108,7 +108,7 @@ private function removeNullAccessoryAndSubtractedTypes(Type $type): Type return $type; } - if ($type instanceof IntersectionType) { // @phpstan-ignore-line ignore instanceof intersection + if ($type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType $newInnerTypes = []; foreach ($type->getTypes() as $innerType) { diff --git a/tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php b/tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php index 4cf29bf..055f595 100644 --- a/tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php +++ b/tests/Rule/EnforceClosureParamNativeTypehintRuleTest.php @@ -58,7 +58,7 @@ public function testNoErrorOnPhp74(): void private function createPhpVersion(int $version): PhpVersion { - return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise + return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor } } diff --git a/tests/Rule/EnforceNativeReturnTypehintRuleTest.php b/tests/Rule/EnforceNativeReturnTypehintRuleTest.php index 2f5eb6b..14d00ae 100644 --- a/tests/Rule/EnforceNativeReturnTypehintRuleTest.php +++ b/tests/Rule/EnforceNativeReturnTypehintRuleTest.php @@ -63,7 +63,7 @@ public function testPhp74(): void private function createPhpVersion(int $version): PhpVersion { - return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise + return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor } } diff --git a/tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php b/tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php index ef4eda7..2a7d27b 100644 --- a/tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php +++ b/tests/Rule/EnforceReadonlyPublicPropertyRuleTest.php @@ -34,7 +34,7 @@ public function testPhp80(): void private function createPhpVersion(int $version): PhpVersion { - return new PhpVersion($version); // @phpstan-ignore-line ignore bc promise + return new PhpVersion($version); // @phpstan-ignore phpstanApi.constructor } } diff --git a/tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php b/tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php index 3ea4131..2c995ec 100644 --- a/tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php +++ b/tests/Rule/ForbidCheckedExceptionInCallableRuleTest.php @@ -35,7 +35,7 @@ protected function getRule(): Rule return new ForbidCheckedExceptionInCallableRule( self::getContainer()->getByType(NodeScopeResolver::class), self::getContainer()->getByType(ReflectionProvider::class), - new DefaultExceptionTypeResolver( // @phpstan-ignore-line ignore BC promise + new DefaultExceptionTypeResolver( // @phpstan-ignore phpstanApi.constructor self::getContainer()->getByType(ReflectionProvider::class), [], [],