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

Allow opting in to multiline arrays explicitly #1008

Open
dkarlovi opened this issue Jun 24, 2024 · 7 comments
Open

Allow opting in to multiline arrays explicitly #1008

dkarlovi opened this issue Jun 24, 2024 · 7 comments

Comments

@dkarlovi
Copy link

dkarlovi commented Jun 24, 2024

Since multiline arrays are fully supported, it seems weird to not allow a feature to enable them when printing except by adding a dummy comment in the array.

An attribute like multiline = true seems like it should be enough to check in maybeMultiline? This could then be set when parsing, preserving the intent.

@ondrejmirtes
Copy link
Contributor

You can do this by yourself by extending the Standard printer, overriding the pCommaSeparated method and insert newlines between the items if the items are PhpParser\Node\ArrayItem.

@dkarlovi
Copy link
Author

Why would I do this myself if it's already fully supported, the only issue is you can't opt-in sanely, which this issue is trying to remedy.

@ondrejmirtes
Copy link
Contributor

Because it doesn't make sense to add options for everything. People might have different preferences for different code structures (many things can be formatted in multi-line fashion in PHP).

What about a single item array? Would you still want to have it formatted on multiple lines?

There are many unknowns and many people have different preferences.

That's why (IMHO) it's not worth it to burden the maintainer and all the users with additional complexity.

You can implement exactly what you need already today.

@dkarlovi
Copy link
Author

People might have different preferences

Which is why it says "opting in" in the title of the issue.

What about a single item array? Would you still want to have it formatted on multiple lines?

Maybe. I should get a chance to do that since it's literally already supported, the hard part is done.

@pmjones
Copy link

pmjones commented Jun 24, 2024

@dkarlovi pmjones/php-styler may be useful to you here.

@dkarlovi
Copy link
Author

@pmjones That looks like an external package so I'm not sure how it can help allowing to opt in into multiline arrays explicitly in this one?

@dkarlovi
Copy link
Author

@ondrejmirtes just realized your argument

it doesn't make sense to add options for everything

doesn't make sense here because there's literally the kind attribute for Array_ which decides how the array stmt should get printed (short or long syntax).

This could in theory be an extension to that: long / short, single line / multiline, do a Cartesian product of those.

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

No branches or pull requests

3 participants