From cb4c02aa7913dbf8044a1f93b709348800d52340 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Mon, 21 Feb 2022 12:03:07 +0100 Subject: [PATCH] NoTrailingCommaInSinglelineFunctionCallFixer - Introduction --- doc/list.rst | 11 + doc/ruleSets/Symfony.rst | 1 + .../function_declaration.rst | 9 + ...ling_comma_in_singleline_function_call.rst | 31 +++ doc/rules/index.rst | 3 + .../FunctionDeclarationFixer.php | 38 ++- ...lingCommaInSinglelineFunctionCallFixer.php | 112 +++++++++ .../NoSpacesInsideParenthesisFixer.php | 2 +- src/RuleSet/Sets/SymfonySet.php | 1 + tests/AutoReview/FixerFactoryTest.php | 3 + .../FunctionDeclarationFixerTest.php | 55 +++- ...CommaInSinglelineFunctionCallFixerTest.php | 238 ++++++++++++++++++ tests/Fixtures/Integration/misc/PHP7_3.test | 42 ++-- tests/Fixtures/Integration/misc/PHP8_0.test | 6 +- ...ion_declaration,method_argument_space.test | 2 +- ...ion_call,no_spaces_inside_parenthesis.test | 11 + 16 files changed, 530 insertions(+), 35 deletions(-) create mode 100644 doc/rules/function_notation/no_trailing_comma_in_singleline_function_call.rst create mode 100644 src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php create mode 100644 tests/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixerTest.php create mode 100644 tests/Fixtures/Integration/priority/no_trailing_comma_in_singleline_function_call,no_spaces_inside_parenthesis.test diff --git a/doc/list.rst b/doc/list.rst index 3080f747f6d..1a2b7b72d02 100644 --- a/doc/list.rst +++ b/doc/list.rst @@ -741,6 +741,10 @@ List of Available Rules | Spacing to use before open parenthesis for closures. | Allowed values: ``'none'``, ``'one'`` | Default value: ``'one'`` + - | ``trailing_comma_single_line`` + | Whether trailing commas are allowed in single line signatures. + | Allowed types: ``bool`` + | Default value: ``false`` Part of rule sets `@PSR12 <./ruleSets/PSR12.rst>`_ `@PSR2 <./ruleSets/PSR2.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_ @@ -1538,6 +1542,13 @@ List of Available Rules Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_ `Source PhpCsFixer\\Fixer\\ArrayNotation\\NoTrailingCommaInSinglelineArrayFixer <./../src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php>`_ +- `no_trailing_comma_in_singleline_function_call <./rules/function_notation/no_trailing_comma_in_singleline_function_call.rst>`_ + + When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument. + + Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_ + + `Source PhpCsFixer\\Fixer\\FunctionNotation\\NoTrailingCommaInSinglelineFunctionCallFixer <./../src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php>`_ - `no_trailing_whitespace <./rules/whitespace/no_trailing_whitespace.rst>`_ Remove trailing whitespace at the end of non-blank lines. diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index e762b31ad94..f2cb0f32d22 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -70,6 +70,7 @@ Rules ``['allow_mixed' => true, 'allow_unused_params' => true]`` - `no_trailing_comma_in_list_call <./../rules/control_structure/no_trailing_comma_in_list_call.rst>`_ - `no_trailing_comma_in_singleline_array <./../rules/array_notation/no_trailing_comma_in_singleline_array.rst>`_ +- `no_trailing_comma_in_singleline_function_call <./../rules/function_notation/no_trailing_comma_in_singleline_function_call.rst>`_ - `no_unneeded_control_parentheses <./../rules/control_structure/no_unneeded_control_parentheses.rst>`_ config: ``['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']]`` diff --git a/doc/rules/function_notation/function_declaration.rst b/doc/rules/function_notation/function_declaration.rst index 98d1a7e37b4..fe004073352 100644 --- a/doc/rules/function_notation/function_declaration.rst +++ b/doc/rules/function_notation/function_declaration.rst @@ -16,6 +16,15 @@ Allowed values: ``'none'``, ``'one'`` Default value: ``'one'`` +``trailing_comma_single_line`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Whether trailing commas are allowed in single line signatures. + +Allowed types: ``bool`` + +Default value: ``false`` + Examples -------- diff --git a/doc/rules/function_notation/no_trailing_comma_in_singleline_function_call.rst b/doc/rules/function_notation/no_trailing_comma_in_singleline_function_call.rst new file mode 100644 index 00000000000..1cb83f4b872 --- /dev/null +++ b/doc/rules/function_notation/no_trailing_comma_in_singleline_function_call.rst @@ -0,0 +1,31 @@ +====================================================== +Rule ``no_trailing_comma_in_singleline_function_call`` +====================================================== + +When making a method or function call on a single line there MUST NOT be a +trailing comma after the last argument. + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +.. code-block:: diff + + --- Original + +++ New + `_ rule set will enable the ``no_trailing_comma_in_singleline_function_call`` rule. + +@Symfony + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_trailing_comma_in_singleline_function_call`` rule. diff --git a/doc/rules/index.rst b/doc/rules/index.rst index f885377bd71..21dd1060f9f 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -340,6 +340,9 @@ Function Notation - `no_spaces_after_function_name <./function_notation/no_spaces_after_function_name.rst>`_ When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis. +- `no_trailing_comma_in_singleline_function_call <./function_notation/no_trailing_comma_in_singleline_function_call.rst>`_ + + When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument. - `no_unreachable_default_argument_value <./function_notation/no_unreachable_default_argument_value.rst>`_ *(risky)* In function arguments there must not be arguments with default values before non-default ones. diff --git a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php index d8243cba4a9..9005f5d9bd2 100644 --- a/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php +++ b/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php @@ -47,10 +47,7 @@ final class FunctionDeclarationFixer extends AbstractFixer implements Configurab private const SUPPORTED_SPACINGS = [self::SPACING_NONE, self::SPACING_ONE]; - /** - * @var string - */ - private $singleLineWhitespaceOptions = " \t"; + private string $singleLineWhitespaceOptions = " \t"; /** * {@inheritdoc} @@ -134,6 +131,17 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); + + if (false === $this->configuration['trailing_comma_single_line'] + && !$tokens->isPartialCodeMultiline($index, $endParenthesisIndex) + ) { + $commaIndex = $tokens->getPrevMeaningfulToken($endParenthesisIndex); + + if ($tokens[$commaIndex]->equals(',')) { + $tokens->clearTokenAndMergeSurroundingWhitespace($commaIndex); + } + } + $startBraceIndex = $tokens->getNextTokenOfKind($endParenthesisIndex, [';', '{', [T_DOUBLE_ARROW]]); // fix single-line whitespace before { or => @@ -160,6 +168,16 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $useStartParenthesisIndex = $tokens->getNextTokenOfKind($afterParenthesisIndex, ['(']); $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $useStartParenthesisIndex); + if (false === $this->configuration['trailing_comma_single_line'] + && !$tokens->isPartialCodeMultiline($index, $useEndParenthesisIndex) + ) { + $commaIndex = $tokens->getPrevMeaningfulToken($useEndParenthesisIndex); + + if ($tokens[$commaIndex]->equals(',')) { + $tokens->clearTokenAndMergeSurroundingWhitespace($commaIndex); + } + } + // remove single-line edge whitespaces inside use parentheses $this->fixParenthesisInnerEdge($tokens, $useStartParenthesisIndex, $useEndParenthesisIndex); @@ -211,14 +229,22 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setDefault(self::SPACING_ONE) ->setAllowedValues(self::SUPPORTED_SPACINGS) ->getOption(), + (new FixerOptionBuilder('trailing_comma_single_line', 'Whether trailing commas are allowed in single line signatures.')) + ->setAllowedTypes(['bool']) + ->setDefault(false) + ->getOption(), ]); } private function fixParenthesisInnerEdge(Tokens $tokens, int $start, int $end): void { + do { + --$end; + } while ($tokens->isEmptyAt($end)); + // remove single-line whitespace before `)` - if ($tokens[$end - 1]->isWhitespace($this->singleLineWhitespaceOptions)) { - $tokens->clearAt($end - 1); + if ($tokens[$end]->isWhitespace($this->singleLineWhitespaceOptions)) { + $tokens->clearAt($end); } // remove single-line whitespace after `(` diff --git a/src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php b/src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php new file mode 100644 index 00000000000..7d3f6d453fc --- /dev/null +++ b/src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php @@ -0,0 +1,112 @@ + + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\FunctionNotation; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Analyzer\AttributeAnalyzer; +use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\Tokenizer\Tokens; + +final class NoTrailingCommaInSinglelineFunctionCallFixer extends AbstractFixer +{ + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument.', + [new CodeSample("isAnyTokenKindsFound([T_STRING, T_VARIABLE, T_CLASS, T_UNSET, T_ISSET, T_LIST]); + } + + /** + * {@inheritdoc} + */ + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + for ($index = \count($tokens) - 1; $index > 0; --$index) { + if (!$tokens[$index]->equals(')')) { + continue; + } + + $trailingCommaIndex = $tokens->getPrevMeaningfulToken($index); + + if (!$tokens[$trailingCommaIndex]->equals(',')) { + continue; + } + + $callIndex = $tokens->getPrevMeaningfulToken( // get before "parenthesis open index" + $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) + ); + + if ($tokens[$callIndex]->isGivenKind([T_VARIABLE, T_CLASS, T_UNSET, T_ISSET, T_LIST])) { + $this->clearCommaIfNeeded($tokens, $callIndex, $index, $trailingCommaIndex); + + continue; + } + + if ($tokens[$callIndex]->isGivenKind(T_STRING)) { + if (!AttributeAnalyzer::isAttribute($tokens, $callIndex)) { + $this->clearCommaIfNeeded($tokens, $callIndex, $index, $trailingCommaIndex); + } + + continue; + } + + if ($tokens[$callIndex]->equalsAny([')', ']', [CT::T_DYNAMIC_VAR_BRACE_CLOSE], [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE]])) { + $block = Tokens::detectBlockType($tokens[$callIndex]); + if ( + Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $block['type'] + || Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE === $block['type'] + || Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE === $block['type'] + || Tokens::BLOCK_TYPE_PARENTHESIS_BRACE === $block['type'] + ) { + $this->clearCommaIfNeeded($tokens, $callIndex, $index, $trailingCommaIndex); + + // continue; implicit + } + } + } + } + + private function clearCommaIfNeeded(Tokens $tokens, int $startIndex, int $endIndex, int $commaIndex): void + { + if (!$tokens->isPartialCodeMultiline($startIndex, $endIndex)) { + $tokens->clearTokenAndMergeSurroundingWhitespace($commaIndex); + } + } +} diff --git a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php index 0fb421a67b2..fe6b56a348a 100644 --- a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php +++ b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php @@ -51,7 +51,7 @@ function foo( \$bar, \$baz ) * {@inheritdoc} * * Must run before FunctionToConstantFixer, GetClassToClassKeywordFixer, StringLengthToEmptyFixer. - * Must run after CombineConsecutiveIssetsFixer, CombineNestedDirnameFixer, LambdaNotUsedImportFixer, ModernizeStrposFixer, NoUselessSprintfFixer, PowToExponentiationFixer. + * Must run after CombineConsecutiveIssetsFixer, CombineNestedDirnameFixer, LambdaNotUsedImportFixer, ModernizeStrposFixer, NoTrailingCommaInSinglelineFunctionCallFixer, NoUselessSprintfFixer, PowToExponentiationFixer. */ public function getPriority(): int { diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index 2d357c37bcf..ed031b95077 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -104,6 +104,7 @@ public function getRules(): array ], 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline_function_call' => true, 'no_unneeded_control_parentheses' => [ 'statements' => [ 'break', diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 0fa28369148..47dfcb94ea2 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -561,6 +561,9 @@ private static function getFixersPriorityGraph(): array 'no_empty_phpdoc', 'void_return', ], + 'no_trailing_comma_in_singleline_function_call' => [ + 'no_spaces_inside_parenthesis', + ], 'no_unneeded_control_parentheses' => [ 'no_trailing_whitespace', ], diff --git a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php index 952d8c62f55..68f8615cd0b 100644 --- a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php @@ -434,13 +434,39 @@ public function testFixPhp80(string $expected, ?string $input = null, array $con public function provideFixPhp80Cases(): \Generator { yield [ - ' null;', + ' null;', ' null;', self::$configurationClosureSpacingNone, ]; + + yield [ + ' true], + ]; } } diff --git a/tests/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixerTest.php b/tests/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixerTest.php new file mode 100644 index 00000000000..ed19b5653b7 --- /dev/null +++ b/tests/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixerTest.php @@ -0,0 +1,238 @@ + + * Dariusz Rumiński + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\FunctionNotation; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @internal + * + * @covers \PhpCsFixer\Fixer\FunctionNotation\NoTrailingCommaInSinglelineFunctionCallFixer + */ +final class NoTrailingCommaInSinglelineFunctionCallFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixCases(): iterable + { + yield 'simple var' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + 'abc($a);', + 'abc($a,);', + ]; + + yield 'nested call' => [ + 'abc($a,foo(1));', + 'abc($a,foo(1,));', + ]; + + yield 'wrapped' => [ + 'getOutput(1);', + 'getOutput(1,);', + ]; + + yield 'dynamic function and method calls' => [ + '$a(1); $c("");', + '$a(1,); $c("",);', + ]; + + yield 'static function call' => [ + 'bar); +$b = isset($foo->bar); +list($a,$b) = $a; +', + 'bar,); +$b = isset($foo->bar,); +list($a,$b,) = $a; +', + ]; + + yield 'unset' => [ + ' [ + ' [ + ' static function(int $a): void{ echo $a;}, + "d" => [ + [2 => static function(int $a): void{ echo $a;}] + ] +]; + +$a["e"](1); +$a["d"][0][2](1); + +$z = new class { public static function b(int $a): void {echo $a; }}; +$z::b(1); + +${$e}(1); +$$e(2); +$f(0)(1); +$g["e"](1); // foo', + ' static function(int $a): void{ echo $a;}, + "d" => [ + [2 => static function(int $a): void{ echo $a;}] + ] +]; + +$a["e"](1,); +$a["d"][0][2](1,); + +$z = new class { public static function b(int $a): void {echo $a; }}; +$z::b(1,); + +${$e}(1,); +$$e(2,); +$f(0,)(1,); +$g["e"](1,); // foo', + ]; + + yield 'do not fix' => [ + 'doTest($expected, $input); + } + + public static function provideFix80Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'method(1); strlen(...);', + 'method(1,); strlen(...);', + ]; + } +} diff --git a/tests/Fixtures/Integration/misc/PHP7_3.test b/tests/Fixtures/Integration/misc/PHP7_3.test index 385d6ba169d..4c61e619c5c 100644 --- a/tests/Fixtures/Integration/misc/PHP7_3.test +++ b/tests/Fixtures/Integration/misc/PHP7_3.test @@ -48,41 +48,41 @@ foo( ); __DIR__; // `dir_constant` rule dirname($path, 3); // `combine_nested_dirname` rule -$foo->__invoke(1, ); // `magic_method_casing` rule -implode('', $pieces, ); // `implode_call` rule -implode('', $pieces, ); // `implode_call` rule +$foo->__invoke(1); // `magic_method_casing` rule +implode('', $pieces); // `implode_call` rule +implode('', $pieces); // `implode_call` rule null === $var; // `is_null` rule -mb_strpos($a, $b, ); // `mb_str_functions` rule -sample('foo', 'foobarbaz', 'baz', ); // `method_argument_space` rule -$user->setEmail('voff.web@gmail.com', ) // `method_chaining_indentation` rule - ->setPassword('233434', ); +mb_strpos($a, $b); // `mb_str_functions` rule +sample('foo', 'foobarbaz', 'baz'); // `method_argument_space` rule +$user->setEmail('voff.web@gmail.com') // `method_chaining_indentation` rule + ->setPassword('233434'); $a = (int) $b; // `modernize_types_casting` rule $this->method1() // `multiline_whitespace_before_semicolons` rule - ->method2(3, ); -mb_strlen($str, ); // `native_function_casing` rule -$c = \get_class($d, ); // `native_function_invocation` rule -$a = rtrim($b, ); // `no_alias_functions` rule -$foo->bar($arg1, $arg2, ); // `no_spaces_inside_parenthesis` rule + ->method2(3); +mb_strlen($str); // `native_function_casing` rule +$c = \get_class($d); // `native_function_invocation` rule +$a = rtrim($b); // `no_alias_functions` rule +$foo->bar($arg1, $arg2); // `no_spaces_inside_parenthesis` rule final class MyTest extends \PHPUnit_Framework_TestCase { public function testFoo(): void { - $this->assertTrue($a, ); // `php_unit_construct` rule - $this->assertNan($a, ); // `php_unit_dedicate_assert` rule + $this->assertTrue($a); // `php_unit_construct` rule + $this->assertNan($a); // `php_unit_dedicate_assert` rule $this->expectException('RuntimeException'); $this->expectExceptionMessage('Msg'); $this->expectExceptionCode(123); // `php_unit_expectation` rule - $this->createMock('Foo', ); // `php_unit_mock` rule - $this->assertSame(1, 2, ); // `php_unit_test_case_static_method_calls` rule - $this->assertSame(1, $a, '', ); // `php_unit_strict` rule + $this->createMock('Foo'); // `php_unit_mock` rule + $this->assertSame(1, 2); // `php_unit_test_case_static_method_calls` rule + $this->assertSame(1, $a, ''); // `php_unit_strict` rule } } $a ** 1; // `pow_to_exponentiation` rule -random_int($a, $b, ); // `random_api_migration` rule +random_int($a, $b); // `random_api_migration` rule $foo = (int) $foo; // `set_type_to_cast` rule -in_array($b, $c, true, ); // `strict_param` rule -@trigger_error('Warning.', \E_USER_DEPRECATED, ); // `error_suppression` rule -foo(null === $a, ); // `yoda_style` rule +in_array($b, $c, true); // `strict_param` rule +@trigger_error('Warning.', \E_USER_DEPRECATED); // `error_suppression` rule +foo(null === $a); // `yoda_style` rule $a = null; // `no_unset_cast` rule $foo->bar = null; // `no_unset_on_property` rule diff --git a/tests/Fixtures/Integration/misc/PHP8_0.test b/tests/Fixtures/Integration/misc/PHP8_0.test index 2da5a153f9b..85a84fe31a8 100644 --- a/tests/Fixtures/Integration/misc/PHP8_0.test +++ b/tests/Fixtures/Integration/misc/PHP8_0.test @@ -89,15 +89,15 @@ class T // nothing we can do // https://wiki.php.net/rfc/trailing_comma_in_parameter_list -function foo(string $param = null, ): void +function foo(string $param = null): void { } -call_user_func('foo', 1, ); +call_user_func('foo', 1); // https://wiki.php.net/rfc/trailing_comma_in_closure_use_list $foo1a = function (): void {}; $foo1b = function (): void {}; -$foo2 = function () use ($bar, $baz, ): void { echo $bar.$baz; }; +$foo2 = function () use ($bar, $baz): void { echo $bar.$baz; }; // https://wiki.php.net/rfc/mixed_type_v2 class T_Mixed diff --git a/tests/Fixtures/Integration/priority/function_declaration,method_argument_space.test b/tests/Fixtures/Integration/priority/function_declaration,method_argument_space.test index 11701c70524..0445b814148 100644 --- a/tests/Fixtures/Integration/priority/function_declaration,method_argument_space.test +++ b/tests/Fixtures/Integration/priority/function_declaration,method_argument_space.test @@ -1,7 +1,7 @@ --TEST-- Integration of fixers: function_declaration,method_argument_space. --RULESET-- -{"function_declaration": true, "method_argument_space": true} +{"function_declaration": {"trailing_comma_single_line": true}, "method_argument_space": true} --REQUIREMENTS-- {"php": 80000} --EXPECT-- diff --git a/tests/Fixtures/Integration/priority/no_trailing_comma_in_singleline_function_call,no_spaces_inside_parenthesis.test b/tests/Fixtures/Integration/priority/no_trailing_comma_in_singleline_function_call,no_spaces_inside_parenthesis.test new file mode 100644 index 00000000000..464eb02b57b --- /dev/null +++ b/tests/Fixtures/Integration/priority/no_trailing_comma_in_singleline_function_call,no_spaces_inside_parenthesis.test @@ -0,0 +1,11 @@ +--TEST-- +Integration of fixers: no_trailing_comma_in_singleline_function_call,no_spaces_inside_parenthesis. +--RULESET-- +{"no_trailing_comma_in_singleline_function_call": true, "no_spaces_inside_parenthesis": true} +--EXPECT-- +