Php-cs-fixer: whitespace_after_comma_in_array - how can format them to just only one white space?

Created on 22 Oct 2018  路  2Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

I know whitespace_after_comma_in_array means In array declaration, there MUST be a whitespace after each comma.

But if I have many whitespaces after comma, how can format them to just only one white space?

I am using VSCode win32-x64-1.28.2 with PhpCsFixer plugin config like this

return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2'           => true,
        '@PHP71Migration' => true,

        'array_indentation'          => true,
        'array_syntax'               => ['syntax' => 'short'],
        'combine_consecutive_unsets' => true,
        'method_separation'          => true,
        'single_quote'               => true,

        'no_multiline_whitespace_before_semicolons' => true,

        'binary_operator_spaces' => [
            'default' => 'align_single_space_minimal'
        ],
        'braces' => [
            'allow_single_line_closure'                   => true,
            'position_after_anonymous_constructs'         => 'same',
            'position_after_functions_and_oop_constructs' => 'same'
        ],
        'cast_spaces' => [
            'space' => 'none'
        ],
        'concat_space'            => ['spacing' => 'one'],
        'declare_equal_normalize' => true,
        'function_typehint_space' => true,
        'hash_to_slash_comment'   => true,
        'include'                 => true,
        'lowercase_cast'          => true,
        'no_extra_consecutive_blank_lines' => [
            'curly_brace_block',
            'extra',
            'parenthesis_brace_block',
            'square_brace_block',
            'throw',
            'use',
        ],
        'no_multiline_whitespace_around_double_arrow' => true,

        'no_spaces_around_offset'             => true,
        'no_whitespace_before_comma_in_array' => true,
        'whitespace_after_comma_in_array'     => true,
        'trim_array_spaces'                   => true,
        'no_whitespace_in_blank_line'         => true,
        'object_operator_without_whitespace'  => true,

        'single_blank_line_before_namespace' => true,

        'ternary_operator_spaces' => true,

        'unary_operator_spaces' => true,
    ])
    ->setLineEnding("\n");

My code:
Input:

$test = [
    'text' => 'Data: ' . json_encode(['a' => $a,                        'b' => $b,                        'c' => $c], JSON_UNESCAPED_UNICODE)
];

Wanted output:

$test = [
    'text' => 'Data: ' . json_encode(['a' => $a, 'b' => $b, 'c' => $c], JSON_UNESCAPED_UNICODE)
];

Thanks so much

kinfeature request

Most helpful comment

Hi @EnvySky ,

Currently the rule whitespace_after_comma_in_array only makes sure that there is spacing after the comma, but not what the spacing looks like.
At first glance it makes sense to adjust the rule so it will (optional); make sure the spacing it is only a single space (if not followed by a comment), or the spacing starts with a line break.
However I didn't check for possible conflicting rules yet.

All 2 comments

Hi @EnvySky ,

Currently the rule whitespace_after_comma_in_array only makes sure that there is spacing after the comma, but not what the spacing looks like.
At first glance it makes sense to adjust the rule so it will (optional); make sure the spacing it is only a single space (if not followed by a comment), or the spacing starts with a line break.
However I didn't check for possible conflicting rules yet.

Thank you for your confirmation.

I can config to format like that with PHPStorm but not with VSCode. Hope this feature request can be complete soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UksusoFF picture UksusoFF  路  3Comments

carusogabriel picture carusogabriel  路  3Comments

ndench picture ndench  路  3Comments

datenmeister picture datenmeister  路  3Comments

grachevko picture grachevko  路  3Comments