Skip to content

Commit

Permalink
Generic/DisallowTabIndent: improve handling of yield from
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Nov 2, 2024
1 parent 8da7f11 commit 7349295
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function process(File $phpcsFile, $stackPtr)
T_COMMENT => true,
T_END_HEREDOC => true,
T_END_NOWDOC => true,
T_YIELD_FROM => true,
];

for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ $var = "$hello $there";
Another line.
*/

// A `yield from` can be single-line and multiline and may contain a tab in the whitespace between the keywords.
function myGenerator() {
yield from gen1();

yield
from
gen2();
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ $var = "$hello $there";

Another line.
*/

// A `yield from` can be single-line and multiline and may contain a tab in the whitespace between the keywords.
function myGenerator() {
yield from gen1();

yield
from
gen2();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,45 @@ public function getErrorList($testFile='')
switch ($testFile) {
case 'DisallowTabIndentUnitTest.1.inc':
return [
5 => 2,
9 => 1,
15 => 1,
20 => 2,
21 => 1,
22 => 2,
23 => 1,
24 => 2,
31 => 1,
32 => 2,
33 => 2,
41 => 1,
42 => 1,
43 => 1,
44 => 1,
45 => 1,
46 => 1,
47 => 1,
48 => 1,
54 => 1,
55 => 1,
56 => 1,
57 => 1,
58 => 1,
59 => 1,
79 => 1,
80 => 1,
81 => 1,
82 => 1,
83 => 1,
85 => 1,
86 => 1,
87 => 1,
89 => 1,
90 => 1,
92 => 1,
93 => 1,
5 => 2,
9 => 1,
15 => 1,
20 => 2,
21 => 1,
22 => 2,
23 => 1,
24 => 2,
31 => 1,
32 => 2,
33 => 2,
41 => 1,
42 => 1,
43 => 1,
44 => 1,
45 => 1,
46 => 1,
47 => 1,
48 => 1,
54 => 1,
55 => 1,
56 => 1,
57 => 1,
58 => 1,
59 => 1,
79 => 1,
80 => 1,
81 => 1,
82 => 1,
83 => 1,
85 => 1,
86 => 1,
87 => 1,
89 => 1,
90 => 1,
92 => 1,
93 => 1,
97 => 1,
100 => 1,
];

case 'DisallowTabIndentUnitTest.2.inc':
Expand Down

0 comments on commit 7349295

Please sign in to comment.