Is there any way to set rule for removing trailing comma using PHP-CS-Fixer?

717 Views Asked by At

I'm using PHP-CS-Fixer to set up linting in project. There is a rule trailing_comma_in_multiline. It lets you to check whether all multiple-lines arrays have trailing commas.

Is it possible to reverse this logic and check whether all multiple-lines arrays have NO trailing commas?

In other words I want this syntax to be valid:

$data = [
    'First item',
    'Second item'
];

And this syntax to throw an error when checking with PHP-CS-Fixer:

$data = [
    'First item',
    'Second item',
];
1

There are 1 best solutions below

1
On

I believe that should work:

'trailing_comma_in_multiline' => ['elements' => []]

https://cs.symfony.com/doc/rules/control_structure/trailing_comma_in_multiline.html