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

feature: binary_operator_spaces - Revert change about => alignment and use option instead #6724

Merged
merged 1 commit into from Jan 29, 2023

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Dec 24, 2022

HI @julienfalque

The previous bugfix in #6590 is subject to debate about yes or no it was a bug.

The issue #4395 and #5546 consider it's a bug.
The issue #6716 consider it's not.

I think the best solution is

This closes #6716

The only doubt I have is if by_scope is a good suffix or if there is one more meaningful...

@@ -2312,9 +3009,25 @@ function foo () {
}
',
],
[
'<?php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added for #6716 (comment)

@@ -656,6 +733,10 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA
// no need to analyze for `isBinaryOperator` (always true), nor if part of declare statement (not valid PHP)
// there is also no need to analyse the second arrow of a line
if ($token->isGivenKind(T_DOUBLE_ARROW) && $newLineFoundSinceLastPlaceholder) {
if ($yieldFoundSinceLastPlaceholder) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To handle #6716 (comment)

When a yield was previously use, it's another scope/level.

@@ -774,7 +859,11 @@ private function replacePlaceholders(Tokens $tokens, string $alignStrategy, stri
foreach ($lines as $index => $line) {
if (substr_count($line, $placeholder) > 0) {
$groups[$groupIndex][] = $index;
} elseif ('=>' !== $tokenContent) {
} elseif (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specific behavior won't be hardcoded for => but instead will be an option BY_SCOPE for alignment.

@@ -1643,6 +1643,703 @@ public function testFixAlignDoubleArrow(string $expected, ?string $input = null)
}

public static function provideAlignDoubleArrowCases(): array
{
return [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git diff is not great but I've duplicated provideAlignDoubleArrowCases into provideAlignScopedDoubleArrowCases with small diff I'll list.

"foo" => "bar",
"foofoo" => 42,
]),
"baz" => "OK",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In provideAlignScopedDoubleArrowCases, it's aligned with others arrows

1 => 2,
22 => 3,
],
100 => [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In provideAlignScopedDoubleArrowCases, it's aligned with others arrows

20 => 22,
30 => 33,
40
=>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In provideAlignScopedDoubleArrowCases, it's aligned with others arrows

Comment on lines +2008 to +2009
1 => 2,
5 => [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In provideAlignScopedDoubleArrowCases, it's aligned with others arrows

@coveralls
Copy link

coveralls commented Dec 24, 2022

Pull Request Test Coverage Report for Build 3770962655

  • 42 of 42 (100.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.006%) to 93.387%

Files with Coverage Reduction New Missed Lines %
src/PharChecker.php 1 85.71%
Totals Coverage Status
Change from base Build 3722532501: 0.006%
Covered Lines: 22709
Relevant Lines: 24317

💛 - Coveralls

@kenjis
Copy link

kenjis commented Dec 24, 2022

Thank you! This is awesome.
I've confirmed our source code style does not break.

The only doubt I have is if by_scope is a good suffix or if there is one more meaningful...

I'm not good at English, but I'm fine with by_scope.

@VincentLanglet
Copy link
Contributor Author

Hi, @julienfalque @keradus
There was a lot of reaction in the #6716 issue.
What do you think about this proposal to solve the situation ?
Is there a way for me to help with this PR ?

@kenjis
Copy link

kenjis commented Jan 18, 2023

We are really waiting for this fix.

@joaopalopes24
Copy link

We really need this fix. I thought the new organization was not good.

@keradus
Copy link
Member

keradus commented Jan 29, 2023

TBH this PR is too big complex to find time to properly review it. As you were touching it last, I put my trust on you here. Big thanks for taking care of it, and sorry for delay from our side!

@keradus keradus changed the title Revert change about => alignment and use option instead feature: binary_operator_spaces - Revert change about => alignment and use option instead Jan 29, 2023
@keradus keradus changed the title feature: binary_operator_spaces - Revert change about => alignment and use option instead feature: binary_operator_spaces - Revert change about => alignment and use option instead Jan 29, 2023
@keradus keradus merged commit 6b7eb5b into PHP-CS-Fixer:master Jan 29, 2023
@VincentLanglet
Copy link
Contributor Author

TBH this PR is too big complex to find time to properly review it. As you were touching it last, I put my trust on you here. Big thanks for taking care of it, and sorry for delay from our side!

Sure, I understand. I tried my best to cover changes with tests. Feel free to ping me if an issue occurs on this rule.

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

Successfully merging this pull request may close these issues.

New option to align arrows (binary_operator_spaces)
5 participants