Skip to content

Commit 7349295

Browse files
committed
Generic/DisallowTabIndent: improve handling of yield from
This commit on the one hand confirms (via a test) that indentation for a multi-line `yield from` expression is now handled correctly by the sniff. On the other hand, this commit enables checking for tabs being used for inline "alignment" between the `yield` and the `from` keyword. This will now also be handled (and auto-fixed) by this sniff. Includes test.
1 parent 8da7f11 commit 7349295

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed

src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function process(File $phpcsFile, $stackPtr)
7878
T_COMMENT => true,
7979
T_END_HEREDOC => true,
8080
T_END_NOWDOC => true,
81+
T_YIELD_FROM => true,
8182
];
8283

8384
for ($i = 0; $i < $phpcsFile->numTokens; $i++) {

src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,12 @@ $var = "$hello $there";
9191
9292
Another line.
9393
*/
94+
95+
// A `yield from` can be single-line and multiline and may contain a tab in the whitespace between the keywords.
96+
function myGenerator() {
97+
yield from gen1();
98+
99+
yield
100+
from
101+
gen2();
102+
}

src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,12 @@ $var = "$hello $there";
9191

9292
Another line.
9393
*/
94+
95+
// A `yield from` can be single-line and multiline and may contain a tab in the whitespace between the keywords.
96+
function myGenerator() {
97+
yield from gen1();
98+
99+
yield
100+
from
101+
gen2();
102+
}

src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,43 +50,45 @@ public function getErrorList($testFile='')
5050
switch ($testFile) {
5151
case 'DisallowTabIndentUnitTest.1.inc':
5252
return [
53-
5 => 2,
54-
9 => 1,
55-
15 => 1,
56-
20 => 2,
57-
21 => 1,
58-
22 => 2,
59-
23 => 1,
60-
24 => 2,
61-
31 => 1,
62-
32 => 2,
63-
33 => 2,
64-
41 => 1,
65-
42 => 1,
66-
43 => 1,
67-
44 => 1,
68-
45 => 1,
69-
46 => 1,
70-
47 => 1,
71-
48 => 1,
72-
54 => 1,
73-
55 => 1,
74-
56 => 1,
75-
57 => 1,
76-
58 => 1,
77-
59 => 1,
78-
79 => 1,
79-
80 => 1,
80-
81 => 1,
81-
82 => 1,
82-
83 => 1,
83-
85 => 1,
84-
86 => 1,
85-
87 => 1,
86-
89 => 1,
87-
90 => 1,
88-
92 => 1,
89-
93 => 1,
53+
5 => 2,
54+
9 => 1,
55+
15 => 1,
56+
20 => 2,
57+
21 => 1,
58+
22 => 2,
59+
23 => 1,
60+
24 => 2,
61+
31 => 1,
62+
32 => 2,
63+
33 => 2,
64+
41 => 1,
65+
42 => 1,
66+
43 => 1,
67+
44 => 1,
68+
45 => 1,
69+
46 => 1,
70+
47 => 1,
71+
48 => 1,
72+
54 => 1,
73+
55 => 1,
74+
56 => 1,
75+
57 => 1,
76+
58 => 1,
77+
59 => 1,
78+
79 => 1,
79+
80 => 1,
80+
81 => 1,
81+
82 => 1,
82+
83 => 1,
83+
85 => 1,
84+
86 => 1,
85+
87 => 1,
86+
89 => 1,
87+
90 => 1,
88+
92 => 1,
89+
93 => 1,
90+
97 => 1,
91+
100 => 1,
9092
];
9193

9294
case 'DisallowTabIndentUnitTest.2.inc':

0 commit comments

Comments
 (0)