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

Forcing short hand arrays in PHP #2123

Open
vincentmcgreevy opened this issue Dec 30, 2022 · 5 comments
Open

Forcing short hand arrays in PHP #2123

vincentmcgreevy opened this issue Dec 30, 2022 · 5 comments

Comments

@vincentmcgreevy
Copy link

It appears the PHP array short hand is being forced for version 5.4 and above?

const useShortForm =
(node.kind === "array" && isMinVersion(options.phpVersion, "5.4")) ||
(node.kind === "list" && node.shortForm

Can this be updated to have the option to override this?

@czosel
Copy link
Collaborator

czosel commented Dec 30, 2022

Hi @vincentmcgreevy! That's correct, there is no option to override this. Prettier is an opinionated code formatter, and we try to keep the number of options to an absolute minimum. Can you explain why the shorthand array syntax is not working out for you?

@Dalton-James
Copy link

I am actually having the same issue. We have the old syntax in 1000s of places and them all being updated makes PRs very hard to distinguish between real changes and these

@czosel
Copy link
Collaborator

czosel commented Feb 4, 2023

@Dalton-James I'd recommend to format every file in a single commit when introducing prettier in an existing codebase, such that commits afterwards never just change formatting at places unrelated to the actual change. There even is a way to rewrite history as if the project would have always been formatted with Prettier, but I never tried that myself.

@vincentmcgreevy
Copy link
Author

Formatting all the code at once is not an option, we have a lot of old PHP scripts and prettier was breaking scripts so we lost any confidence in doing this. From what I remember one of the issues was prettier broke the syntax if you declared a class property with a variable.

@czosel
Copy link
Collaborator

czosel commented Jun 9, 2023

@vincentmcgreevy I get that. I’ll mention the AST_COMPARE flag though, which ensures that the AST doesn’t change after formatting (except expected changes), which should give you additional safety. See

* You can run `AST_COMPARE=1 yarn test` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent.

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