-
-
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
Split the errors, adding the *CloserSameLine ones #284
Split the errors, adding the *CloserSameLine ones #284
Conversation
OT, sharing because it happened to me... I just found that something in composer is not installing things properly, neither |
@stronk7 Thanks for the PR, I'll try to review it over the next few days.
Just tried myself and all seems fine, so I'm not sure what happened for you. As for the "platform constraint": the repo doesn't have one, so I don't know what you mean. The only real (known) problem with the tests is that you need to run them locally on PHP 7.4 or lower as otherwise you run into issues with PHPUnit 7.5. There are work-arounds for that, see: https://github.com/PHPCSStandards/PHPCSExtra/blob/develop/.github/workflows/quicktest.yml , but the simple solution is to just run on PHP 7.4. |
@stronk7 I've just had a quick glance at the PR and first thing I noticed is that the new error code is not just reserved for multi-line arrays. |
P.S.: no need to worry about the code coverage builds failing - this is a known issue and I'm working with Coveralls to fix that. |
Thanks for the composer comments and tricks… I’ll try again tomorrow from scratch. Maybe I had some old lock file around and that caused the troubles… Regarding applying it only to multilines, cannot but agree. As commented in the issue, it really doesn’t make sense for singles. I will amend the PR tomorrow, thanks! |
865c8d9
to
a23d82b
Compare
Patch updated to only apply the "CloserSameLine" error code suffix to multi lines (with tests amended to ensure that's what it's being done). Ciao :-) |
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.
@stronk7 Hi Eloy, thank you for fixing that up.
I've now done a proper review of the PR and the principle of the fix is now correct 👍🏻 .
I've left some nitpicky comments inline to tidy that up a little still, but that doesn't affect the actual functional change, which is good.
As for the tests...
While I appreciate how much attention you've given to the tests, the way this is done now, means the diff is much bigger than it should be, what with all test lines being renumbered. This also makes it much harder than it should be to review the PR.
As a rule of thumb: always put new tests at the bottom of a test case file (or in a new file if so warranted) with a comment explaining what those tests are related to.
Do not touch or cause to re-number the pre-existing tests.
In all honesty, the 3
test case file is redundant, as it isn't testing anything new in the PHPCSExtra repo. It is testing whether PHPCS handles the disable/ignore annotations correctly, but that is something which should be (and is) tested in the PHPCS repo.
So, in short:
- Please remove the
3
test case file. - Please remove the comment at the top of the
1
test case file. - Please move the new tests in the
1
test case file to the bottom of the file (just above the reset) and add appropriatephpcs:set
comments for each situation and add a comment to describe why these tests were added and what is specifically being tested with them. Include the issue number in the comment as a reference.
As for the actual tests, these are only testing the "unhappy" path (= the path which throws an error).
I'm missing tests with multi-line arrays with the closer on the same line as the last content, which don't trigger an error, both for the forbid
, as well as the enforce
case.
And for completeness of testing the actual change, you may want to also add single line test code just to demonstrate that those aren't affected, but I'm fine with leaving those out as well, as this can also be confirmed via the pre-existing tests.
Sorry to be a pain. Please let me know if you have questions.
P.S.: if you rebase the PR on the current |
No worries, I'm used, LOL :-) Thanks for the review, I'll go towards all the the test changes and suggestions later today. |
a23d82b
to
1694346
Compare
Ok, I think I've followed all your suggestions and the new candidate PR follows all them. Only point that I'm not 100% convinced is the one about not covering with tests what happens when the Note I don't mind much, because for sure we are going to add some tests covering that in our standard, but I think that it should be tested here because, as said, it's not covering the new real code at all. Ciao :-) |
e19550b
to
3d6192a
Compare
Adding on my previous comment... what I'd add to the tests is this (I think it's the minimum patch I've been able to create): You can see that it doesn't change the tests outcome (all the new lines are ok, because we are ignoring the For your consideration, I'm happy to fixup this PR with that commit or to leave it apart (and to add a similar testing to our standard, ensuring that the new error codes work as expected). Ciao :-) |
Okay, so let's split this up:
I agree that 2 is problematic, and that's inherent to the PHPCS native test framework, which is being used as a base for these tests. I'd be okay with you adding the extra tests you propose. I think only one for each type (missing/found) would be fine and that those can be in the same |
Ok, will amend the commit to incorporate ONE missing and ONE found case to the 2 "new sections" fixtures introduced here. OT: Since we started to use phpcs long ago... one of the first things we did is to switch to a "richer" testing alternative. It supports the normal |
👍🏻
Looks interesting, but not quite what I had in mind. We use a custom test case in PHPCompatibility as well. Basically, what I'm looking to create would be a "best of these worlds" situation, where it would give sniff writers the flexibility to test what they want to test, while also making the test suites straight-forward to maintain. Keep en eye on PHPCSUtils or subscribe to the issue if you'd like to stay informed. |
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
3d6192a
to
ef6ab26
Compare
Patch amended, by adding the 2 agreed new cases (using phpcs:ignore).
|
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.
All good! Thanks for contributing and for bearing with me to get this to where it is now.
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 #283.