-
-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Labels
Description
Describe the bug
Given:
- You have a ruleset with the
Generic.WhiteSpace.ScopeIndentsniff enabled - The sniff is configured so that
T_OPEN_TAGandT_CLOSE_TAGare inignoreIndentationTokens - You have any other sniff enabled that provides autofixing
- You have a file that contains PHP open/close tags (and whose indentation is perhaps incorrect, but that's beyond the point)
- The ScopeIndent sniff is disabled for that file
- The other sniff finds an autofixable issue on that file
Then, phpcs won't report anything from ScopeIndent, but phpcbf will still make unwanted indentation changes.
Code sample
<?php
// phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
use \stdClass;
class Page {
public function flush() {
?><!DOCTYPE html>
<html dir="ltr" lang="en-US">
<?php
if ( rand() ) {
echo 'foo';
}
?>
</html>
<?php
}
}Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<rule ref="PSR12.Files.ImportStatement" />
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="ignoreIndentationTokens" type="array">
<element value="T_OPEN_TAG" />
<element value="T_CLOSE_TAG" />
</property>
</properties>
</rule>
</ruleset>To reproduce
Steps to reproduce the behavior:
- Create a file called
test.phpwith the code sample above - Run
phpcs -s test.php - Notice how ScopeIndent does not report anything, only the other sniff:
----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------
5 | ERROR | [x] Import statements must not begin with a leading backslash (PSR12.Files.ImportStatement.LeadingSlash)
----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------
- Run
phpcbf test.php - Notice how it fixed not only the leading backslash, but also indentation:
5c5
< use \stdClass;
---
> use stdClass;
13c13
< echo 'foo';
---
> echo 'foo';Expected behavior
The ScopeIndent autofixer should not make unwanted changes when no issues are reported.
Versions (please complete the following information)
| Operating System | Ubuntu 24.04 |
| PHP version | 8.5.2 |
| PHP_CodeSniffer version | 4.x (commit 8b1c267) |
| Standard | custom |
| Install type | composer local |
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
4.xbranch of PHP_CodeSniffer.
Reactions are currently unavailable