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

Squiz.WhiteSpace.OperatorSpacing false positive for negation in arrow function #3043

Closed
mabar opened this issue Aug 6, 2020 · 2 comments · Fixed by #3129
Closed

Squiz.WhiteSpace.OperatorSpacing false positive for negation in arrow function #3043

mabar opened this issue Aug 6, 2020 · 2 comments · Fixed by #3129

Comments

@mabar
Copy link

mabar commented Aug 6, 2020

Describe the bug
Minus - used as negation of brackets result is okay in function but not in fn

Code sample

This is reported

static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp())

This is not reported

static function (DateTime $a, DateTime $b): int {
	return -($a->getTimestamp() <=> $b->getTimestamp());
}

Custom ruleset

<ruleset>
  <rule ref="Squiz.WhiteSpace.OperatorSpacing">
		<properties>
			<property name="ignoreNewlines" value="true"/>
		</properties>
	</rule>
</ruleset>

To reproduce

  1. Create a file called test.php with the code sample above
  2. Create a file called ruleset.xml with custom ruleset above
  3. Run phpcs test.php --standard=ruleset.xml
  4. See error message displayed
Expected 1 space after "-"; 0 found (Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter)

Expected behavior

Code is not reported as invalid or at least have same behavior for both contexts (function and fn)

@jrfnl
Copy link
Contributor

jrfnl commented Sep 8, 2020

Confirmed. I have a fix ready for this, but the PR would conflict with open PRs #3102 and #3103, so I'll wait with pulling it until those have been merged.

Thanks for reporting this @mabar!

@jrfnl
Copy link
Contributor

jrfnl commented Sep 29, 2020

As PRs #3102 and #3103 have been merged, I've pulled the fix for this issue - PR #3129. Testing appreciated.

@gsherwood gsherwood changed the title Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter false positive Squiz.WhiteSpace.OperatorSpacing false positive for negation in arrow function Oct 13, 2020
gsherwood added a commit that referenced this issue Oct 13, 2020
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
3 participants