Automattic / phpcs-neutron-standard

A set of phpcs sniffs for PHP >7 development
MIT License
94 stars 7 forks source link

Disallow multiple spaces in assignments (disallow alignment) #46

Closed sirbrillig closed 6 years ago

sirbrillig commented 6 years ago

I assumed there was already a sniff to do this, but I can't find one. I'd like to make a sniff which replaces this:

$foo         = 'bar';
$barfoo      = 'foo';

with this:

$foo = 'bar';
$barfoo = 'foo';

And the same thing with associative arrays, replacing this:

[
  'foo'     => 'bar',
  'barfoo'  => 'foo',
]

with this:

[
  'foo' => 'bar',
  'barfoo'  => 'foo',
]

Why?

Assignment alignment looks nice sometimes, but it vastly complicates writing and modifying code. If there are twenty adjacent assignments, and one of them gets longer than the others, it requires the developer to go back and adjust the spacing of all the other lines. It's also not always consistent since different typeface and displays will have different visual widths of spaces and other characters.

stuwest commented 6 years ago

+1. I've tried out Generic.Formatting.MultipleStatementAlignment.NotSameWarning and WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned even in a few files and just don't like them, largely because of your observation:

it requires the developer to go back and adjust the spacing of all the other lines

which will lead to messy diffs full of distraction.