PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
880 stars 54 forks source link

Match Expressions alignments #590

Open jacobcassidy opened 1 month ago

jacobcassidy commented 1 month ago

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'
};
jrfnl commented 1 month ago

@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:

  1. To align the arrows.
  2. 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).

jacobcassidy commented 1 month ago

@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.