Php_codesniffer: PSR12.Files.FileHeader false positive when file only contains docblock

Created on 27 Sep 2019  路  6Comments  路  Source: squizlabs/PHP_CodeSniffer

FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Header blocks must be followed by a single blank line

is unfixable.
It doesn't respect a file that only contains a docblock.

code is:

<?php

/**
 * Here go your local configs
 */
Bug

Most helpful comment

Is there an explanation on why it's impossible to do the following?

Those sort of questions are better directed to the authors of PSR-12. I had nothing to do with the writing of the standard so I can't talk to the decisions within it. I've just implemented it in PHPCS as faithfully as I can.

All 6 comments

I think Datadog/dd-trace-php is hitting this same issue for a different reason in branch levi/phpcs:

circleci@82b8c67c4988:~/app$ composer lint
> phpcs -s --ignore=src/DDTrace/Integrations/ZendFramework/V1/Ddtrace.php

FILE: /home/circleci/app/tests/Unit/Util/TryCatchFinallyTest.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 226 | ERROR | [x] Header blocks must be followed by a single blank
     |       |     line
     |       |     (PSR12.Files.FileHeader.SpacingAfterBlock)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 39.58 secs; Memory: 20.25MB

Script phpcs -s --ignore=src/DDTrace/Integrations/ZendFramework/V1/Ddtrace.php handling the lint event returned with error code 2
circleci@82b8c67c4988:~/app$ composer fix-lint
> phpcbf

PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
...cleci/app/tests/Unit/Util/TryCatchFinallyTest.php  FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------

Time: 37.31 secs; Memory: 20.25MB


Script phpcbf handling the fix-lint event returned with error code 2

I've since disabled the lint, so be sure to use the link as it points to a specific commit.

Thanks for the report. I've committed a fix, which will be in 3.5.1.

It''s bugging out all of my repos...

We've been doing <?php declare(strict_types=1); for years and years. It's by far the best place for it.

Hi,

Is there an explanation on why it's impossible to do the following?

<?php
declare(strict_types=1);

The blank line is a waste of space imo.

The already added newline is a big waste of space :)
There is no good reasoning here IMO - just a decision made by them that you can chose to ignore.

Is there an explanation on why it's impossible to do the following?

Those sort of questions are better directed to the authors of PSR-12. I had nothing to do with the writing of the standard so I can't talk to the decisions within it. I've just implemented it in PHPCS as faithfully as I can.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brzuchal picture brzuchal  路  3Comments

slawkens picture slawkens  路  3Comments

wowcut picture wowcut  路  3Comments

petegore picture petegore  路  3Comments

justintadlock picture justintadlock  路  3Comments