Skip to content

Commit e38cee8

Browse files
Mike-Hermansjrfnl
authored andcommitted
Docs/WordPress.Arrays.ArrayIndentation (#1744)
Adds documentations for the WordPress.Arrays.ArrayIndentation sniff Related to #1722
1 parent 313ddea commit e38cee8

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<documentation title="Array Indentation">
2+
<standard>
3+
<![CDATA[
4+
The array closing bracket indentation should line up with the start of the content on the line containing the array opener.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: Closing bracket lined up correctly">
9+
<![CDATA[
10+
$args = array(
11+
'post_id' => 22,
12+
<em>);</em>
13+
]]>
14+
</code>
15+
<code title="Invalid: Closing bracket lined up incorrectly">
16+
<![CDATA[
17+
$args = array(
18+
'post_id' => 22,
19+
<em>);</em>
20+
]]>
21+
</code>
22+
</code_comparison>
23+
<standard>
24+
<![CDATA[
25+
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.
26+
]]>
27+
</standard>
28+
<code_comparison>
29+
<code title="Valid: Correctly indented array">
30+
<![CDATA[
31+
$args = array(
32+
'post_id' => 22,
33+
'comment_count' => array(
34+
<em>'value' => 25,
35+
'compare' => '>=',</em>
36+
),
37+
'post_type' => array(
38+
'post',
39+
'page',
40+
),
41+
);
42+
]]>
43+
</code>
44+
<code title="Invalid: Indented incorrectly; harder to read.">
45+
<![CDATA[
46+
$args = array(
47+
'post_id' => 22,
48+
'comment_count' => array(
49+
<em>'value' => 25,
50+
'compare' => '>=',</em>
51+
),
52+
'post_type' => array(
53+
<em>'post',
54+
'page',</em>
55+
),
56+
);
57+
]]>
58+
</code>
59+
</code_comparison>
60+
<standard>
61+
<![CDATA[
62+
Subsequent lines in multiline array items should be indented at least as much as the first line of the array item.
63+
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.
64+
]]>
65+
</standard>
66+
<code_comparison>
67+
<code title="Valid: Subsequent lines are indented correctly.">
68+
<![CDATA[
69+
$args = array(
70+
'phrase' => 'start of phrase'
71+
. 'concatented additional phrase'
72+
. 'more text',
73+
);
74+
]]>
75+
</code>
76+
<code title="Invalid: Subsequent items are indented before the first line item.">
77+
<![CDATA[
78+
$args = array(
79+
'phrase' => 'start of phrase'
80+
. 'concatented additional phrase'
81+
. 'more text',
82+
);
83+
]]>
84+
</code>
85+
</code_comparison>
86+
<code_comparison>
87+
<code title="Valid: Opener and comma after closer are indented correctly">
88+
<![CDATA[
89+
$text = array(
90+
<<<EOD
91+
start of phrase
92+
concatented additional phrase
93+
more text
94+
EOD
95+
,
96+
);
97+
]]>
98+
</code>
99+
<code title="Invalid: Opener is aligned incorrectly to match the closer. The comma does not align correctly with the array indentation.">
100+
<![CDATA[
101+
$text = array(
102+
<em><<<EOD</em>
103+
start of phrase
104+
concatented additional phrase
105+
more text
106+
EOD
107+
<em>,</em>
108+
);
109+
]]>
110+
</code>
111+
</code_comparison>
112+
</documentation>

0 commit comments

Comments
 (0)