Code style: mixed line/separate line function arguments with alignment
I'm trying to get code style and reformatting to work as I want to.
My current issue is with "Function/constructor call arguments -> Align when multiline"
I like this setting but there are places where I want a mix of multiline and single-line - usually where a parameter is a multi-line closure/anonymous function.
e.g. in WordPress you might pass an anonymous function as a filter, such as:
add_filter( 'pre_get_posts', function ( \WP_Query $query ) {
// Modify the $query
return $query;
}, 10, 1 );
With "Align when multiline" is on, this becomes:
add_filter( 'pre_get_posts', function ( \WP_Query $query ) {
// Modify the $query
return $query;
}, 10, 1 );
(Note the spacing on the final line)
Is there some way to have this mixed multi-line code respected as not-actually-multiline?
Is this a bug in the formatter?
Is there a setting that will align other multi-line arguments, but preserve the correct spacing in my example?
Thanks
请先登录再写评论。
Actually - part 2 of this: I don't seem to be able to turn off "Function/constructor call arguments -> Align when multiline"
If I turn this off I expect this (made up for effect) code to be left alone:
But instead, even with "Align when multiline" turned off, it still reformats to:
Is this expected? Is there something else I need to turn off to have these multi-line function calls left alone?
Surely, I was able to reproduce both cases on 2022.1.3 and 2022.2 EAP. But it seems to be there is no code style option that can help you to achieve the needed formatting, sorry. I will double-check that but as for the rough workaround you may turn off formatter for the problematic regions with the @formatter:off marker:
https://www.jetbrains.com/help/phpstorm/reformat-and-rearrange-code.html#exclude_part_of_code