Skip to content
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

4.0 | PSR12/FileHeader: make "SpacingAfter" and "SpacingInside" errorcodes modular #35

Open
wants to merge 1 commit into
base: 4.0
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 9, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#2729:

This changes the error codes for the SpacingAfterBlock and SpacingInsideBlock errors to modular error codes which include a reference to the type of header block, i.e. SpacingAfterDeclareBlock, SpacingInsideUseFunctionBlock etc.

This allows for more selective application of the rules.

Take for instance the quite common case of the header blocks all being separated by blank lines, except for the open tag and file docblock.

<?php
/**
 * File docblock.
 */

namespace A\B\C;

use B\C;

The modular errorcodes I'm proposing in this PR will allow for the sniff to be used to safeguard the blank lines between each section without enforcing a blank line between the PHP open tag and the file docblock using:

<rule ref="PSR12.Files.FileHeader">
   <exclude name="PSR12.Files.FileHeader.SpacingAfterTagBlock"/>
</rule>

Fixes squizlabs/PHP_CodeSniffer#3453

Suggested changelog entry

The PSR12.Files.FileHeader sniff now has more modular error codes allowing for selective exclusion of errors.

@jrfnl jrfnl added this to the 4.0.0 milestone Nov 9, 2023
@jrfnl jrfnl force-pushed the feature/psr12-fileheader-more-modular-errorcode-spacing-after branch 2 times, most recently from 73c72b9 to 43504ca Compare November 11, 2023 03:29
@jrfnl jrfnl changed the base branch from master to 4.0 December 2, 2023 03:17
@jrfnl jrfnl force-pushed the feature/psr12-fileheader-more-modular-errorcode-spacing-after branch from 43504ca to 9049c5c Compare December 2, 2023 03:18
@jrfnl jrfnl changed the title PSR12/FileHeader: make "SpacingAfter" and "SpacingInside" errorcodes modular 4.0 | PSR12/FileHeader: make "SpacingAfter" and "SpacingInside" errorcodes modular Dec 2, 2023
@jrfnl jrfnl force-pushed the feature/psr12-fileheader-more-modular-errorcode-spacing-after branch from 9049c5c to c718ba3 Compare December 6, 2023 00:24
…modular

This changes the error codes for the `SpacingAfterBlock` and `SpacingInsideBlock` errors to modular error codes which include a reference to the type of header block, i.e. `SpacingAfterDeclareBlock`, `SpacingInsideUseFunctionBlock` etc.

This allows for more selective application of the rules.

Take for instance the quite common case of the header blocks all being separated by blank lines, except for the open tag and file docblock.
```php
<?php
/**
 * File docblock.
 */

namespace A\B\C;

use B\C;
```

The modular errorcodes I'm proposing in this PR will allow for the sniff to be used to safeguard the blank lines between each section without enforcing a blank line between the PHP open tag and the file docblock using:
```xml
<rule ref="PSR12.Files.FileHeader">
   <exclude name="PSR12.Files.FileHeader.SpacingAfterTagBlock"/>
</rule>
```

Fixes #3453
@jrfnl jrfnl force-pushed the feature/psr12-fileheader-more-modular-errorcode-spacing-after branch from c718ba3 to 650a507 Compare December 7, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Possible to ignore only one speciifc PSR12 rule?
1 participant