-
Notifications
You must be signed in to change notification settings - Fork 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: Use Prettier? #12260
Comments
There is also https://github.com/prettier/prettier-eslint which formats your code via |
It is also possible to execute prettier in a linter mode. It requires some code, but it shouldn't be a big deal. See this comment about Jest integration: facebook/react#9101 (comment). |
I guess it depends on the scope of those changes but this looks like a non-negligible downside to me.
Could you point me to a good example of this? I always found that very difficult to do but maybe I'm missing something. |
here's what I used for the notifications client:
in my IDE I have it auto-format on save which is wonderful because on pre-commit it formats all of the changed files. this has been an excellent way of removing a lot of cruft for me while trying to focus on more important matters. I think we could win in Calypso with it as well there are things I don't like about it:
these annoyances have just been that: annoyances; I find the project as a whole is in a much better place because of it. bias: I think JavaScript suffers by not having a standard format guide. I may not like the style but at least I don't have a choice… I use |
@stephanethomas ^^^ |
Wow, I've never noticed that feature. Thanks @dmsnell! |
Why not? All Prettier does is parse the code into an AST and apply a pretty printer output. There is little difference between this and what ESLint does. While it may be true that ESLint's fixer doesn't currently support all rules, it's not fair to claim it can't.
Except if they're coming from a WordPress background.
Sounds like a good candidate for an ESLint error rule.
Is this more a point to them not having a consistent and documented style of their own previously? |
Are we addressing a real pain with this proposal? |
fair. ESLint may some day support fixing all rules
The reason I brought this up wasn't about pointing out the merits or problems with their previous style. It was to highlight the level of maturity / expected continued development & support for
The pain is totally subjective and will differ person to person. Its the reason I proposed a vote. |
for me we are. I would also argue that even if ESLint can "fix" these things it does a very poor job of it, which is one of the reasons given as the impetus for
how is this? it seems like the jump from a "WordPress background" to Calypso is already huge, plus people have to learn our style guides. with an auto-formatter that last piece has been eliminated.
|
Because despite some slight variation (that I'd like to champion upstream) and revisions specific to ES2015+, there's significant overlap between our style guide and the core JavaScript Coding Standards on which it was originally based. |
I love the developer experience of the AST approach brings to the table, though it should be able to match our current style and, to be honest, it would be great that some of the bugs are ironed out, because each change in the tool leads to formatting changes in commits. And we all love those :) |
@nb I think we will be guaranteed that |
@dmsnell outside of the ambiguities, we should be able to get our spaces, at least. |
http://eslint.org/docs/rules/space-in-parens with --fix flag should help |
@nb, you may be interested in: prettier/prettier#40. In summary though: some vocal and influential parts of the js community think that it would be best to not support most configuration. The only one that will probably actually get developed at some point is tabs vs. spaces. Definitely not our liberal spacing around parenthesis. |
see also https://github.com/prettier/prettier-atom and other tools |
Seems like one key question in this discussion is: Do we want to, or do we not want to continue to follow WordPress core's JS Coding Standards? By using |
Agreed. A vote for 👍 is a vote for breaking with WP JS Coding Standards |
I still think the link and the value of the link is dubious. Our coding style is considerably different than what one will find in WordPress and that's happening at a much higher level than spaces and line-lengths. A vote for this is also a vote to remove the obstacle of needing to learn any coding style at all, to eliminate all discussion about style, to handle styling deterministically, and to enjoy the benefits thereof 😄 |
I've created a PR to figure out the finer details in case we decide to Use Prettier #12479 |
If we introduce |
To be honest, I don't think we should vote to decide if we deviate from WP-core standards ... I think this is the kind of decision it should come "from above", or, in any case, decided between the whole company (if we change our standards, we should do it in every automattic project, not just in calypso). A one-sided calypso change would be pretty terrible for anyone who usually works on more than one of our projects at the same time |
I disagree. As @dmsnell explained higher up, using prettier actually doesn't require you learn much new. Its a one time setup cost of integrating a new plugin to your editor/workflow. This shouldn't make working on multiple projects any harder. |
https://github.com/prettier/prettier-eslint seems like it'll get us where we want to be format wise. |
👍 to what @blowery said. Prettier + eslint --fix will do the trick. |
related prettier/prettier-atom#133 been trying that out with our |
Because I've been wanting to use it locally for development, I created a fork (wp-prettier) that keeps our spaces and uses tabs. In order to setup in vscode I did this (and installed the prettier plugin):
|
hrm… not sure how I feel about that but good work! |
As mentioned here #13759 (comment). If we want to effectively use codemods it would be very convenient to have prettier in our workflow. Otherwise we will have to fix issues manually from time to time, because I don't believe |
for the sake of discussion, I would like to propose that we don't mix eslint formatting and prettier. if we introduce prettier then we should stop using why? prettier is designed to be a deterministic formatter and if we start mixing it we're not only defeating that purpose but also introducing potential races and cycles in the formatting between them. |
I've opened a PR to incorporate a fork of cc @gziolo Edit: forgot to link to the pr #14010 |
There is ongoing discussion about using prettier in WordPress core. There is similar set of issues that need to be resolved. @ntwb is planning to explore this further. |
I found also this closed issue in Prettier's repository: prettier/prettier#1303. It seems like they aren't totally against this rule. If there would be a bigger group requesting this feature they would at least consider it. |
Over the last few weeks, I spent some time playing with our prettier fork (originally created by @samouri) and I did some work that might be interesting for Calypso and WordPress developers: I turned the changes into a proper option ( I rebased the patch two times already against official releases -- first time from 1.1 to 1.2, second time 1.2 to 1.5. It's not a very big deal and I can commit to doing the upgrade regularly as needed and to fix any related bugs. There is a calypso-1.5 branch in the fork repo that contains a sequence of independent and easy-to-maintain commits. One adds the If we decide to use the fork, I think it's now in a very good shape and easy to maintain. I don't know the status of the WordPress core discussion mentioned by @gziolo and the explorations done by @ntwb. I'd love to learn more about that. |
Thanks for maintaining that @jsnajdr - it's still a big patch and I'm not sure how easy it would be to maintain if someone else had to jump into it, especially if the official repo diverges much. I'm more in favor every day of just accepting all the default options and letting it be. We even recently made the jump to spaces over tabs in the notifications client (and I prefer tabs!) and so far it hasn't caused one little headache at all. The benefits of not having to think about styling are so huge and the auto-format while I code makes me that much quicker. |
If that ever happens and the style guide for Calypso (or WordPress in general) changes, that's going to be great, of course. Meanwhile, if someone wants to just press |
@jsnajdr is there a PR out there to update calypso to use the newest fork? |
Just created one: #15942 |
lets use calypso-prettierWith the release of React 16, and the important role that codemods will play in getting us to a state where we can upgrade, I think its important to revisit the question of whether or not we want to use a code auto-formatter for the entire repo. Besides for all of the points mentioned in this thread so far, the one I'm focusing on right now is that running Here are some updates on
Thanks to all the people that have been making Note: @dmsnell attempted this months back: #14801 Related: p4TIVU-89g-p2 |
Speaking from my recent trial perspective, I have to say that calypso-prettier was immensely helpful in getting up to speed with the formatting style. It meant I could focus on producing output right away rather than worrying about formatting details (while learning them along the way by looking at the changes made by calypso-prettier). Two key advantages here: It makes the onboarding experience for new OSS contributors considerably smoother. It cuts down the time spent on PR reviews considerably, no more loops just to correct formatting means time saved on both ends. So from a trial / new hire perspective definitely a 👍 for calypso-prettier. |
My evolution with
My vote is yes! |
My evolution with
My vote has been openly yes! |
It finally happened! 🎉 |
Over the past few weeks, the prettier javascript auto-formatter has come up many times in calypso-framework chat. 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
tldw:
git blame
. GitHub makes it pretty easy to skip around blame historyI think we all know that we could debate styles until the end of time, so I figure lets just call for a vote and be done with it. Should we spin up a PR that formats all of calypso, modifies our eslint style rules, and updates our docs?
Thumbs up for yes, thumbs down for no.
The text was updated successfully, but these errors were encountered: