Skip to content

Commit 3aef98b

Browse files
andrewnicolsstronk7
authored andcommitted
Include Generic.Arrays.DisallowLongArraySyntax
- as warning in the moodle standard. - as error in the moodle-extra standard. - to become error in both standards in 1y (#58)
1 parent ef04fab commit 3aef98b

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

moodle-extra/ruleset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<!-- Extend the standard Moodle coding style -->
1010
<rule ref="moodle"/>
1111

12+
<!-- This is an error in moodle-extra. TODO: Remove as part of #58 -->
13+
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
14+
<type>error</type>
15+
</rule>
16+
1217
<!-- Include the PSR-12 ruleset with relevant Moodle exclusions -->
1318
<rule ref="PSR12">
1419

moodle/Tests/MoodleStandardTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,33 @@ public function test_moodle_files_linelength() {
223223
$this->verify_cs_results();
224224
}
225225

226+
/**
227+
* Test the Generic.Arrays.DisallowLongArraySyntax sniff.
228+
*
229+
* @covers \PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\DisallowLongArraySyntaxSniff
230+
*/
231+
public function test_generic_array_disallowlongarraysyntax(): void {
232+
// Define the standard, sniff and fixture to use.
233+
$this->set_standard('moodle');
234+
$this->set_sniff('Generic.Arrays.DisallowLongArraySyntax');
235+
$this->set_fixture(__DIR__ . '/fixtures/generic_array_longarraysyntax.php');
236+
237+
// Define expected results (errors and warnings). Format, array of:
238+
// - line => number of problems, or
239+
// - line => array of contents for message / source problem matching.
240+
// - line => string of contents for message / source problem matching (only 1).
241+
$this->set_errors([
242+
3 => 'Short array syntax must be used to define arrays @Source: Generic.Arrays.DisallowLongArraySyntax.Found',
243+
5 => 'Short array syntax must be used to define arrays @Source: Generic.Arrays.DisallowLongArraySyntax.Found',
244+
9 => 'Short array syntax must be used to define arrays @Source: Generic.Arrays.DisallowLongArraySyntax.Found',
245+
]);
246+
247+
$this->set_warnings(array());
248+
249+
// Let's do all the hard work!
250+
$this->verify_cs_results();
251+
}
252+
226253
/**
227254
* Test the Generic.Files.LineEndings sniff.
228255
*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$a = array();
4+
$b = [];
5+
$c = array(
6+
);
7+
$d = [
8+
];
9+
$e = array (
10+
'alphabet'
11+
);
12+
$f = [
13+
'numbers'
14+
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$a = [];
4+
$b = [];
5+
$c = [
6+
];
7+
$d = [
8+
];
9+
$e = [
10+
'alphabet'
11+
];
12+
$f = [
13+
'numbers'
14+
];

moodle/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<arg name="extensions" value="php" />
1010
<arg name="encoding" value="utf-8" />
1111

12+
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
13+
<type>warning</type>
14+
</rule>
15+
1216
<rule ref="Generic.Classes.DuplicateClassName"/>
1317
<rule ref="Generic.Classes.OpeningBraceSameLine"/>
1418

0 commit comments

Comments
 (0)