Skip to content

PHP formatting support#3521

Closed
mgrip wants to merge 38 commits intoprettier:masterfrom
mgrip:php-prettier
Closed

PHP formatting support#3521
mgrip wants to merge 38 commits intoprettier:masterfrom
mgrip:php-prettier

Conversation

@mgrip
Copy link
Copy Markdown
Contributor

@mgrip mgrip commented Dec 18, 2017

Inspiration taken from #3349 - this time for php! There's still a lot of work to be done here, but wanted to get eyes on it to make sure we're headed in the right direction. We're using https://github.com/glayzzle/php-parser for a parser - luckily its written in JS so no need for external dependencies.

@TrySound
Copy link
Copy Markdown
Contributor

Adding another one dependency will make prettier even larger which is not good. Look at python implementation #3349 without deps.

@@ -0,0 +1,7827 @@
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this file.. since we are using yarn.lock

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

whoops sorry about that - all set!

@azz
Copy link
Copy Markdown
Member

azz commented Dec 18, 2017

Hi! Thanks for working on this. I think we should finish HTML printing before tackling PHP, because PHP has to be embedded in a HTML document.

@azz
Copy link
Copy Markdown
Member

azz commented Dec 18, 2017

Unless we just support PHP files without any HTML?

@vjeux
Copy link
Copy Markdown
Contributor

vjeux commented Dec 18, 2017

This is really exciting! I just want to make sure that you are aware that writing a pretty printer for a full language (and one as crazy as PHP) is going to be a big undertaking. If you are onboard, here are the three overall steps:

  1. Keep doing what you're doing and print all the nodes.
  2. Run --debug-check through a bunch of big codebases and make sure that you are every piece of code you can throw at it correctly.
  3. Make sure the long tail of code is printed in a way that looks good.

Step 2 is absolutely critical. If your formatter outputs invalid code, people are not going to trust it, no matter how pretty the code is.

@hawkrives
Copy link
Copy Markdown
Contributor

@mgrip For step 2, you can let me know when you think you have something that should work – I can run it on a big-ish internal Wordpress theme / app.

@mgrip
Copy link
Copy Markdown
Contributor Author

mgrip commented Dec 19, 2017

thanks for the info all! so i cant make any promises in terms of timeline, but definitely interested in pushing this forward. I work with a large number of engineers using php daily, so im sure I could wrangle some help there as well (and we have a very large php codebase to run it against for testing, in addition to some open source ones like wordpress or drupal). mostly wanted to post this initially to make sure we’re headed in the right direction. in terms of next steps, that makes sense - thanks @vjeux. what are your guys thoughts on the parser we’re using? that could be expensive to pivot on, so just want to make sure thats set in stone before continuing on with this.

return handleNode(n);
}

function handleLiteral(node) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should these be renamed print* to be similar to other printers’ methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

makes sense - updated!

@azz azz mentioned this pull request Dec 21, 2017
9 tasks
@azz
Copy link
Copy Markdown
Member

azz commented Dec 21, 2017

👋 @mgrip, FYI: #3349 (comment).

@mgrip
Copy link
Copy Markdown
Contributor Author

mgrip commented Dec 21, 2017

makes sense, sounds much more scalable. so the intent would be to move this PR to a new prettier/prettier-php repo with a dependency on prettier?

return true;
}
}
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can just do array.indexOf(val) !== -1 here.

@mgrip
Copy link
Copy Markdown
Contributor Author

mgrip commented Dec 21, 2017

anyone know why the ci job fails w/ NODE_ENV=production? seems if dependencies are added in the PR they don't actually get installed?

@maks-rafalko
Copy link
Copy Markdown

Sorry for such a question, but why have you decided to support PHP when there is already a known leader of PHP Code Style fixes: PHP-CS-Fixer ?

@azz
Copy link
Copy Markdown
Member

azz commented Dec 23, 2017

Looks like that's a fixer (rule based edits), not a full formatter.

@azz
Copy link
Copy Markdown
Member

azz commented Dec 24, 2017

I have copied all the commits from this pull request to a new repository using the in-progress plugin API. https://github.com/prettier/prettier-php

@mgrip I have added you as an admin of the repository.

@azz azz closed this Dec 24, 2017
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants