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

Text doc generator does not allow for multi-line rule explanations #2541

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jun 27, 2019

While new lines were (accidentally) being respected by the existing code, the line length count was not being reset when a new line character was encountered, causing weird line wrapping.

This has been fixed now by:

  • First splitting the received text into individual lines.
  • Then doing the line wrapping calculations for each line individually.

Includes:

  • Reducing the code complexity by removing an else and using an early continue instead.
  • Removing some duplicate function calls.

To test this:

  • Make sure you are on the master branch and:
    • Create a Standard/Docs/Category/SomeSniffStandard.xml file with the following content:

      XML Documentation code sample
        ```xml
        <documentation title="Yoda Conditions">
            <standard>
            <![CDATA[
              When doing logical comparisons involving variables, the variable must be placed on the right side. All constants, literals, and function calls must be placed on the left side. If neither side is a variable, the order is unimportant.
      
        For more information:
        https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions
            ]]>
            </standard>
            <code_comparison>
                <code title="Valid: The variable $the_force is placed on the right">
                <![CDATA[
        if ( true === $the_force ) {
            $victorious = you_will( $be );
        }
                ]]>
                </code>
                <code title="Invalid: The variable $the_force has been placed on the left">
                <![CDATA[
        if ( $the_force === false ) {
            $victorious = you_will_not( $be );
        }
                ]]>
                </code>
            </code_comparison>
        </documentation>
        ```
      
    • Run: phpcs --generator=Text --sniffs=Standard.Category.SomeSniff

    • Take note of the incorrect line wrapping for the For more information line.
      PHPCS Text wrong line wrapping

  • Now, check out this branch and follow the same steps.
    • Take note of the now correct line wrapping for the For more information line.
      PHPCS Text correct line wrapping

While new lines were (accidentally) being respected by the existing code, the line length count was not being reset when a new line character was encountered, causing weird line wrapping.

This has been fixed now by:
* First splitting the received text into individual lines.
* Then doing the line wrapping calculations for each line individually.

Includes:
* Reducing the code complexity by removing an `else` and using an early `continue` instead.
* Removing some duplicate function calls.
@jrfnl jrfnl force-pushed the feature/generator-text-line-wrapping-bug-fix branch from 0a24da0 to b109358 Compare July 10, 2019 07:57
@gsherwood gsherwood added this to Backlog in PHPCS v3 Development via automation Sep 17, 2019
@gsherwood gsherwood added this to the 3.5.0 milestone Sep 17, 2019
@gsherwood gsherwood changed the title Generator/Text: allow for multi-line rule explanations Text doc generator does not allow for multi-line rule explanations Sep 19, 2019
gsherwood added a commit that referenced this pull request Sep 19, 2019
@gsherwood gsherwood merged commit b109358 into squizlabs:master Sep 19, 2019
PHPCS v3 Development automation moved this from Backlog to Ready for Release Sep 19, 2019
@gsherwood
Copy link
Member

Thanks

@jrfnl jrfnl deleted the feature/generator-text-line-wrapping-bug-fix branch September 19, 2019 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants