Browse Source

minor #5669 Remove TrailingCommaInMultilineArrayFixer (kubawerlos, keradus)

This PR was squashed before being merged into the 3.0 branch.

Discussion
----------

Remove TrailingCommaInMultilineArrayFixer

Commits
-------

a04d9c50a Remove TrailingCommaInMultilineArrayFixer
Dariusz Ruminski 3 years ago
parent
commit
2160b5f315

+ 1 - 0
UPGRADE-v3.md

@@ -46,6 +46,7 @@ Old name | New name | Note
 `psr0`                                          | `psr_autoloading`                                                                 | use configuration `['dir' => x ]`
 `psr4`                                          | `psr_autoloading`                                                                 |
 `silenced_deprecation_error`                    | `error_suppression`                                                               |
+`trailing_comma_in_multiline_array`             | `trailing_comma_in_multiline`                                                     | use configuration `['elements' => ['arrays']]`
 
 ### Removed rootless configuration
 

+ 0 - 58
doc/rules/array_notation/trailing_comma_in_multiline_array.rst

@@ -1,58 +0,0 @@
-==========================================
-Rule ``trailing_comma_in_multiline_array``
-==========================================
-
-.. warning:: This rule is deprecated and will be removed on next major version.
-
-   You should use ``trailing_comma_in_multiline`` instead.
-
-PHP multi-line arrays should have a trailing comma.
-
-Configuration
--------------
-
-``after_heredoc``
-~~~~~~~~~~~~~~~~~
-
-Whether a trailing comma should also be placed after heredoc end.
-
-Allowed types: ``bool``
-
-Default value: ``false``
-
-Examples
---------
-
-Example #1
-~~~~~~~~~~
-
-*Default* configuration.
-
-.. code-block:: diff
-
-   --- Original
-   +++ New
-    <?php
-    array(
-        1,
-   -    2
-   +    2,
-    );
-
-Example #2
-~~~~~~~~~~
-
-With configuration: ``['after_heredoc' => true]``.
-
-.. code-block:: diff
-
-   --- Original
-   +++ New
-    <?php
-        $x = [
-            'foo',
-            <<<EOD
-                bar
-   -            EOD
-   +            EOD,
-        ];

+ 0 - 2
doc/rules/index.rst

@@ -39,8 +39,6 @@ Array Notation
     In array declaration, there MUST NOT be a whitespace before each comma.
 - `normalize_index_brace <./array_notation/normalize_index_brace.rst>`_
     Array index should always be written by using square braces.
-- `trailing_comma_in_multiline_array <./array_notation/trailing_comma_in_multiline_array.rst>`_ *(deprecated)*
-    PHP multi-line arrays should have a trailing comma.
 - `trim_array_spaces <./array_notation/trim_array_spaces.rst>`_
     Arrays should be formatted like function/method arguments, without leading or trailing single line space.
 - `whitespace_after_comma_in_array <./array_notation/whitespace_after_comma_in_array.rst>`_

+ 0 - 108
src/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixer.php

