Closed davleh closed 7 years ago
The reason you don't get errors in your specific cases is probably because the checks are confirming that code is indented at least the correct number of spaces, but it also allows more spaces to be used for additional indentation. Things like this:
$foo->something()
->somethingElse()
->andSomethingElse();
The indentation checks that PHPCS does ensure that code block opening and closing lines are indented correctly so they set a baseline for the content within them. So that means things like IF and FOR statements must be indented to an exact level, but the code within just needs to be indented at least 4 more spaces after that.
Does that explain things better?
If you think there is a specific code block that is being incorrectly checked based on those rules, then please post it so I can check it.
Ok, that makes sense to me, also for following scenarios:
$something = 'SELECT id
FROM table
WHERE ...';
So, this actually can't be checked against. Thanks for your quick reply. This issue can be closed.
There is a $exact
parameter. Its false by default, when its true indent needs to be exactly 4 spaces. When its false, indent needs to be at least 4 spaces (but can be more).
But It should not be false by default. This behavior must be improved. It needs to check if the new line is in between quotes like @davleh said, or it has ->
prepended like @gsherwood said. When it occurs, then it should not force $exact check.
So this issue must reopen.
I am really tired of seeing unnecessary extra spaces that our developers mistakenly add while coding.
@bcalik The rules of where "extra indent" is allowed are different in every project. You can set the exact
property to true
in your ruleset if that's what you want and pass a selection of tokens in the ignoreIndentationTokens
property to regulate where extra indents are allowed.
This should, IMHO, however, be project/team based, not something which should be solved by PHPCS (other than giving you the tools to do so).
See: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#genericwhitespacescopeindent for more information.
How to reproduce:
Expected:
What actually happens: