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

Enforce new line for each array item if there's already at least one new line #6675

Open
VincentLanglet opened this issue Nov 2, 2022 · 15 comments · Fixed by #6677 · May be fixed by #7813
Open

Enforce new line for each array item if there's already at least one new line #6675

VincentLanglet opened this issue Nov 2, 2022 · 15 comments · Fixed by #6677 · May be fixed by #7813
Labels
kind/feature request topic/whitespace Indentation, spacing, new lines

Comments

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Nov 2, 2022

ℹ️ Note: related to #1217, but it looks like it should be implemented as configurable strategy.

Rule request

I just encountered the issue when I was surprised that

[$foo,
$bar]

was fixed to

[$foo,
$bar, ]

by the trailing_comma_in_multiline rule.

  1. We definitely need a rule to change this code to
[
    $foo,
    $bar,
]

Any idea about the name ?

  1. Even without this rule, shouldn't trailing_comma_in_multiline have a special behavior when the ] is on the same line than the last element ? I would expect
[$foo,
$bar]

to be untouched by this rule.

WDYT ?

@julienfalque
Copy link
Member

trailing_comma_in_multiline adding a comma here is definitely a bug to me. The purpose of the comma is to reduce noise in diffs when appending a new item is the array. In this snippet, the ] defeats this purpose so the comma is superfluous.

And I'm 👍 to add a rule that enforces newlines around every entry of an array as soon as there is at least one newline.

@kubawerlos
Copy link
Contributor

@VincentLanglet @julienfalque this ☝🏼 and maybe this then?

@VincentLanglet
Copy link
Contributor Author

The PR will fix the bug indeed.

Then we could add a rule to improve the display of multiline array (one item by line).

@julienfalque julienfalque reopened this Nov 4, 2022
@Wirone Wirone added the status/to verify issue needs to be confirmed or analysed to continue label May 16, 2023
@github-actions

This comment was marked as outdated.

@VincentLanglet
Copy link
Contributor Author

The rule is still not implemented

@Wirone
Copy link
Member

Wirone commented Aug 16, 2023

@VincentLanglet isn't it the same feature request as in #1217?

@VincentLanglet
Copy link
Contributor Author

I would say yes and no.

The referenced issues ask to always split multi items array.

Mine ask to fully split multi items arrays IF you started to write it multi line.

@Wirone Wirone added topic/whitespace Indentation, spacing, new lines and removed status/to verify issue needs to be confirmed or analysed to continue status/stale labels Aug 16, 2023
@Wirone Wirone changed the title New rule similar to method_argument_space but for arrays Enforce new line for each array item if there's already at least one new line Aug 16, 2023
@winiarekk
Copy link

winiarekk commented Oct 25, 2023

The new rule should be a part of @PER-CS ruleset as stated in https://www.php-fig.org/per/coding-style/

Array declarations MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first value in the array MUST be on the next line, and there MUST be only one value per line.

@Wirone
Copy link
Member

Wirone commented Oct 25, 2023

@winiarekk it's only MAY, so enforcing it would be a little bit too opinionated IMHO. Regardless, it's not required to make such decision here, we rather modify rulesets in separate PRs.

@VincentLanglet
Copy link
Contributor Author

@winiarekk it's only MAY, so enforcing it would be a little bit too opinionated IMHO. Regardless, it's not required to make such decision here, we rather modify rulesets in separate PRs.

It MAY be split across multiple lines,
but when it's split, it MUST be one value per line.

That's exactly the feature request.

I want

[$foo, $bar]

to be untouched, but

[$foo,
$bar]

fixed to

[
    $foo,
    $bar,
]

@Wirone
Copy link
Member

Wirone commented Oct 25, 2023

You're both right, I wasn't focused enough. Tough time in private life, that's why I don't do much here recently 😥. Good to see fresh heads around 👍.

This comment was marked as outdated.

@keithbrink
Copy link

Still relevant.

This comment was marked as outdated.

@VincentLanglet
Copy link
Contributor Author

Still WIp #7813

It requires #7901 first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature request topic/whitespace Indentation, spacing, new lines
Projects
None yet
6 participants