WordPress/WordPress-Coding-Standards

Confusing Warning After Declaring Function With Default Argument Value

kassemEzz opened this issue · 2 comments

Bug Description

When declaring two Javascript functions, with the first one having a default value assigned to its parameter, a warning is thrown targeting the line of the second function declaration stating that the equals sign is not aligned.

So the following code

aVerylongFunctionName = function( arg = null ) {
	// Some code here.
}

testFun = function() {
	// Some code here.
}

The sniff throws the warning:

5 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

While the same code with the default value for the argument removed:

aVerylongFunctionName = function( arg ) {
	// Some code here.
}

testFun = function() {
	// Some code here.
}

does not throw any warning.

I could be missing something but this does not seem right.
Any explanation of why this is happening is much appreciated.

Environment

Question Answer
PHP version 5.6.40
PHP_CodeSniffer version 3.6.1
WPCS version 2.3.0
jrfnl commented

@kassemEzz Thanks for reporting this, but I'd like to ask you to read the contributing guidelines about reporting bugs.

Based on your report as-is, this is not an issue with WPCS, but with one of the upstream sniffs and therefore should have been reported upstream to PHP_CodeSniffer.

I suspect it may be a similar/the same issue as this one, which was reported upstream a while ago and already has a PR open to fix it. I suggest you test that PR to verify.

I'll be closing this issue now. If you are sure this is a WPCS issue and can come up with a code sample with which this would be reproducable for one of the WPCS sniffs, please add the extra information and the issue can be reopened.

@jrfnl For some reason I thought I was reporting this to the sniffer page 🤦‍♂️.
Thanks