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

Could the Standard pretty printer add a space after "use" keyword #418

Closed
martinsik opened this issue Sep 24, 2017 · 1 comment
Closed

Comments

@martinsik
Copy link

martinsik commented Sep 24, 2017

I've noticed that when I try to pretty print code with PhpParser\PrettyPrinter\Standard that contains closures with the use clause it'll be printed without spaces after the use keyword:

function() use($var) { ...

while I'd expect this:

function() use ($var) { ...

I checked the documentation (http://php.net/manual/en/functions.anonymous.php) and they do use spaces after use so I was thinking if this is intentional or possibly available for PR.

https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/PrettyPrinter/Standard.php#L556

@nikic
Copy link
Owner

nikic commented Sep 26, 2017

We can't really satisfy everyone with the default behavior -- there's just too many different coding styles in active use. Even adding options is not feasible, because there are hundreds of individual items that may need configuration. My recommendation would be:

  • If you only want to adjust a few things, extend the respective method in the pretty printer.
  • If you want to have more precise control of the formatting, print using the default style and then run the result though one of the existing code formatting libraries, which already implement fine-grained options to control formatting.
  • If you're not generating but modifying code, Format-preserving AST transformations TODO #344 may be an option.

@nikic nikic closed this as completed Sep 26, 2017
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

2 participants