-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Report Full: fix two line wrapping bugs #125
Conversation
@anomiex Thanks for this PR. I'm looking at it now. To keep this moving forward, could you please rebase the PR ? I made some changes to the workflows since you created this branch and it would be great to see a passing build using the current workflows. |
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.
@anomiex Thanks for reporting this issue and your work on this patch.
I've now looked at and tested this PR extensively, including with the test code from a previous fix/iteration on this code which was merged in squizlabs/PHP_CodeSniffer#2093.
Findings:
- Your code fixes the issue, but does still contain an "off by one" error somewhere.
This can be seen when running the test code using the exact max length:Using the first command the line for the first message will still be wrapped, while when using the second command, it won't but will have a one space difference with the delimiter line.phpcs -s ./test.php --report-width=110 --standard=PSR12 phpcs -s ./test.php --report-width=111 --standard=PSR12
From #124:
A more complex fix might be to wordwrap() only the message, and then manually calculate the length of the last line to decide whether to append the source directly or to append it as a new line.
As I was looking at this now anyway, I've prepared an update to your fix, which does just that and surprisingly, actually simplifies the code instead of making it more complex.
If you are okay with this, I can push the update in a separate commit to this PR for you to have a look at ?
As a future iteration, I would really like to safeguard these fixes (both this one as well as the ones from squizlabs/PHP_CodeSniffer#2093) with tests, but as testing the reports is greenfields, I consider that "future scope" and not something which needs to be addressed in this PR.
I also discovered another bug while testing this fix. I will pull that as a separate PR, but wouldn't mind a review from you on that PR.
FYI: I've opened PR #154 for this other bug. |
That's how the existing code works, it comes from the PHP_CodeSniffer/src/Reports/Full.php Line 116 in 7fb9515
Try a file like this, for example: <?php
$x = TRUE;
I'll be interested to see your take on it. |
The first is that the ANSI escape codes applied to bold the message when `-s` is used were not being taken into account when wrapping the lines for width, causing some lines to be wrapped unnecessarily. The second is that when lines were wrapped in the middle of a long message, the `|` characters making up the table were being bolded along with the message.
c0300cc
to
0febbfb
Compare
This commit takes the fix one step further by adding the padding only after the message has been word-wrapped. Includes correct handling of padding for multi-line error messages. It then takes the last line of the resulting message and detemines in isolation whether the source code suffix can fit on that line or needs to be placed on a new line.
Good catch! I've updated my change to take that into account now.
Pushing it now. |
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.
Ah, wordwrap()
already handles embedded newlines, so the code doesn't have to handle them itself. Good catch!
It does indeed, though I have to admit I needed to test that out myself as well (which I did when creating the update): https://3v4l.org/7ENWc |
Prevent inconsistency in handling of single-line vs multi-line length calculation. Co-authored-by: Brad Jorsch <anomie@users.sourceforge.net>
Don't hard code the color code length to prevent this breaking on potential future changes. Co-authored-by: Brad Jorsch <anomie@users.sourceforge.net>
245efc5
to
0ba5736
Compare
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.
As far as I'm concerned this is ready for merge. @anomiex All okay from your perspective too ?
I did much the same thing! 😀 https://3v4l.org/knYT4
Looks good to me too! |
* Fix two line wrapping bugs in default report formatter The first is that the ANSI escape codes applied to bold the message when `-s` is used were not being taken into account when wrapping the lines for width, causing some lines to be wrapped unnecessarily. The second is that when lines were wrapped in the middle of a long message, the `|` characters making up the table were being bolded along with the message. * Report Full: iterate on line wrapping bug fix This commit takes the fix one step further by adding the padding only after the message has been word-wrapped. Includes correct handling of padding for multi-line error messages. It then takes the last line of the resulting message and determines in isolation whether the source code suffix can fit on that line or needs to be placed on a new line. Co-authored-by: Brad Jorsch <anomie@users.sourceforge.net> Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
Thanks @anomiex ! |
Description
This is a re-creation of squizlabs/PHP_CodeSniffer#3925:
Suggested changelog entry
-s
is used.-s
is used and messages wrap.Related issues/external references
Fixes #124
Fixes squizlabs/PHP_CodeSniffer#3924
Closes squizlabs/PHP_CodeSniffer#3925
Types of changes
PR checklist