Make WordPress Core

Changeset 42249


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.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r42228 r42249  
    22492249
    22502250                    // Extract type, name and columns from the definition.
     2251                    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    22512252                    preg_match(
    22522253                        '/^'
     
    22722273                        $index_matches
    22732274                    );
     2275                    // phpcs:enable
    22742276
    22752277                    // Uppercase the index type and normalize space characters.
  • 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 );
  • trunk/src/wp-includes/kses.php

    r42228 r42249  
    10941094    }
    10951095
     1096    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    10961097    $regex =
    10971098    '(?:'
     
    11141115    . ')'
    11151116    . '\s*';              // Trailing space is optional except as mentioned above.
     1117    // phpcs:enable
    11161118
    11171119    // Although it is possible to reduce this procedure to a single regexp,
  • trunk/src/wp-includes/shortcodes.php

    r42228 r42249  
    236236    // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
    237237    // Also, see shortcode_unautop() and shortcode.js.
     238
     239    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    238240    return
    239         '\\['                              // Opening bracket
     241        '\\['                                // Opening bracket
    240242        . '(\\[?)'                           // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
    241243        . "($tagregexp)"                     // 2: Shortcode name
     
    265267        . ')'
    266268        . '(\\]?)';                          // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
     269    // phpcs:enable
    267270}
    268271
Note: See TracChangeset for help on using the changeset viewer.