Skip to content

Commit 5e988dd

Browse files
authored
Add new Sniff to check declare statements (#179)
2 parents de5974a + 83a94e6 commit 5e988dd

File tree

7 files changed

+1107
-8
lines changed

7 files changed

+1107
-8
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<documentation title="Declare Statements">
2+
<standard>
3+
<![CDATA[
4+
Declare statements should be formatted in the following way:
5+
- the declare keyword should be lower case
6+
- no space between the keyword and opening parenthesis
7+
- one space after the opening parenthesis
8+
- one space before the equals sign
9+
- one space after the equals sign
10+
- one space before the closing parenthesis
11+
- no space between the closing parenthesis and terminating semi-colon
12+
- one space between the closing parenthesis and opening curly brace in a block declaration
13+
- the opening curly brace should be the last content on the line
14+
- the closing curly brace in a block declaration should be on a new line
15+
- the closing curly brace should be column-aligned with the declare keyword
16+
- the only supported directives are "ticks", "strict_types", or "encoding"
17+
]]>
18+
</standard>
19+
<code_comparison>
20+
<code title="Valid: Correct spacing.">
21+
<![CDATA[
22+
declare<em></em>(<em> </em>strict_types<em> </em>=<em> </em>1<em> </em>)<em></em>;
23+
declare(<em> </em>strict_types = 1<em> </em>);
24+
25+
26+
]]>
27+
</code>
28+
<code title="Invalid: Incorrect spacing.">
29+
<![CDATA[
30+
declare<em> </em>(<em></em>strict_types<em> </em>=<em></em>1<em></em>)<em> </em>;
31+
declare(<em>
32+
</em>strict_types = 1<em>
33+
</em>);
34+
]]>
35+
</code>
36+
</code_comparison>
37+
<code_comparison>
38+
<code title="Valid: Correct directive.">
39+
<![CDATA[
40+
declare( <em>strict_types</em> = 1 );
41+
]]>
42+
</code>
43+
<code title="Invalid: Invalid directive.">
44+
<![CDATA[
45+
declare( <em>struct_types</em> = 1 );
46+
]]>
47+
</code>
48+
</code_comparison>
49+
<code_comparison>
50+
<code title="Valid: Correct braces spacing and alignment in block declaration.">
51+
<![CDATA[
52+
declare( ticks = 1 )<em> </em>{
53+
// code here.
54+
<em></em>}
55+
]]>
56+
</code>
57+
<code title="Invalid: Incorrect braces spacing and alignment in block declaration.">
58+
<![CDATA[
59+
declare( ticks = 1 )<em> </em>{
60+
// code here.
61+
<em> </em>}
62+
]]>
63+
</code>
64+
</code_comparison>
65+
</documentation>

0 commit comments

Comments
 (0)