Browse Source

bug #6117 SingleSpaceAfterConstruct - handle before destructuring close brace (liquid207)

This PR was merged into the master branch.

Discussion
----------

SingleSpaceAfterConstruct - handle before destructuring close brace

Fixer 'single_space_after_construct' should not insert whitespace after those comments that before destructuring square brace close tag

closes #6110

Commits
-------

d3d6fed1e Fixer 'single_space_after_construct' should not insert whitespace after those comments that before destructuring square brace close tag
SpacePossum 3 years ago
parent
commit
fb51b49d13

+ 1 - 1
src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php

@@ -219,7 +219,7 @@ yield  from  baz();
 
             $whitespaceTokenIndex = $index + 1;
 
-            if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE]])) {
+            if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE], [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE]])) {
                 continue;
             }
 

+ 7 - 0
tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php

@@ -2923,6 +2923,13 @@ new Dummy(/** b */);
 foo(/* c */);
 foo($a /* d */, $b);
 $arr = [/* empty */];
+',
+        ];
+
+        yield 'before_destructuring_square_brace_close' => [
+            '<?php
+foreach ($fields as [$field/** @var string*/]) {
+}
 ',
         ];
     }