Page MenuHomePhabricator

MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment is too strict
Open, Needs TriagePublic

Description

Consider the following snippet:

functionWithAVeryLongParameterList( /* $param1 */ 1, /* $param2 */ 2, ... /* $param10 */ 10 )

Currently, it generates a warning:

xx | WARNING | Comments should start on new line.
   |         | (MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment)

However, adding clarity to call lists like that is a perfectly good practice and should not be discouraged.

Event Timeline

So, to put in terms that can be implemented in the sniff: don't complain about not having a newline before a single line comment, if after the comment ends there is more code?

Note this will become more and more irrelevant when we can start using PHP 8's named arguments:

functionWithAVeryLongParameterList( param1: 1, param2: 2, ... param10: 10 )

However, this might take a while. Until then I agree with what @MaxSem originally wrote.

I'm not sure how to check for this specific use case.

  • Check the surrounding scope and don't complain when the comment is inside a pair of round brackets? This will fix this issue, but also allow other usages that should still be reported.
  • Check if there is code before and after, without checking what this code is? I guess this will allow for many, many more usages we don't want to allow.
  • Check if the previous token is an opening bracket or a comma. This will allow exactly what this ticket describes, but nothing else.
  • … other ideas?