-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Ensure that Fixer::endChangeset() returns the real outcome #375
base: master
Are you sure you want to change the base?
Conversation
I was debugging a complex sniff that implies multiple potential modifications to the same token (that is, right now, not possible - we could discuss about that another day), when have detected that the Fixer::endChangeset() method is returning always true, no matter the changes have been not accepted. So this just ensures that the method returns the real outcome. I've been looking to current tests to try to add something to have it covered, but it seems that the Fixer is one of those areas needing some coverage, haven't found any test explicitly covering it. Also, I've searched at github, to see if anybody may be using expressions like: $outcome = $phpcsFile->fixer->endChangeset()... if ($phpcsFile->fixer->endChangeset()... And have found zero lines of code using the return value of the method. Hence, I think it's a safe change to apply.
@stronk7 Thanks for this PR and the due diligence of the codesearch. I'm a bit hesitant to accept this change, largely for the reasons you also mention above (no tests, potential for breaking code in external standards), but also because there actually is a code-path which returns For the record, I've also done a codesearch via Sourcegraph and can confirm that, in practice, this change is very unlikely to break anything. Digging into the code history, it looks like the All in all, I'm inclined to accept the change, but for the 4.0 branch with a "breaking change" label and preferably after tests have been added. I made a start adding tests for this class recently, when I wanted to make a change to one of the methods in this class myself and I'd encourage you to add tests covering the code being changed as well. |
I don't understand the value of returning any value from this method. I can understand that the return value could be used to indicate if a particular set of changes were applied or not, but I don't see what a sniff could usefully do with that information. If a sniff is trying to detect conflicts, then by the time If a sniff is modifying the same content / set of tokens multiple times within itself, then that's a design flaw which can be fixed within the sniff. (Set the correct set of tokens / content just once.) The fact that a particular change-set was rejected isn't something that the sniff can usefully do anything about. I advocate for making this method return |
Ok, I just proposed this because I faced the problem when debugging a complex "recursive" Sniff (in charge of sorting some lines alphabetically). And it drove me crazy not understanding why the fixer was not fixing anything and, still, returning true. Finally, I workaround it by "accumulating" all the recursive changes in a structure and then, applying them all-together, escaping from the "conflict-and-rollback" behaviour of the fixer (and the 50 iterations limit). Yes, I saw that the In any case, I'm happy closing this as won't fix or, if you think it's worth it, look for tests in 4.0 and try to complete the PR. 100% you preference. Ciao :-) Edited: Sorry @fredden, did not see your comment! About your proposal of changing it to return |
Sure-it-is! |
Description
I was debugging a complex sniff that implies multiple potential modifications to the same token (that is, right now, not possible - we could discuss about that another day), when have detected that the
Fixer::endChangeset()
method is returning always true, no matter the changes have been not accepted.So this just ensures that the method returns the real outcome.
I've been looking to current tests to try to add something to have it covered, but it seems that the
Fixer
is one of those areas needing some coverage, haven't found any test explicitly covering it.Also, I've searched at github, to see if anybody may be using expressions like:
$outcome = $phpcsFile->fixer->endChangeset()...
if ($phpcsFile->fixer->endChangeset()...
And have found zero lines of code using the return value of the method. Hence, I think it's a safe change to apply.
Suggested changelog entry
Ensure that Fixer::endChangeset() returns the real outcome
Related issues/external references
Fixes N/A
Types of changes
PR checklist