Skip to content

Commit

Permalink
Docs/ArrayKeySpacingRestrictions and Array.MultipleStatementAlignment (
Browse files Browse the repository at this point in the history
…#1737)

Adds documentations for the `WordPress.Arrays.ArrayKeySpacingRestrictions` sniff and the `WordPress.Arrays.MultipleStatementAlignment` sniff.

Related to #1722
  • Loading branch information
Mike-Hermans authored and jrfnl committed Oct 13, 2019
1 parent e38cee8 commit 058be1b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
27 changes: 27 additions & 0 deletions WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<documentation title="Array Key Spacing Restrictions">
<standard>
<![CDATA[
When referring to array items, only include a space around the index if it is a variable or the key is concatenated.
]]>
</standard>
<code_comparison>
<code title="Valid: Correct spacing around the index keys">
<![CDATA[
$post = $posts<em>[ </em>$post_id<em> ]</em>;
$post_title = $post<em>[ </em>'concatenated' . $title<em> ]</em>;
$post = $posts<em>[ </em>HOME_PAGE<em> ]</em>;
$post = $posts<em>[</em>123<em>]</em>;
$post_title = $post<em>[</em>'post_title'<em>]</em>;
]]>
</code>
<code title="Invalid: Incorrect spacing around the index keys">
<![CDATA[
$post = $posts<em>[</em>$post_id<em>]</em>;
$post_title = $post<em>[</em>'concatenated' . $title<em> ]</em>;
$post = $posts<em>[</em>HOME_PAGE<em>]</em>;
$post = $posts<em>[ </em>123<em> ]</em>;
$post_title = $post<em>[ </em>'post_title'<em> ]</em>;
]]>
</code>
</code_comparison>
</documentation>
46 changes: 46 additions & 0 deletions WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<documentation title="Multiple Statement Alignment">
<standard>
<![CDATA[
When declaring arrays, there should be one space on either side of a double arrow operator used to assign a value to a key.
]]>
</standard>
<code_comparison>
<code title="Valid: correct spacing between the key and value.">
<![CDATA[
$foo = array( 'cat'<em> => </em>22 );
$bar = array( 'year'<em> => </em>$current_year );
]]>
</code>
<code title="Invalid: No or incorrect spacing between the key and value.">
<![CDATA[
$foo = array( 'cat'<em>=></em>22 );
$bar = array( 'year'<em>=> </em>$current_year );
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
In the case of a block of related assignments, it is recommended to align the arrows to promote readability.
]]>
</standard>
<code_comparison>
<code title="Valid: Double arrow operators aligned">
<![CDATA[
$args = array(
'cat'<em> => </em>22,
'year'<em> => </em>$current_year,
'monthnum'<em> => </em>$current_month,
);
]]>
</code>
<code title="Invalid: Not aligned; harder to read">
<![CDATA[
$args = array(
'cat' <em>=></em> 22,
'year' <em>=></em> $current_year,
'monthnum' <em>=></em> $current_month,
);
]]>
</code>
</code_comparison>
</documentation>

0 comments on commit 058be1b

Please sign in to comment.