@@ -1,108 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace PhpCsFixer\Fixer\ArrayNotation;
-
-use PhpCsFixer\AbstractProxyFixer;
-use PhpCsFixer\Fixer\ConfigurableFixerInterface;
-use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
-use PhpCsFixer\Fixer\DeprecatedFixerInterface;
-use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
-use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
-use PhpCsFixer\FixerDefinition\CodeSample;
-use PhpCsFixer\FixerDefinition\FixerDefinition;
-use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
-use PhpCsFixer\FixerDefinition\VersionSpecification;
-use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
-
-/**
- * @author Sebastiaan Stok <s.stok@rollerscapes.net>
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @deprecated
- */
-final class TrailingCommaInMultilineArrayFixer extends AbstractProxyFixer implements ConfigurableFixerInterface, DeprecatedFixerInterface
-{
-    /**
-     * @var TrailingCommaInMultilineFixer
-     */
-    private $fixer;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getDefinition(): FixerDefinitionInterface
-    {
-        return new FixerDefinition(
-            'PHP multi-line arrays should have a trailing comma.',
-            [
-                new CodeSample("<?php\narray(\n    1,\n    2\n);\n"),
-                new VersionSpecificCodeSample(
-                    <<<'SAMPLE'
-<?php
-    $x = [
-        'foo',
-        <<<EOD
-            bar
-            EOD
-    ];
-
-SAMPLE
-                    ,
-                    new VersionSpecification(70300),
-                    ['after_heredoc' => true]
-                ),
-            ]
-        );
-    }
-
-    public function configure(array $configuration): void
-    {
-        $configuration['elements'] = [TrailingCommaInMultilineFixer::ELEMENTS_ARRAYS];
-        $this->getFixer()->configure($configuration);
-        $this->configuration = $configuration;
-    }
-
-    public function getConfigurationDefinition(): FixerConfigurationResolverInterface
-    {
-        return new FixerConfigurationResolver([
-            $this->getFixer()->getConfigurationDefinition()->getOptions()[0],
-        ]);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getSuccessorsNames(): array
-    {
-        return array_keys($this->proxyFixers);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    protected function createProxyFixers(): array
-    {
-        return [$this->getFixer()];
-    }
-
-    private function getFixer()
-    {
-        if (null === $this->fixer) {
-            $this->fixer = new TrailingCommaInMultilineFixer();
-        }
-
-        return $this->fixer;
-    }
-}

+ 0 - 428
tests/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixerTest.php

@@ -1,428 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
-namespace PhpCsFixer\Tests\Fixer\ArrayNotation;
-
-use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
-
-/**
- * @author Sebastiaan Stok <s.stok@rollerscapes.net>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\ArrayNotation\TrailingCommaInMultilineArrayFixer
- */
-final class TrailingCommaInMultilineArrayFixerTest extends AbstractFixerTestCase
-{
-    /**
-     * @dataProvider provideFixCases
-     */
-    public function testFix(string $expected, ?string $input = null): void
-    {
-        $this->doTest($expected, $input);
-    }
-
-    public function provideFixCases()
-    {
-        return [
-            // long syntax tests
-            ['<?php $x = array();'],
-            ['<?php $x = array("foo");'],
-            ['<?php $x = array("foo", );'],
-            ["<?php \$x = array(\n'foo',\n);", "<?php \$x = array(\n'foo'\n);"],
-            ["<?php \$x = array('foo',\n);"],
-            ["<?php \$x = array('foo',\n);", "<?php \$x = array('foo'\n);"],
-            ["<?php \$x = array('foo', /* boo */\n);", "<?php \$x = array('foo' /* boo */\n);"],
-            ["<?php \$x = array('foo',\n/* boo */\n);", "<?php \$x = array('foo'\n/* boo */\n);"],
-            ["<?php \$x = array(\narray('foo',\n),\n);", "<?php \$x = array(\narray('foo'\n)\n);"],
-            ["<?php \$x = array(\narray('foo'),\n);", "<?php \$x = array(\narray('foo')\n);"],
-            ["<?php \$x = array(\n /* He */ \n);"],
-            [
-                "<?php \$x = array('a', 'b', 'c',\n  'd', 'q', 'z', );",
-                "<?php \$x = array('a', 'b', 'c',\n  'd', 'q', 'z');",
-            ],
-            [
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z', );",
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z');",
-            ],
-            [
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z', );",
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z' );",
-            ],
-            [
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z',\t);",
-                "<?php \$x = array('a', 'b', 'c',\n'd', 'q', 'z'\t);",
-            ],
-            ["<?php \$x = array(\n<<<EOT\noet\nEOT\n);"],
-            ["<?php \$x = array(\n<<<'EOT'\noet\nEOT\n);"],
-            [
-                '<?php
-    $foo = array(
-        array(
-        ),
-    );',
-            ],
-            [
-                '<?php
-    $a = array(
-        1 => array(
-            2 => 3,
-        ),
-    );',
-                '<?php
-    $a = array(
-        1 => array(
-            2 => 3
-        )
-    );',
-            ],
-            [
-                "<?php
-    \$x = array(
-        'foo',
-        'bar',
-        array(
-            'foo',
-            'bar',
-            array(
-                'foo',
-                'bar',
-                array(
-                    'foo',
-                    ('bar' ? true : !false),
-                    ('bar' ? array(true) : !(false)),
-                    array(
-                        'foo',
-                        'bar',
-                        array(
-                            'foo',
-                            ('bar'),
-                        ),
-                    ),
-                ),
-            ),
-        ),
-    );",
-                "<?php
-    \$x = array(
-        'foo',
-        'bar',
-        array(
-            'foo',
-            'bar',
-            array(
-                'foo',
-                'bar',
-                array(
-                    'foo',
-                    ('bar' ? true : !false),
-                    ('bar' ? array(true) : !(false)),
-                    array(
-                        'foo',
-                        'bar',
-                        array(
-                            'foo',
-                            ('bar'),
-                        )
-                    )
-                )
-            )
-        )
-    );",
-            ],
-            [
-                '<?php
-
-                $a = array("foo" => function ($b) {
-                    return "bar".$b;
-                });',
-            ],
-            [
-                '<?php
-    return array(
-        "a" => 1,
-        "b" => 2,
-    );',
-                '<?php
-    return array(
-        "a" => 1,
-        "b" => 2
-    );',
-            ],
-            [
-                '<?php
-    $test = array("foo", <<<TWIG
-        foo
-        bar
-        baz
-TWIG
-        , $twig);',
-            ],
-            [
-                '<?php
-    $test = array("foo", <<<\'TWIG\'
-        foo
-        bar
-        baz
-TWIG
-        , $twig);',
-            ],
-
-            // short syntax tests
-            ['<?php $x = array([]);'],
-            ['<?php $x = [[]];'],
-            ['<?php $x = ["foo",];'],
-            ['<?php $x = bar(["foo",]);'],
-            ["<?php \$x = bar(['foo',\n]);", "<?php \$x = bar(['foo'\n]);"],
-            ["<?php \$x = ['foo', \n];"],
-            ['<?php $x = array([],);'],
-            ['<?php $x = [[],];'],
-            ['<?php $x = [$y,];'],
-            ["<?php \$x = [\n /* He */ \n];"],
-            [
-                '<?php
-    $foo = [
-        [
-        ],
-    ];',
-            ],
-            [
-                '<?php
-
-                $a = ["foo" => function ($b) {
-                    return "bar".$b;
-                }];',
-            ],
-            [
-                '<?php
-    return [
-        "a" => 1,
-        "b" => 2,
-    ];',
-                '<?php
-    return [
-        "a" => 1,
-        "b" => 2
-    ];',
-            ],
-            [
-                '<?php
-    $test = ["foo", <<<TWIG
-        foo
-        bar
-        baz
-TWIG
-        , $twig];',
-            ],
-            [
-                '<?php
-    $test = ["foo", <<<\'TWIG\'
-        foo
-        bar
-        baz
-TWIG
-        , $twig];',
-            ],
-
-            // no array tests
-            [
-                "<?php
-    throw new BadMethodCallException(
-        sprintf(
-            'Method \"%s\" not implemented',
-            __METHOD__
-        )
-    );",
-            ],
-            [
-                "<?php
-    throw new BadMethodCallException(sprintf(
-        'Method \"%s\" not implemented',
-        __METHOD__
-    ));",
-            ],
-            [
-                "<?php
-
-    namespace FOS\\RestBundle\\Controller;
-
-    class ExceptionController extends ContainerAware
-    {
-        public function showAction(Request \$request, \$exception, DebugLoggerInterface \$logger = null, \$format = 'html')
-        {
-            if (!\$exception instanceof DebugFlattenException && !\$exception instanceof HttpFlattenException) {
-                throw new \\InvalidArgumentException(sprintf(
-                    'ExceptionController::showAction can only accept some exceptions (%s, %s), \"%s\" given',
-                    'Symfony\\Component\\HttpKernel\\Exception\\FlattenException',
-                    'Symfony\\Component\\Debug\\Exception\\FlattenException',
-                    get_class(\$exception)
-                ));
-            }
-        }
-    }",
-            ],
-            [
-                '<?php
-    function foo(array $a)
-    {
-        bar(
-            baz(
-                1
-            )
-        );
-    }',
-            ],
-            [
-                '<?php
-    $var = array(
-        "string",
-        //comment
-    );',
-                '<?php
-    $var = array(
-        "string"
-        //comment
-    );',
-            ],
-            [
-                '<?php
-    $var = array(
-        "string",
-        /* foo */);',
-                '<?php
-    $var = array(
-        "string"
-        /* foo */);',
-            ],
-            [
-                '<?php
-    $var = [
-        "string",
-        /* foo */];',
-                '<?php
-    $var = [
-        "string"
-        /* foo */];',
-            ],
-            [
-                '<?php
-function a()
-{
-    yield array(
-        "a" => 1,
-        "b" => 2,
-    );
-}',
-                '<?php
-function a()
-{
-    yield array(
-        "a" => 1,
-        "b" => 2
-    );
-}',
-            ],
-            [
-                '<?php
-function a()
-{
-    yield [
-        "a" => 1,
-        "b" => 2,
-    ];
-}',
-                '<?php
-function a()
-{
-    yield [
-        "a" => 1,
-        "b" => 2
-    ];
-}',
-            ],
-        ];
-    }
-
-    /**
-     * @dataProvider provideFix73Cases
-     * @requires PHP 7.3
-     */
-    public function testFix73(string $expected, ?string $input = null, array $config = []): void
-    {
-        $this->fixer->configure($config);
-        $this->doTest($expected, $input);
-    }
-
-    public function provideFix73Cases()
-    {
-        return [
-            [
-                <<<'EXPECTED'
-<?php
-$a = [
-    <<<'EOD'
-        foo
-        EOD,
-];
-EXPECTED
-                ,
-                <<<'INPUT'
-<?php
-$a = [
-    <<<'EOD'
-        foo
-        EOD
-];
-INPUT
-                ,
-                ['after_heredoc' => true],
-            ],
-        ];
-    }
-
-    /**
-     * @dataProvider provideFixPhp74Cases
-     * @requires PHP 7.4
-     */
-    public function testFixPhp74(string $expected, ?string $input = null): void
-    {
-        $this->doTest($expected, $input);
-    }
-
-    public function provideFixPhp74Cases()
-    {
-        return [
-            [
-                '<?php $x = array(
-                    ...$foo,
-                    ...$bar,
-                );',
-                '<?php $x = array(
-                    ...$foo,
-                    ...$bar
-                );',
-            ],
-            [
-                '<?php $x = [
-                    ...$foo,
-                    ...$bar,
-                ];',
-                '<?php $x = [
-                    ...$foo,
-                    ...$bar
-                ];',
-            ],
-        ];
-    }
-}

+ 1 - 1
tests/Fixtures/Integration/misc/PHP7_4.test

@@ -9,7 +9,7 @@ PHP 7.4 test.
     "no_null_property_initialization": true,
     "no_unset_on_property": true,
     "pow_to_exponentiation": true,
-    "trailing_comma_in_multiline_array": {"after_heredoc": true},
+    "trailing_comma_in_multiline": {"after_heredoc": true},
     "visibility_required": false
 }
 --REQUIREMENTS--