In coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php line 112 we have
if ($isInlineArray === true) {
// Check if this array contains at least 3 elements and exceeds the 80
// character line length.
So what is the reason for an array with two elements being allowed to extend beyond the specified limit? I get it if the 2nd element starts before the limit and extends beyond, but that is not what's being checked for here. I must be missing something.
Secondly, a minor point, following https://git.drupalcode.org/project/coder/commit/0b2dc22 when next changing that file the comment should refer to $this->lineLimit instead of 80.
Set the array line limit for a project
The default (and Drupal standard) array line length is 80 characters. This is independent of the general maximum line length, and can be set for all files by using the project's phpcs.xml.dist file. The example below sets the general line length to 100 but allows arrays to extend to 120
<rule ref="Drupal.Files.LineLength">
<properties>
<property name="lineLimit" value="100"/>
</properties>
</rule>
<rule ref="Drupal.Arrays.Array">
<properties>
<property name="lineLimit" value="120"/>
</properties>
</rule>
Override the array line limit for a file
To override the setting in a specific file, add this to the file document header block. This example increases the array limt to 140.
* phpcs:set Drupal.Arrays.Array lineLimit 140
Comments
Comment #2
jonathan1055 commentedThe coder message given is
So if the rule is correct to only apply for 3-element arrays and above, the message could be altered to say that. Otherwise you get confusion.
Comment #3
klausiNo particular reason that I remember, so we can also apply this to 2 element arrays.
Comment #4
jonathan1055 commentedCreated PR 114 to deal with this. First the test data change, then the sniff change.
https://github.com/pfrenssen/coder/pull/114
Comment #5
jonathan1055 commentedThe PR is ready for review.
Comment #6
klausiThanks, left some comments on the pull request.
Comment #7
jonathan1055 commentedHi @klausi,
I have updated PR 114 with the changes you asked for, and answred your questions.
Comment #9
klausiMerged, thanks a lot!
Comment #10
jonathan1055 commentedI think somewhere we should document explicitly document how to set the overall array line length per project in phpcs.xml.dist and how to override this setting per file. I have updated this issue summary with the details. Does this need to copied elsewhere too?
Comment #11
klausiI don't think so - people shouldn't change this setting as it then would violate the Drupal coding standard. We should not encourage that.
So I think leaving this here in an issue is enough for advanced users to find.
Comment #12
jonathan1055 commentedOK, yes that's fine. Core 8.9 and 9.0 currently exclude this sniff anyway. There has been some general talk (not just within Drupal) that the 80-char limit is quite dated now, and was set when we all had much smaller monitor screens. So I would not be surprised if some project maintainers would happily chose to increase the limit. I have modified the issue summary slightly.
Comment #14
taran2lHello, I think that this particular change creates a lot of false-positive warnings.
A few examples
The following line:
generates
Similar issue with lines like the following:
Is it expected behavior?
Comment #15
jonathan1055 commentedHi Taran2L,
I think the problems you describe have been fixed in #3169452: Use $parenthesisCloser column to correctly determine inline array length but this is currently only in the -dev release.
Jonathan
Comment #16
klausiCoder 8.3.11 has been released with the fix there!