Skip to content

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

Closed
@mabar

Description

@mabar

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions