Skip to content
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

Reports: Fix word wrapping edge cases #654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MatmaRex
Copy link
Contributor

Description

The word wrapping in Code and Full reports did not correctly account for the ANSI color codes (producing differently wrapped text depending on the value of $showSources) and for the PHP_EOL constant values (producing differently wrapped text on Linux and Windows).

Rewrite the code so that word wrapping is done first, and padding and colors are added afterwards.

Also harmonize the implementation between the two reports.

Suggested changelog entry

(probably not needed)

Related issues/external references

(none)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
    (Not applicable? I didn't find any tests for the reports classes, I assume this is not meant to be covered)
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
    (Not applicable)

The word wrapping in Code and Full reports did not correctly account
for the ANSI color codes (producing differently wrapped text depending
on the value of $showSources) and for the PHP_EOL constant values
(producing differently wrapped text on Linux and Windows).

Rewrite the code so that word wrapping is done first, and padding and
colors are added afterwards.

Also harmonize the implementation between the two reports.
@jrfnl
Copy link
Member

jrfnl commented Oct 31, 2024

@MatmaRex Thank you for your interest in contributing to PHP_CodeSniffer.

To understand what this PR is trying to solve, could you please add some screenshots of "before" and "after" highlighting what the problem is supposed to be ?

Some previous issues/PRs related to these reports and wrapping: squizlabs/PHP_CodeSniffer#196, squizlabs/PHP_CodeSniffer#2093, #124, #125, #154

@jrfnl
Copy link
Member

jrfnl commented Oct 31, 2024

I have added tests to cover my changes.
(Not applicable? I didn't find any tests for the reports classes, I assume this is not meant to be covered)

Regarding tests: this part of the codebase absolutely needs tests, but those haven't been created yet. It's part of the reason why I linked to those previous PRs, as - as things are now without tests - it is a little too easy to bring back previously fixed bugs when creating a new fix.

@MatmaRex
Copy link
Contributor Author

MatmaRex commented Nov 1, 2024

I can try adding tests, but I'm reluctant to make large additions as my first patch. I'm also not sure if this part of the codebase is unit-testable, I might end up with an ugly fragile integration test you might not want to maintain.

But I will at least make up a small test case reproducible manually. I'll look into this after the weekend.

(I originally encountered the problem while running integration tests for a CodeSniffer ruleset we maintain. For example, this sample output is poorly wrapped due to the presence of color codes: https://gerrit.wikimedia.org/g/mediawiki/tools/codesniffer/+/9423de5e375150f09dba44093cbdab939afd3489/MediaWiki/Tests/files/code_sample.php.expect#99)

@jrfnl
Copy link
Member

jrfnl commented Nov 1, 2024

For example, this sample output is poorly wrapped due to the presence of color codes:

I still don't see what problem you are trying to solve.

Even if I were to manually test the patch, I still need to be able to reproduce the problem and verify the fix. As things are, there is just not enough information for this.

MatmaRex added a commit to MatmaRex/phpcs-pull-654-demo that referenced this pull request Nov 9, 2024
@MatmaRex
Copy link
Contributor Author

MatmaRex commented Nov 9, 2024

I'm working on an example at https://github.com/MatmaRex/phpcs-pull-654-demo, but it's difficult to provide a concise demo, because PHPCS output differs in other ways on Windows and Linux. Perhaps you may accept a patch for that as well? #662

@MatmaRex
Copy link
Contributor Author

(I will come back to this after #662 and/or #664)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants