Match Expressions alignments
Should Match Expressions have alignment like those under the Generic.Formatting.MultipleStatementAlignment.NotSameWarning and WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAlign rules?
For example, this is not aligned:
$asset_dir = match ( $asset_type ) {
'style' => 'build/base/css',
'script' => 'build/base/js',
'editor_ui_style' => 'build/blocks/css',
'editor_ui_script' => 'build/blocks/js',
default => 'build/base'
};
The desired alignment:
$asset_dir = match ( $asset_type ) {
'style' => 'build/base/css',
'script' => 'build/base/js',
'editor_ui_style' => 'build/blocks/css',
'editor_ui_script' => 'build/blocks/js',
default => 'build/base'
};
@jacobcassidy Good question. AFAICS, the PER standard does not have rules about this. Might be an idea to open an issue in the PER repo ?
Independently of the outcome of such a discussion, I'd be open to accepting two different, but related sniffs for match arrow alignment:
- To align the arrows.
- To disallow alignment and enforce one space either side of the arrows.
Having both sniffs available would allow either style to be enforced, depending on the preference of the coding standard including the sniffs.
P.S.: Please use the appropriate issue template when opening an issue (and do not remove the template).
@jrfnl Sounds good. I'll open an issue with the PER repo, and when I have extra time, I'll review this repo to see how to create the sniffs you mentioned.
P.S.: Please use the appropriate issue template when opening an issue (and do not remove the template).
Noted.
Any updates on this? I'd like to enforce such alignment in array assignments, just like OPs example.
@utdrmac Double arrow alignment in array assignments is a completely different topic. Have a look at the Squiz.Arrays.ArrayDeclaration sniff for that.
@jrfnl That sniff is called out as "completely broken" https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions/1084 @jacobcassidy did you ever find anything that worked?
@utdrmac As I said before, questions regarding array arrow alignment do not belong in this ticket, which is about match arrow alignment.