Coding Standards: Use pre-increment/decrement for stand-alone statements.

Note: This is enforced by WPCS 3.0.0:

1. There should be no space between an increment/decrement operator and the variable it applies to.
2. Pre-increment/decrement should be favoured over post-increment/decrement for stand-alone statements. “Pre” will in/decrement and then return, “post” will return and then in/decrement. Using the “pre” version is slightly more performant and can prevent future bugs when code gets moved around.

References:
* [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#increment-decrement-operators WordPress PHP Coding Standards: Increment/decrement operators]
* [https://github.com/WordPress/WordPress-Coding-Standards/pull/2130 WPCS: PR #2130 Core: add sniffs to check formatting of increment/decrement operators]

Props jrf.
See #59161, #58831.
Built from https://develop.svn.wordpress.org/trunk@56549


git-svn-id: http://core.svn.wordpress.org/trunk@56061 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2023-09-09 09:28:26 +00:00
parent d8936a9fe7
commit b80ce60f70
65 changed files with 146 additions and 146 deletions

View File

@@ -129,7 +129,7 @@ if ( ! class_exists( 'MO', false ) ) :
// Headers' msgid is an empty string.
fwrite( $fh, pack( 'VV', 0, $current_addr ) );
$current_addr++;
++$current_addr;
$originals_table = "\0";
$reader = new POMO_Reader();

View File

@@ -110,19 +110,19 @@ if ( ! class_exists( 'Plural_Forms', false ) ) :
// Ignore whitespace.
case ' ':
case "\t":
$pos++;
++$pos;
break;
// Variable (n).
case 'n':
$output[] = array( 'var' );
$pos++;
++$pos;
break;
// Parentheses.
case '(':
$stack[] = $next;
$pos++;
++$pos;
break;
case ')':
@@ -144,7 +144,7 @@ if ( ! class_exists( 'Plural_Forms', false ) ) :
throw new Exception( 'Mismatched parentheses' );
}
$pos++;
++$pos;
break;
// Operators.
@@ -189,7 +189,7 @@ if ( ! class_exists( 'Plural_Forms', false ) ) :
$o2 = $stack[ $s_pos ];
if ( '?' !== $o2 ) {
$output[] = array( 'op', array_pop( $stack ) );
$s_pos--;
--$s_pos;
continue;
}
@@ -202,7 +202,7 @@ if ( ! class_exists( 'Plural_Forms', false ) ) :
if ( ! $found ) {
throw new Exception( 'Missing starting "?" ternary operator' );
}
$pos++;
++$pos;
break;
// Default - number or invalid.
@@ -264,7 +264,7 @@ if ( ! class_exists( 'Plural_Forms', false ) ) :
$total = count( $this->tokens );
while ( $i < $total ) {
$next = $this->tokens[ $i ];
$i++;
++$i;
if ( 'var' === $next[0] ) {
$stack[] = $n;
continue;

View File

@@ -342,7 +342,7 @@ if ( ! class_exists( 'PO', false ) ) :
$context = '';
$msgstr_index = 0;
while ( true ) {
$lineno++;
++$lineno;
$line = PO::read_line( $f );
if ( ! $line ) {
if ( feof( $f ) ) {
@@ -365,7 +365,7 @@ if ( ! class_exists( 'PO', false ) ) :
// The comment is the start of a new entry.
if ( self::is_final( $context ) ) {
PO::read_line( $f, 'put-back' );
$lineno--;
--$lineno;
break;
}
// Comments have to be at the beginning.
@@ -377,7 +377,7 @@ if ( ! class_exists( 'PO', false ) ) :
} elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) {
if ( self::is_final( $context ) ) {
PO::read_line( $f, 'put-back' );
$lineno--;
--$lineno;
break;
}
if ( $context && 'comment' !== $context ) {
@@ -388,7 +388,7 @@ if ( ! class_exists( 'PO', false ) ) :
} elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) {
if ( self::is_final( $context ) ) {
PO::read_line( $f, 'put-back' );
$lineno--;
--$lineno;
break;
}
if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) {

View File

@@ -261,7 +261,7 @@ if ( ! class_exists( 'Translations', false ) ) :
switch ( $char ) {
case '?':
$res .= ' ? (';
$depth++;
++$depth;
break;
case ':':
$res .= ') : (';