Skip to content

Commit

Permalink
Docs/WordPress.Arrays.ArrayIndentation (#1744)
Browse files Browse the repository at this point in the history
Adds documentations for the WordPress.Arrays.ArrayIndentation sniff

Related to #1722
  • Loading branch information
Mike-Hermans authored and jrfnl committed Oct 13, 2019
1 parent 313ddea commit e38cee8
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions WordPress/Docs/Arrays/ArrayIndentationStandard.xml
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>

0 comments on commit e38cee8

Please sign in to comment.