Make WordPress Core


Ignore:
Timestamp:
11/28/2017 04:23:11 AM (7 years ago)
Author:
pento
Message:

General: Add inline PHPCS options to leave regex indentation.

We have a handful of super long regexen that are written over multiple lines, as a collection of strings concatenated together. Each string is indented appropriately for the regex, but PHPCS doesn't recognised this, so defaults to removing the extra whitespace.

Disabling the Squiz.Strings.ConcatenationSpacing.PaddingFound rule for these blocks stops the extra whitespace from being removed.

See #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r42228 r42249  
    618618
    619619    if ( ! isset( $regex ) ) {
     620        // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    620621        $comments =
    621             '!'           // Start of comment, after the <.
     622            '!'             // Start of comment, after the <.
    622623            . '(?:'         // Unroll the loop: Consume everything until --> is found.
    623624            .     '-(?!->)' // Dash not followed by end of comment.
     
    627628
    628629        $cdata =
    629             '!\[CDATA\['  // Start of comment, after the <.
     630            '!\[CDATA\['    // Start of comment, after the <.
    630631            . '[^\]]*+'     // Consume non-].
    631632            . '(?:'         // Unroll the loop: Consume everything until ]]> is found.
     
    636637
    637638        $escaped =
    638             '(?='           // Is the element escaped?
     639            '(?='             // Is the element escaped?
    639640            .    '!--'
    640641            . '|'
     
    648649
    649650        $regex =
    650             '/('              // Capture the entire match.
     651            '/('                // Capture the entire match.
    651652            .     '<'           // Find start of element.
    652653            .     '(?'          // Conditional expression follows.
     
    656657            .     ')'
    657658            . ')/';
     659        // phpcs:enable
    658660    }
    659661
     
    678680
    679681    if ( ! isset( $html_regex ) ) {
     682        // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    680683        $comment_regex =
    681             '!'           // Start of comment, after the <.
     684            '!'             // Start of comment, after the <.
    682685            . '(?:'         // Unroll the loop: Consume everything until --> is found.
    683686            .     '-(?!->)' // Dash not followed by end of comment.
     
    687690
    688691        $html_regex =            // Needs replaced with wp_html_split() per Shortcode API Roadmap.
    689             '<'                // Find start of element.
     692            '<'                  // Find start of element.
    690693            . '(?(?=!--)'        // Is this a comment?
    691694            .     $comment_regex // Find end of comment.
     
    693696            .     '[^>]*>?'      // Find end of element. If not found, match all input.
    694697            . ')';
     698        // phpcs:enable
    695699    }
    696700
     
    718722    $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
    719723    $tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex().
     724    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    720725    $regex =
    721726        '\['              // Find start of shortcode.
     
    729734        . '\]'              // Find end of shortcode.
    730735        . '\]?';            // Shortcodes may end with ]]
     736    // phpcs:enable
    731737
    732738    return $regex;
     
    818824    $spaces = wp_spaces_regexp();
    819825
     826    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    820827    $pattern =
    821828        '/'
     
    849856        . '<\\/p>'                           // closing paragraph
    850857        . '/';
     858    // phpcs:enable
    851859
    852860    return preg_replace( $pattern, '$1', $pee );
Note: See TracChangeset for help on using the changeset viewer.