Skip to content

Commit eb31ae9

Browse files
authored
feat(DeclareStrictTypes): Add Slevomat sniff for declare strict_types (#3407995)
1 parent 0f95abc commit eb31ae9

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

coder_sniffer/Drupal/ruleset.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@
123123
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
124124
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
125125
<rule ref="SlevomatCodingStandard.PHP.ShortList" />
126+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
127+
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>
128+
<properties>
129+
<property name="linesCountBeforeDeclare" value="1"/>
130+
<property name="linesCountAfterDeclare" value="1"/>
131+
<property name="spacesCountAroundEqualsSign" value="0"/>
132+
</properties>
133+
</rule>
126134

127135
<rule ref="Squiz.Arrays.ArrayDeclaration" />
128136
<!-- Disable some error messages that we do not want. -->
@@ -298,7 +306,7 @@
298306
<exclude-pattern>*/\.svn/*</exclude-pattern>
299307
<exclude-pattern>*/\.hg/*</exclude-pattern>
300308
<exclude-pattern>*/\.bzr/*</exclude-pattern>
301-
309+
302310
<!-- Ignore minified CSS files.-->
303311
<exclude-pattern>*\.min\.css$</exclude-pattern>
304312
</ruleset>

tests/Drupal/bad/BadUnitTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ protected function getErrorList(string $testFile): array
6969
case 'bad.module':
7070
return [
7171
1 => 1,
72-
12 => 1,
73-
19 => 1,
74-
26 => 1,
75-
33 => 1,
76-
44 => 1,
77-
45 => 1,
72+
7 => 1,
73+
14 => 1,
74+
21 => 1,
75+
28 => 1,
76+
35 => 1,
77+
46 => 1,
78+
47 => 1,
7879
];
7980
case 'bad.php':
8081
return [
@@ -404,7 +405,7 @@ protected function getWarningList(string $testFile): array
404405
{
405406
switch ($testFile) {
406407
case 'bad.module':
407-
return [7 => 1];
408+
return [9 => 1];
408409
case 'bad.php':
409410
return [
410411
14 => 1,

tests/Drupal/bad/bad.module

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Bad examples of install hooks in a module file.
55
*/
66

7+
declare(strict_types = 1);
8+
79
define('UNPREFIXED_CONSTANT', 'invalid');
810

911
/**

tests/Drupal/good/good.module

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
* It is used to check sniffs that run on .module files but skip .php files.
88
*/
99

10+
declare(strict_types=1);
11+
1012
define('GOOD_FOO_BAR', 5);

0 commit comments

Comments
 (0)