Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing Warning After Declaring Function With Default Argument Value #2015

Closed
kassemEzz opened this issue Nov 22, 2021 · 2 comments
Closed

Comments

@kassemEzz
Copy link

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
@kassemEzz kassemEzz changed the title Wrong reporting After decalring function with default argument value Confusing Warning After Declaring Function With Default Argument Value Nov 22, 2021
@jrfnl
Copy link
Member

jrfnl commented Nov 22, 2021

@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.

@kassemEzz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants