Description
Bug Description
Generally inserting extra white spaces to align =
and =>
works quite well. There are many good examples of it in the WordPress Coding Standards. However the current settings for maxPadding
and maxColumn
allow for edge cases that may make the code harder to read.
The tl;dr:
- Having a lot of white space in the middle of a line of text makes it harder to read.
- Having a lot of white space in the middle of all lines in a paragraph/block of text makes it much harder to read. This is due to the eyes not being able to follow the lines, and "connect" the left side with the right side of the same line.
Prior art: I think everybody has seen tables of content that list the chapters/sections on the left and page numbers on the right. Many of them have ...........
connecting the chapter title to the page number. These dots allow the eyes to follow the lines easily. Example:
Of course a TOC may look like this:
But note how the space between the titles and the page numbers is quite shorter and there are blank lines after each entry. That makes it very easy to read.
Unfortunately after reformatting Core's code with the current default settings in WPCS, there are several edge cases like this:
If you try reading the above example a few times you will probably notice how it becomes increasingly harder to match the array keys to the values.
To fix
The default maxPadding
value for Generic.Formatting.MultipleStatementAlignment
has to be changed from 40
to something like 10
. This seems to be a good amount of white space that prevents the above edge case and fully matches all examples in the WordPress Coding Standards.
Unfortunately it seems there is another bug preventing setting of maxColumn
to lower value. Testing with something like 20
doesn't seem to work.
Looking back at when maxPadding = 40 and maxColumn = 60 were chosen:
The value for maxPadding which I've chosen is arbitrary - similar to my notes about maxColumn in #1135 - and could probably use some scrutiny before deciding on the real number to use.
The sniff has been added to the Core ruleset with a maxColumn value of 60.
The 60 is arbitrary.
Additional Context (optional)
Looking at the PHP code in WPCS inself, the maxPadding
value used there comes from Squiz and is 12
which is much better. See https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist#L110.
Tested Against develop
branch?
[ * ] I have verified the issue still exists in the develop
branch of WPCS.