-
-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs/ArrayKeySpacingRestrictions and Array.MultipleStatementAlignment (…
…#1737) Adds documentations for the `WordPress.Arrays.ArrayKeySpacingRestrictions` sniff and the `WordPress.Arrays.MultipleStatementAlignment` sniff. Related to #1722
- Loading branch information
1 parent
e38cee8
commit 058be1b
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |