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
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.
Most helpful comment
Hi @EnvySky ,
Currently the rule
whitespace_after_comma_in_arrayonly 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.