PedroTroller / PhpCSFixer-Custom-Fixers

A set of new fixers for PHP-CS-Fixer
77 stars 7 forks source link

line_break_between_method_arguments -> inline-attributes not working as expected #201

Closed pkly closed 9 months ago

pkly commented 10 months ago

I noticed an issue with the rule's inline-attribute settings not working as expected. If an attribute is already inlined the fixer will move the attribute to be in a previous line.

Using 3.25.1 Fixer and 2.32.2 custom fixers

PedroTroller commented 10 months ago

Can you give me an example to add it in tests ?

pkly commented 10 months ago
<?php

namespace App;

use Doctrine\Common\Collections\Collection;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class TestClass
{
    public function __construct(
        #[Autowire(service: 'doctrine')] private readonly Collection $collection,
        #[Autowire] private readonly Collection $whatever
    ) {
    }
}

Gets its attributes put into a separate line

Fixer config is as follows:

<?php

$finder = (new PhpCsFixer\Finder())
    ->in(__DIR__)
    ->exclude('var')
    ->exclude('bin')
    ->exclude('public')
    ->exclude('scripts')
    ->exclude('vendor')
;

return (new PhpCsFixer\Config())
    ->setRules([
        '@Symfony' => true,
        'blank_line_before_statement' => [
            'statements' => [
                'declare',
                'return',
                'throw',
                'try',
                'if',
                'for',
                'while',
                'foreach',
            ],
        ],
        'cast_spaces' => ['space' => 'none'],
        'constant_case' => ['case' => 'lower'],
        'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
        'phpdoc_align' => false,
        'single_line_throw' => false,
        'phpdoc_to_comment' => false,
        'phpdoc_types_order' => false,
        'phpdoc_scalar' => false,
        'phpdoc_types' => false,
        'increment_style' => false,
        'ordered_class_elements' => true,
        'nullable_type_declaration_for_default_null_value' => false,
        'nullable_type_declaration' => ['syntax' => 'union'],
        'ordered_types' => ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last'],
        'PedroTroller/line_break_between_method_arguments' => [
            'max-args' => false,
            'max-length' => 1,
            'automatic-argument-merge' => false,
            'inline-attributes' => true,
        ],
    ])
    ->setFinder($finder)
    ->registerCustomFixers(new \PedroTroller\CS\Fixer\Fixers());

CS Fixer version: 3.26.0 Custom fixers version: 2.32.2

PedroTroller commented 9 months ago

If you look at the documentation for this fixer, there's an inline-attributes parameter that you can set to true to do the behaviour you want. https://github.com/PedroTroller/PhpCSFixer-Custom-Fixers?tab=readme-ov-file#pedrotrollerline_break_between_method_arguments

pkly commented 9 months ago

If you look at the config I supplied below the example you'll see I already set the option to true.

PedroTroller commented 9 months ago

I can't reproduce it. I'm using your TestClass.php file, your configuration. I run the whole thing and the attributes remain well inlined. If I completely uninline your file, it returns to its original state. I already have a regression test that validates this too. And when I put your file in a new regression test, the test is green.

PedroTroller commented 9 months ago

I reproduce, it's apparently a conflict with method_argument_space

PedroTroller commented 9 months ago

:tada: This issue has been resolved in version 2.32.3 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: