Skip to content

Generic.Strings.UnnecessaryHeredoc incorrectly converts tabs into spaces in heredoc #1320

@anomiex

Description

@anomiex

Describe the bug

If --tab-width is set, the fixer for Generic.Strings.UnnecessaryHeredoc incorrectly converts tabs into spaces in lines edited in the heredoc.

Code sample

Note this file must be indented using tabs, not spaces.

<?php

$var = <<<EOF
	Normal line
	Test \$escaped var
	Normal line
EOF;

Custom ruleset

N/A

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Run phpcbf -s --tab-width=8 --standard=Generic --sniffs=Generic.Strings.UnnecessaryHeredoc test.php
  3. Examine the file.

Expected behavior

File content is

<?php

$var = <<<'EOF'
	Normal line
	Test $escaped var
	Normal line
EOF;

Actual behavior

File content is

<?php

$var = <<<'EOF'
	Normal line
        Test $escaped var
	Normal line
EOF;

i.e. the line "Test $escaped var" is indented with 8 spaces rather than one tab.

Versions (please complete the following information)

Operating System Debian unstable
PHP version 8.4.11
PHP_CodeSniffer version 4.x-dev 4067971. Also reproduces with 3.13.5, 3.13.3, and 3.13.2.
Standard Generic
Install type Composer local

Additional context

Add any other context about the problem here.

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.x branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions