-
-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs/WordPress.Arrays.ArrayIndentation (#1744)
Adds documentations for the WordPress.Arrays.ArrayIndentation sniff Related to #1722
- Loading branch information
1 parent
313ddea
commit e38cee8
Showing
1 changed file
with
112 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,112 @@ | ||
<documentation title="Array Indentation"> | ||
<standard> | ||
<![CDATA[ | ||
The array closing bracket indentation should line up with the start of the content on the line containing the array opener. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Closing bracket lined up correctly"> | ||
<![CDATA[ | ||
$args = array( | ||
'post_id' => 22, | ||
<em>);</em> | ||
]]> | ||
</code> | ||
<code title="Invalid: Closing bracket lined up incorrectly"> | ||
<![CDATA[ | ||
$args = array( | ||
'post_id' => 22, | ||
<em>);</em> | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
In multi-line arrays, array items should be indented by a 4-space tab for each level of nested array, so that the array visually matches its structure. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Correctly indented array"> | ||
<![CDATA[ | ||
$args = array( | ||
'post_id' => 22, | ||
'comment_count' => array( | ||
<em>'value' => 25, | ||
'compare' => '>=',</em> | ||
), | ||
'post_type' => array( | ||
'post', | ||
'page', | ||
), | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Indented incorrectly; harder to read."> | ||
<![CDATA[ | ||
$args = array( | ||
'post_id' => 22, | ||
'comment_count' => array( | ||
<em>'value' => 25, | ||
'compare' => '>=',</em> | ||
), | ||
'post_type' => array( | ||
<em>'post', | ||
'page',</em> | ||
), | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
Subsequent lines in multiline array items should be indented at least as much as the first line of the array item. | ||
For heredocs/nowdocs, this does not apply to the content of the heredoc/nowdoc or the closer, but it does apply to the comma separating the item from the next. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Subsequent lines are indented correctly."> | ||
<![CDATA[ | ||
$args = array( | ||
'phrase' => 'start of phrase' | ||
. 'concatented additional phrase' | ||
. 'more text', | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Subsequent items are indented before the first line item."> | ||
<![CDATA[ | ||
$args = array( | ||
'phrase' => 'start of phrase' | ||
. 'concatented additional phrase' | ||
. 'more text', | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<code_comparison> | ||
<code title="Valid: Opener and comma after closer are indented correctly"> | ||
<![CDATA[ | ||
$text = array( | ||
<<<EOD | ||
start of phrase | ||
concatented additional phrase | ||
more text | ||
EOD | ||
, | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Opener is aligned incorrectly to match the closer. The comma does not align correctly with the array indentation."> | ||
<![CDATA[ | ||
$text = array( | ||
<em><<<EOD</em> | ||
start of phrase | ||
concatented additional phrase | ||
more text | ||
EOD | ||
<em>,</em> | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
</documentation> |