-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSR12.Files.FileHeader: false positive when there is no header #2997
Comments
This is because the docblock is ambiguous. The sniff can't tell the difference between:
and
So it sees the docblock and reports an error for no blank line after it. If it looked at the next token and tried to guess that this is a docblock for an include statement, it wouldn't error for the second code sample above. I don't have a solution for this. |
@gsherwood Even thought still in draft status, PSR-5 states that an <?php
/**
* File docblock.
*/
class Foo {} Also: why doesn't having the non-Docblock multi-line comment above the Docblock in the original example make a difference ? Shouldn't that signal to the sniff already that everything aside from the PHP open tag is missing ? |
A lot of things can have a docblock, but it's impossible to know if they actually relate to that element. It's just a hard problem where you can post code that should obviously be ignored and I can post code that obviously shouldn't be. It's the same with detecting file comments vs OO structure comments. It's a real pain and whatever I do I'm going to generate false positives.
Because PSR12 specifically says nothing about standard comments in file headers, I have to ignore them. Any time I've not done so for PSR2, I've had developers complaining that the standard doesn't define commenting standards and they can do whatever they want. Which is true, but annoying. |
@gsherwood I hear you. Let me think on this for a while. |
Looks like I am hitting same issue, not as ambiguous however: laminas/laminas-coding-standard#56 With code sniffer 3.5.8 I get
When run on files like: <?php
declare(strict_types=1);
use Mezzio\Application;
use Mezzio\MiddlewareFactory;
use Psr\Container\ContainerInterface;
/**
* FastRoute route configuration
*
* @see https://github.com/nikic/FastRoute
*
* Setup routes with a single request method:
*
* $app->get('/', App\Handler\HomePageHandler::class, 'home');
* $app->post('/album', App\Handler\AlbumCreateHandler::class, 'album.create');
* $app->put('/album/{id:\d+}', App\Handler\AlbumUpdateHandler::class, 'album.put');
* $app->patch('/album/{id:\d+}', App\Handler\AlbumUpdateHandler::class, 'album.patch');
* $app->delete('/album/{id:\d+}', App\Handler\AlbumDeleteHandler::class, 'album.delete');
*
* Or with multiple request methods:
*
* $app->route('/contact', App\Handler\ContactHandler::class, ['GET', 'POST', ...], 'contact');
*/
return static function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {
}; Docblock belongs to closure here and not file level |
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#21 |
Given the following code run against the PSR12 standard:
I get the following error:
... while I expected none.
The text was updated successfully, but these errors were encountered: