From e3217bc5ed33db675095fbf180321d71980fac88 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 30 Jan 2026 15:28:46 -0300 Subject: [PATCH 1/2] Arrays/ArrayDeclarationSpacing: replace "associative" with "explicit keys" Updates one error message and docblocks to use "arrays with explicit keys" instead of "associative arrays" to align with the PHP handbook terminology. The sniff has always checked for arrays with explicit keys (whether string or numeric), not just associative arrays with string keys. This change aligns the wording with the actual behavior. The public property `allow_single_item_single_line_associative_arrays` and the error code `AssociativeArrayFound` are intentionally left unchanged to avoid breaking changes for users who reference them in their ruleset configurations. Ref: wpcs-docs 156, wpcs-docs 157 --- .../Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index bd0f75acf1..71dc124feb 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -19,21 +19,21 @@ /** * Enforces WordPress array spacing format. * - * - Checks that associative arrays are multi-line. + * - Checks that arrays with explicit keys are multi-line. * - Checks that each array item in a multi-line array starts on a new line. * * @link https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#indentation * * @since 0.11.0 - The WordPress specific additional checks have now been split off * from the `WordPress.Arrays.ArrayDeclaration` sniff into this sniff. - * - Added sniffing & fixing for associative arrays. + * - Added sniffing & fixing for arrays with explicit keys. * @since 0.12.0 Decoupled this sniff from the upstream sniff completely. * This sniff now extends the WordPressCS native `Sniff` class instead. * @since 0.13.0 Added the last remaining checks from the `WordPress.Arrays.ArrayDeclaration` * sniff which were not covered elsewhere. * The `WordPress.Arrays.ArrayDeclaration` sniff has now been deprecated. * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 0.14.0 Single item associative arrays are now by default exempt from the + * @since 0.14.0 Single item arrays with explicit keys are now by default exempt from the * "must be multi-line" rule. This behavior can be changed using the * `allow_single_item_single_line_associative_arrays` property. * @since 3.0.0 Removed various whitespace related checks and fixers in favor of the PHPCSExtra @@ -42,7 +42,7 @@ final class ArrayDeclarationSpacingSniff extends Sniff { /** - * Whether or not to allow single item associative arrays to be single line. + * Whether or not to allow single item arrays with explicit keys to be single line. * * @since 0.14.0 * @@ -102,7 +102,7 @@ public function process_token( $stackPtr ) { } /** - * Check that associative arrays are always multi-line. + * Check that arrays with explicit keys are always multi-line. * * @since 0.13.0 The actual checks contained in this method used to * be in the `process()` method. @@ -137,9 +137,9 @@ protected function process_single_line_array( $stackPtr, $opener, $closer ) { if ( false === $array_has_keys ) { return; } - $error = 'When an array uses associative keys, each value should start on %s.'; + $error = 'When an array has explicit keys, each value should start on %s.'; if ( true === $this->allow_single_item_single_line_associative_arrays ) { - $error = 'When a multi-item array uses associative keys, each value should start on %s.'; + $error = 'When a multi-item array has explicit keys, each value should start on %s.'; } /* From c482551e50c0e1e303821c0f58d35c3754f8b7cd Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Tue, 3 Feb 2026 08:48:21 -0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 71dc124feb..ae44ca523b 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -137,9 +137,9 @@ protected function process_single_line_array( $stackPtr, $opener, $closer ) { if ( false === $array_has_keys ) { return; } - $error = 'When an array has explicit keys, each value should start on %s.'; + $error = 'When an array is declared with explicit keys, each value should start on %s.'; if ( true === $this->allow_single_item_single_line_associative_arrays ) { - $error = 'When a multi-item array has explicit keys, each value should start on %s.'; + $error = 'When a multi-item array is declared with explicit keys, each value should start on %s.'; } /*