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

[Feature] Insert a space after the fn keyword for arrow functions #414

Open
1 task done
hirasso opened this issue Mar 23, 2024 · 2 comments
Open
1 task done

[Feature] Insert a space after the fn keyword for arrow functions #414

hirasso opened this issue Mar 23, 2024 · 2 comments

Comments

@hirasso
Copy link

hirasso commented Mar 23, 2024

Is your feature request related to a problem?

Not really. It's more of a "nice to have". I'd like phpcbf to format my arrow functions from this:

$ids = array_map(fn($entity) => $entity->getId(), $entities);

to this (note the space after the fn keyword):

$ids = array_map(fn ($entity) => $entity->getId(), $entities);

Describe the solution you'd like

Maybe there already is a rule for this? When I google it, I'm only able to find this resolved issue on the PHP CS Fixer repo.

Additional context (optional)

  • if I would know the ins and outs of PHP_CodeSniffer, I'd certainly propose a PR. But I'm only beginning to use it...
@jrfnl
Copy link
Member

jrfnl commented Mar 24, 2024

@hirasso Thanks for bringing this up.

There is an open PR for this in the old repo, however, that PR was blocked because PSR-PER (the successor of PSR12) in their wisdom decided that there should be no space after the fn keyword for arrow function - in contrast to the required one space after the function keyword for closures....

I didn't port that PR over (yet) to this repo as it would need an update before it would be viable for merge, but considering your request, maybe the updated version of the PR shouldn't enforce no space, but should make it a configurable option, with the default being no space (to satisfy PSR-PER) and a user override being available to change this to 1 space.

What do you think ?

@hirasso
Copy link
Author

hirasso commented Mar 25, 2024

That sounds very reasonable to me! Thanks for the link to that PR. It's hugely interesting to read all the thoughts that go into these decisions.

Thank you for your very important work 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants