-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Framework: Should we use Prettier? #2819
Comments
One more idea would be to use the newly introduced After the very small initial setup, every new addition will be autofixed by that ESLint plugin. One more cool thing to note is the fact that prettier supports config files and config in |
@andreiglingeanu yes, this is how Facebook introduced prettier in their projects. It's a very nice way which helps to roll out it gradually.
We would need |
I'd love to see this. I've used prettier in the past on a Gutenberg-sized project and it's very nice to not have to be conscious about formatting rules while writing code. |
Another try to encourage Prettier team to add the spacing rule: prettier/prettier#1303 (comment) and https://twitter.com/gziolo/status/944165778655498240. |
I'm all for supporting Prettier + ESLint rule. While trying to build an ESLint + Prettier setup for WordPress I am having the same troubles being discussed here and am discussing it here at a Facebook thread. Maybe we can build a combination of Not sure, thinking out loud here. |
@ahmadawais, yes it makes perfect sense. We should definitely try to provide a setup which combines all that ingredients. Actually, I'm planning on spinning a PR with that in the upcoming days/weeks. I will put it under https://github.com/WordPress/packages. |
For what it's worth, I've been using https://github.com/prettier/prettier-eslint in my day-to-day work on Gutenberg for the past 20 or so days. It works pretty nicely with just our So far, I've only noticed one issue. {isVisible && (
<Something
foo="bar"
/>
)} Instead of this: { isVisible && (
<Something
foo="bar"
/>
) } |
We can always add our own —fix for this case. I’m sure @aduth know all the tricks required to have it coded. I didn’t known prettier-eslint was moved to the prettier org. I assumed that it is no longer maintained... |
Turns out it was just a matter of setting a property on one of our eslint rules: #4362 😄 |
Do you have prettier-eslint configured globally and your IDE calls it on every file save? |
I have it set up in my IDE using https://github.com/prettier/prettier-vscode but I haven't set it up to run automatically since doing so would introduce a lot of unrelated and probably distracting changes into my PRs. In case anyone is curious, here's what I put in my VSCode settings (after installing the plugin) to have it work nicely for Gutenberg: "prettier.printWidth": 120,
"prettier.tabWidth": 4,
"prettier.eslintIntegration": true |
I started experimenting with reusable scripts which would simplify sharing code between Gutenberg and shared Wordpress packages in WordPress/packages#62. @noisysocks, we should also work on prettier command which would use the setup you described. I like it a lot. If other people agree we could battle test it on the https://github.com/WordPress/packages repository :) |
Also, Prettier for PHP is coming 🎉 |
We already use |
@noisysocks The spacing issue with Prettier is keeping me away from using it in the WordPress projects. Can you share with me how you have set it up along with ESLint to follow WordPress Code Standards? Also would you be willing to help build an open source goto standard library that once included in WordPress projects would the formatting for us? I had a discussion with @gziolo on AWP FB Group about it and am really interested in building something like that. |
The spacing issue I described should be fixed now that #4362 is merged. |
Closing per #4628 (comment) (Quoted below for reference)
|
Issue Overview
The prettier javascript auto-formatter has already come up in the WordPress/packages PR and #core-js discussion a few weeks back. For anyone who wants a fun introduction to what prettier is, feel free to watch the creators lightning talk at ReactConf: https://www.youtube.com/watch?v=hkfBvpEfWdA
or listen to one of the episodes of 5 minutes of React podcast about Prettier:
https://m.soundcloud.com/5minreact_audio/018-prettier
tldw:
git blame
.Props to @samouri for preparing a ver similar list here in the context of Calypso.
Current Behavior
In my opinion, there is one blocker that needs to be resolved, which @aduth mentioned in this post Proposal for JS Standards Revision: Removing Array/Function Whitespace Exceptions:
There seems to be general agreement that we should remove all exceptions, which would make usage of Prettier completely valid. There is still one issue that would have to be tackled - WordPress spacing conventions - which aren't supported by Prettier. There was already an open issue in Prettier where spaces between parens and brackets were proposed, but it was rejected.
Possible Solutions
eslint
with the--fix
flag, your code will be formatted according to prettier style. It might get into conflicts with other rules, so it might not work as expected with spaces. See also this related article from @neciu to find out more.The text was updated successfully, but these errors were encountered: