-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Problem with NormalizedArrays.Arrays.CommaAfterLast in some cases #283
Comments
BTW, note that the first alternative above:
In practice, render inexistent any difference between mono-line and multi-line, because the former always has the closer in the same/unique (mono) line. |
Making this default behaviour seems to make sense to me. If people want to assert that the closer of a multi-line array is on a different line, one can use another sniff like |
@stronk7 Thanks for bringing this to my attention. Changing the default behaviour would be a breaking change, so I'm not keen on that, but I'm missing another alternative solution:
Having the separate error codes would allow for excluding the applicable error code, while retaining the default behaviour as is. The extra error code could also be considered a breaking change, but one with a smaller impact than changing the default behaviour. What do you think ? |
Yeah, or, also, PHPCSExtra's NormalizedArrays.Arrays.ArrayBraceSpacing available here, that is about enforcing newlines and so on (obviously we don't use that one, because we allow the cases commented above. |
Aha, that's a good 5th alternative, had not thought about it! For sure it will be enough for us to be able to ignore those error codes. |
In that case, I'm open to a PR to make that change. |
Sup, will give a try to it soon, thanks! |
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. For testing, a couple of cases have been added to CommaAfterLastUnitTest.1.inc and then, the fixtures have been 100% duplicated into CommaAfterLastUnitTest.3.inc that runs with the *CloserSameLine errors disabled. A simple diff shows the 8 cases in which the outcome is different, as expected. Fixes PHPCSStandards#283
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. For testing, a couple of cases have been added to CommaAfterLastUnitTest.1.inc and then, the fixtures have been 100% duplicated into CommaAfterLastUnitTest.3.inc that runs with the *CloserSameLine errors disabled. A simple diff shows the 8 cases in which the outcome is different, as expected. Fixes PHPCSStandards#283.
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. For testing, a couple of cases have been added to CommaAfterLastUnitTest.1.inc and then, the fixtures have been 100% duplicated into CommaAfterLastUnitTest.3.inc that runs with the *CloserSameLine errors disabled. A simple diff shows the 8 cases in which the outcome is different, as expected. Fixes PHPCSStandards#283.
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. For testing, a couple of cases have been added to CommaAfterLastUnitTest.1.inc and then, the fixtures have been 100% duplicated into CommaAfterLastUnitTest.3.inc that runs with the *CloserSameLine errors disabled. A simple diff shows the 8 cases in which the outcome is different, as expected. Fixes PHPCSStandards#283.
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. Only for MultiLine cases, they don't make sense in SingleLine ones. For testing, a couple of cases have been added to CommaAfterLastUnitTest.1.inc and then, the fixtures have been 100% duplicated into CommaAfterLastUnitTest.3.inc that runs with the *CloserSameLine errors disabled. A simple diff shows the 8 cases in which the outcome is different, as expected. Fixes PHPCSStandards#283.
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. Only for MultiLine cases, they don't make sense in SingleLine ones. Fixes PHPCSStandards#283
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. Only for MultiLine cases, they don't make sense in SingleLine ones. Fixes PHPCSStandards#283
Some standards may want to have different rules when the array closer is in the same line than the last element. When that happens, the new *CloserSameLine errors are emitted, allowing to disable them via ruleset. Only for MultiLine cases, they don't make sense in SingleLine ones. Fixes PHPCSStandards#283
Bug Description
The
NormalizedArrays.Arrays.CommaAfterLast
does its job pretty well. But there is a case that is hitting us a lot (because of our own coding standard explicitly allowing it), and that I think that can be hitting others out there too.Right now we support all these arrays as valid:
And the Sniff is working ok for all the cases but the 3rd one. And it seems logic not to require a comma there, because, if there are new items to be added to the array later, the line is going to change, yes or yes (the closer will need to be moved.
Given the following reproduction Scenario
Ensure that "Multi-multi line with same line closer " cases don't require a comma.
The issue happens when running this command:
... over a file containing this code:
I'd expect the following behaviour
No errors are reported.
Instead this happened
Five errors are reported.
Environment
Additional Context (optional)
This was originally reported for us @ moodlehq/moodle-cs#76
And this change seems to fix the problem:
Note the TODO that I've put there. IMO there are 4 alternatives:
$validValues
, say:enforce_but_when_sameline_closer
.enforce_skipped_when_sameline_closer
.If there is any insight/preference about any of the 1-3 alternatives above... I'm happy preparing a PR with tests and so on...
Ciao :-)
Tested Against
develop
branch?develop
branch of PHPCSExtra.The text was updated successfully, but these errors were encountered: