vertical alignment of function/method arguments with default assignments #1162
Unanswered
JohnRDOrazio
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have added the
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
sniff to my phpcs.xml, and it's working for multiple adjacent assignments, except for within a function / method declaration.When a function / method takes a large number of arguments, it can make for more readable code to split the arguments each on their own line. If these arguments are also assigned default values, it can be aesthetically pleasing to see these assignments also vertically aligned:
In the example above, I added a tilde to represent the red squiggly line giving the sniff error
Incorrect spacing between argument "$one" and equals sign; expected 1 but found 3 (Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals)
.It seems that the
Generic.Formatting.MultipleStatementAlignment
sniff simply doesn't work for function argument assignments on multiple lines, because I tried disabling completely theSquiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals
sniff, but even with that disabled theGeneric.Formatting.MultipleStatementAlignment
sniff doesn't kick in when the assignments are not vertically aligned.So perhaps this could be a feature request, to allow
Generic.Formatting.MultipleStatementAlignment
to work also for function arguments that are split across multiple lines. I'm not sure if or how that would interfere with theSquiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals
, which would perhaps also need to be able to be customized toignoreMultiline
, so that the two sniffs don't compete.Or is there another solution that anyone could suggest for this use case?
Beta Was this translation helpful? Give feedback.
All reactions