-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the documentation for WordPress.Arrays.CommaAfterArrayItem (#1734)
* Add the documentation for WordPress.Arrays.CommaAfterArrayItem Co-authored-by: jrfnl <[email protected]>
- Loading branch information
1 parent
8df9712
commit 11c354d
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
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,94 @@ | ||
<documentation title="Comma After Array Item"> | ||
<standard> | ||
<![CDATA[ | ||
There should be no space between an array item and the comma following it. | ||
There should be either exactly one space, or a new line, after the comma. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: No space before a comma."> | ||
<![CDATA[ | ||
$array = array( | ||
'type' => 'value'<em>,</em> | ||
'values' => array( 1 )<em>,</em> | ||
'extra' => 'c'<em>,</em> /* Comment. */ | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: One or more spaces before a comma."> | ||
<![CDATA[ | ||
$array = array( | ||
'type' => 'value'<em> ,</em> | ||
'values' => array( 1 ), | ||
'extra' => 'c'<em> ,</em> /* Comment. */ | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
|
||
<code_comparison> | ||
<code title="Valid: Exactly one space after a comma in a single line array."> | ||
<![CDATA[ | ||
$array = array( 'a'<em>, </em>'b'<em>, </em>'c' ); | ||
]]> | ||
</code> | ||
<code title="Invalid: Multiple or no spaces after a comma in a single line array."> | ||
<![CDATA[ | ||
$array = array( 'a'<em>,</em>'b'<em>, </em>'c' ); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
|
||
<standard> | ||
<![CDATA[ | ||
Single line arrays should not have a trailing comma after the last array item. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Single line array without a trailing comma."> | ||
<![CDATA[ | ||
$array = array( 'a', 'b', <em>'c' </em>); | ||
]]> | ||
</code> | ||
<code title="Invalid: Single line array with a trailing comma."> | ||
<![CDATA[ | ||
$array = array( 'a', 'b', <em>'c', </em>); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
|
||
<standard> | ||
<![CDATA[ | ||
Multi-line arrays must have a trailing comma after the last array item. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Comma after each item in a multi-line array."> | ||
<![CDATA[ | ||
$array = array( | ||
'a', | ||
<em>'c',</em> | ||
); | ||
$assoc = array( | ||
'type' => 'value', | ||
'key' => <em>'c'</em>, | ||
); | ||
]]> | ||
</code> | ||
|
||
<code title="Invalid: Missing trailing comma after last item in a multi-line array."> | ||
<![CDATA[ | ||
$array = array( | ||
'a', | ||
<em>'c'</em> | ||
); | ||
$assoc = array( | ||
'type' => 'value', | ||
'key' => <em>'c'</em> | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
</documentation> |