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',
];
My Answer:
Unfortunately, PHP-CS-Fixer does not have a built-in rule to enforce the absence of trailing commas in multiple-line arrays. However, you can achieve this by creating a custom rule or using a different linting tool that supports this specific requirement.
Alternatively, you can manually check for trailing commas in your code and remove them before running PHP-CS-Fixer. This way, you can ensure that your code follows the desired coding style.
Rate this post
5 of 5 based on 7101 votesComments