-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: Add strict option to array indentation #7846
feat: Add strict option to array indentation #7846
Conversation
0f47528
to
e099e9f
Compare
e099e9f
to
682221e
Compare
Friendly ping @Wirone @kubawerlos :) This would help me to make #7813 useful |
@@ -35,6 +39,7 @@ public function getDefinition(): FixerDefinitionInterface | |||
'Each element of an array must be indented exactly once.', | |||
[ | |||
new CodeSample("<?php\n\$foo = [\n 'bar' => [\n 'baz' => true,\n ],\n];\n"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I don't get what this option does, are you able to update the samples to have the same input code with both strict
options to see the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code sample, it more clear now ?
The difference is the same than
SINGLE_SPACE
vs AT_LEAST_SINGLE_SPACE
for the BinaryOperatorSpacesFixer
.
Currently, array_indentation
enforce EXACTLY one indentation.
When looking at PSR12, it enforce indentation but not "exactly" one, so it could be considered to add the rule with the strict => false
option to enforce AT LEAST one indentation.
This option would be also useful for SymfonyRuleset since they use indentation, but sometimes use more than one indentation.
In my case this would be useful for #7813 because I need a fixer to resolve indentation after mine but the array_indentation
is too strict atm to be added in the PSR ruleset.
I don't find the "at least" words in the "Arrays" section of PER CS 2.0:
PSR-12 does not specifically provide guidelines for arrays and PSR-2 does not use the words "at least" at all. Maybe I'm missing something but I don't see a need for this option. I would add the rule to the Also, formatting arrays like e.g. [
'foo',
'bar',
] seems a bit off. Do you know actual use cases? |
Yes, for PERCS 2.0 it should be strict
Not really, I thought this would help to add the array_indentation rule to PSR/PERCS, but that's maybe not a good idea. |
Hi @Wirone,
When working on #7813, I discovered that:
array_indentation
to be use if someone wants to usesingle_expression_per_line
for arraysarray_indentation
is not added to any PSR sets.If we wants to add the
single_expression_per_line
for arrays to the PERCS 2, which would resolve the partwe will need to indent correctly the array. So we will need
array_indentation
in PERCS 2 too or at least in a less strict version: "Each element of an array must be indented AT LEAST once."When looking at PSR12 and PSR2, there is the following section
I think the
array_indentation
is going in this direction and therefore could be added to the PSR2 ruleset (with the optionstrict => false
to minimize the impact). This would be similar to thestatement_indentation
which is already added to the PSR2 ruleset.WDYT ?
array_indentation
withstrict => false
to the PSR2 ?array_indentation
withstrict => false
to the PERCS 2 only ?array_indentation
withstrict => true
to the PERCS 2 ?For the records,
array_indentation
withstrict => true
(since the option didn't exist)array_indentation
but withstrict => false
there are some fixes in the code base which seems to be typo most of the time (like 3 spaces instead of 4) ; there was way more fixes withstrict => true
, so maybe it's voluntary to sometime use more indentations.