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.


Built from https://develop.svn.wordpress.org/trunk@42249


git-svn-id: http://core.svn.wordpress.org/trunk@42078 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2017-11-28 04:24:57 +00:00
parent 58a904e893
commit 882db52bdd
5 changed files with 23 additions and 8 deletions

View File

@ -2248,6 +2248,7 @@ function dbDelta( $queries = '', $execute = true ) {
*/
// Extract type, name and columns from the definition.
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
preg_match(
'/^'
. '(?P<index_type>' // 1) Type of the index.
@ -2271,6 +2272,7 @@ function dbDelta( $queries = '', $execute = true ) {
$fld,
$index_matches
);
// phpcs:enable
// Uppercase the index type and normalize space characters.
$index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );

View File

@ -617,8 +617,9 @@ function get_html_split_regex() {
static $regex;
if ( ! isset( $regex ) ) {
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$comments =
'!' // Start of comment, after the <.
'!' // Start of comment, after the <.
. '(?:' // Unroll the loop: Consume everything until --> is found.
. '-(?!->)' // Dash not followed by end of comment.
. '[^\-]*+' // Consume non-dashes.
@ -626,7 +627,7 @@ function get_html_split_regex() {
. '(?:-->)?'; // End of comment. If not found, match all input.
$cdata =
'!\[CDATA\[' // Start of comment, after the <.
'!\[CDATA\[' // Start of comment, after the <.
. '[^\]]*+' // Consume non-].
. '(?:' // Unroll the loop: Consume everything until ]]> is found.
. '](?!]>)' // One ] not followed by end of comment.
@ -635,7 +636,7 @@ function get_html_split_regex() {
. '(?:]]>)?'; // End of comment. If not found, match all input.
$escaped =
'(?=' // Is the element escaped?
'(?=' // Is the element escaped?
. '!--'
. '|'
. '!\[CDATA\['
@ -647,7 +648,7 @@ function get_html_split_regex() {
. ')';
$regex =
'/(' // Capture the entire match.
'/(' // Capture the entire match.
. '<' // Find start of element.
. '(?' // Conditional expression follows.
. $escaped // Find end of escaped element.
@ -655,6 +656,7 @@ function get_html_split_regex() {
. '[^>]*>?' // Find end of normal element.
. ')'
. ')/';
// phpcs:enable
}
return $regex;
@ -677,8 +679,9 @@ function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
static $html_regex;
if ( ! isset( $html_regex ) ) {
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$comment_regex =
'!' // Start of comment, after the <.
'!' // Start of comment, after the <.
. '(?:' // Unroll the loop: Consume everything until --> is found.
. '-(?!->)' // Dash not followed by end of comment.
. '[^\-]*+' // Consume non-dashes.
@ -686,12 +689,13 @@ function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
. '(?:-->)?'; // End of comment. If not found, match all input.
$html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap.
'<' // Find start of element.
'<' // Find start of element.
. '(?(?=!--)' // Is this a comment?
. $comment_regex // Find end of comment.
. '|'
. '[^>]*>?' // Find end of element. If not found, match all input.
. ')';
// phpcs:enable
}
if ( empty( $shortcode_regex ) ) {
@ -717,6 +721,7 @@ function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
function _get_wptexturize_shortcode_regex( $tagnames ) {
$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
$tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex().
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$regex =
'\[' // Find start of shortcode.
. '[\/\[]?' // Shortcodes may begin with [/ or [[
@ -728,6 +733,7 @@ function _get_wptexturize_shortcode_regex( $tagnames ) {
. ')*+' // Possessive critical.
. '\]' // Find end of shortcode.
. '\]?'; // Shortcodes may end with ]]
// phpcs:enable
return $regex;
}
@ -817,6 +823,7 @@ function shortcode_unautop( $pee ) {
$tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
$spaces = wp_spaces_regexp();
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$pattern =
'/'
. '<p>' // Opening paragraph
@ -848,6 +855,7 @@ function shortcode_unautop( $pee ) {
. '(?:' . $spaces . ')*+' // optional trailing whitespace
. '<\\/p>' // closing paragraph
. '/';
// phpcs:enable
return preg_replace( $pattern, '$1', $pee );
}

View File

@ -1093,6 +1093,7 @@ function wp_kses_hair_parse( $attr ) {
return array();
}
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$regex =
'(?:'
. '[-a-zA-Z:]+' // Attribute name.
@ -1113,6 +1114,7 @@ function wp_kses_hair_parse( $attr ) {
. '(?:\s|$)' // If attribute has no value, space is required.
. ')'
. '\s*'; // Trailing space is optional except as mentioned above.
// phpcs:enable
// Although it is possible to reduce this procedure to a single regexp,
// we must run that regexp twice to get exactly the expected result.

View File

@ -235,8 +235,10 @@ function get_shortcode_regex( $tagnames = null ) {
// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
// Also, see shortcode_unautop() and shortcode.js.
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
return
'\\[' // Opening bracket
'\\[' // Opening bracket
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
. "($tagregexp)" // 2: Shortcode name
. '(?![\\w-])' // Not followed by word character or hyphen
@ -264,6 +266,7 @@ function get_shortcode_regex( $tagnames = null ) {
. ')?'
. ')'
. '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
// phpcs:enable
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-42247';
$wp_version = '5.0-alpha-42249';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.