-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Generic.Array.ArrayCommaSpacingSniff #2759
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
Conversation
|
Some review notes:
Personally, I think the "comma after last" check should be a separate sniff from the "spacing around comma's" check, which could actually be turned into a more generic spacing around comma's check independently of arrays. |
I don't know this but found this example on internet. Did you talk about this ?
Is it wrong ?
There is already But I can split this into CommaAfterLast and ArrayCommaSpacing if needed. |
|
I think trailing commas in multi-line arrays should be an option, because not everyone uses them. |
@glen-84 I'm sorry but I don’t understand. That’s the principe of a Sniff. You use it only if you want the check to be done. Did you mean the spacing check and the comma check should be split in two different sniffs ? |
If that were true, then sniffs like Some developers may want to enforce the opposite (no trailing commas), so an option like Anyway, you don't have to add it, it's just a suggestion. |
|
Ok I understood what you mean. I added the option @glen-84. I also added an option for hereDoc/nowDoc in order to avoid parse error with php < 7.3 |
|
I prefer different sniffs to do things like enforce a trailing comma or enforce no trailing comma, rather than have a property for the sniff. It makes it easier for people to understand when the sniff has a singular purpose, so new sniffs should try and do this. I also agree that this specific rule (comma or not) should live alone inside a sniff and not be mixed up with spacing requirements. Having said that, I think the array comma sniffs do actually need a property so that a developer can decide if they want commas required/banned after both single and multi-line arrays. So I'd see 2 sniffs here: Both might have a property called To use the sniffs to enforce no comma at the end of single-line array declarations and enforce a comma for multi-line definitions, you'd so something like this: <rule ref="Generic.Arrays.EndComma">
<properties>
<property name="type" value="multi"/>
</properties>
</rule>
<rule ref="Generic.Arrays.DisallowEndComma">
<properties>
<property name="type" value="single"/>
</properties>
</rule>Thoughts? |
|
I was ok with two sniffs : one with spacing and one with trailing comma. I understand your point of view, about creating two sniff but I'm disturbed with the following fact. If I create a And if I create a That's why maybe the best split of this sniff is :
What do you think about this split @gsherwood ? |
I'd be happy with that as well. Assuming the property is called <rule ref="Generic.Arrays.MultiLineTrailingCommaSniff" />
<rule ref="Generic.Arrays.SingleLineTrailingCommaSniff">
<properties>
<property name="allow" value="false"/>
</properties>
</rule> |
Ok, I'll work on it. What would be the 'good' default value according to you ? Based on usage, I think it would be :
But maybe consistency is preferred and then it's better to be
|
|
By the way, I think i didn't fix all the issue with HereDoc/NowDoc. Is actually untouched. But Is fixed to I need to work on this too. |
As per my example, I thought the default would be |
Isn't it weird having the default value to But you have the final word. |
Then you'd write a sniff called DisallowSingleLineTrailingCommaSniff and have no option, making the assumption that nobody will ever want this. I'd be happy with that option as well. |
|
Ok ! I'll go with this. |
|
I apologize for my incorrect suggestion, I had no idea that Greg would want separate sniffs for this. I had assumed that it may just look something like this: <rule ref="Generic.Arrays.TrailingCommaSniff">
<properties>
<property name="singleLine" value="false" /> <!-- default -->
<property name="multiLine" value="true" /> <!-- default (possibly false) -->
</properties>
</rule>It seems a bit strange to me to have separate sniffs for each variation (think |
|
No problem, @glen-84. @gsherwood I'll start with the ArrayCommaSpacingSniff. |
|
Hi @gsherwood ! Are you interested by this PR ? :) |
This sniff checks:
Todo List for other sniff: