PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
880 stars 54 forks source link

Indenting not fixed #405

Closed adam-nielsen closed 5 months ago

adam-nielsen commented 6 months ago

Discussed in https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions/399

Converting to an issue as requested.

Originally posted by **adam-nielsen** March 15, 2024 I have a bunch of poorly formatted code, but I can't figure out how to get basic stuff like the indenting fixed. For example this file: ```php if (!$a) { if ($b) { // Single line comment indented too far. $a = $b; } else { /* Comment indented too far. */ $x = true; /* Another comment indented incorrectly. */ $y = true; } } ``` When I run it, it says: ``` $ php phpcbf.phar --standard=PSR12 test.php PHPCBF RESULT SUMMARY ---------------------------------------- FILE FIXED REMAINING ---------------------------------------- test.php 4 0 ---------------------------------------- A TOTAL OF 4 ERRORS WERE FIXED IN 1 FILE ---------------------------------------- Time: 65ms; Memory: 8MB ``` But all it has done is put that `else` back on the same line, it hasn't fixed the indenting of any statements or of the comments inside the curly braces. What am I doing wrong?
adam-nielsen commented 5 months ago

Closing issue - per the linked discussion, the issue was that unlike linters in other languages, the default rules in phpcs don't enforce any indenting rules. Manually turning them on makes it work as expected.