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
refactor: Use Prettier for code formatting #3737
Conversation
@schalkneethling @davidflanagan Does MDN have a style guide? Are we okay with using prettier? Do we already use it somewhere with specific settings? I don't see an ADR about it. https://github.com/mdn/mdn/tree/master/ADRs |
We are using Prettier with the rewrite of the frontend. We also use it for all other new SaSS, CSS, JavaSript in Kuma. We do have a config here, but I am going to throw that out and simply go with the Prettier defaults.
I am working on that as we speak. With the rewrite, it has become even more apparent to me that this is a requirement we can no longer put of. I am therefore working on my own time to define design elements, components, as well as code style. With regards to code style specifically, we will simply use whatever Prettier does. It seems like an unnecessary pain, to try and define and then enforce our own little quirks. There are much bigger problems and challenges we can use our energy to solve ;) |
Btw. this will all live in mdn-fiori. A lot of what is there now is appropriate, but I would not invest energy in reading through and absorbing the information that is currently there. Best to hold off until I/we release something that is "official" |
Thanks! In this PR the following setting are proposed: https://github.com/mdn/browser-compat-data/pull/3737/files#diff-f2e285fb35cc9694564cb6d2af099ad2 I'll wait for an MDN-wide decision and maybe an ADR before proceeding as these settings might not be the ones we'll be using throughout. |
Agreed. The JSON piece looks interesting(would need to read more about that), but for the rest, I would recommend going with the defaults. We can then disable Prettier for specific lines/blocks etc. should the default in some instances prove problematic. |
@Elchi3 @schalkneethling is it possible to open an issue or a draft PR somewhere (presumably for an ADR), to track the establishment of a style standard? I don't like the idea of leaving a PR open indefinitely while waiting on a decision, but I like it even less when there's no obvious place to check whether the PR is still blocked |
Yup, yup. I need to do that. Will place a link to it here. |
I’m in favour of using prettier (preferably with tabs). |
@schalkneethling is there an issue or PR to follow for a JS style decision yet? Not trying to rush the decision itself, but I want to make sure I'm keeping track of this appropriately. Thank you! |
Well, there should probably be an ADR PR like the one for pnpm: mdn/mdn#69. |
@ExE-Boss: I think this PR is incomplete without adding prettier to devDependencies in package.json, and also adding a script to package.json so that anyone can just type Also, the require-pragma things makes this opt-in, and requires that @prettier comment at the top of all the files. I did it that way for my kumascript refactor. I think because I was afraid to just make it the default. In kuma now, we're doing it by default for everything in kuma/javascript/src, and it is convenient not to have to use opt-in for each file with the Finally, it looks like you've even got prettier running over md files. Which seems like something that might be more controversial. I don't have an opinion, really, but it might be simpler to start with just .js and .ts files. @ddbeck: you and Florian are the ones who do the bulk of the work in this repo and I'd suggest that you should feel empowered to just make the call on this. If you think the ADR process would be useful for posterity, I'd encourage you to write up a really simple one. But also, there are a small enough number of files affected, that you could just try it out and see how it goes. The beauty of prettier is that it is easy to change your mind about the settings and reformat things again later. The only downside is that if there is formatting churn it affects the git repo history and breaks things like So basically, my advice is: don't over think it. But if you do decide to land this or something like it do update your package.json file with the devDependency and script. |
Way ahead of you: browser-compat-data/package.json Line 37 in 80e0ee1
browser-compat-data/package.json Line 42 in 80e0ee1
|
@davidflanagan thanks for your feedback on this!
This is a good point. I can't speak for @Elchi3 on this but my thinking was that if I was going to wreck the git blame, it'd be nice to do it consistent with related projects. But if it's not actually on anybody's near(ish)-term agenda, then we're just avoiding having a style at all. In the absence of a style guide, @wbamberg suggested the Airbnb ESLint style for mdn/short-descriptions#7, which has been a benign choice so far though I don't actually remember why we picked that one, apart from it being prominent. I like the idea of taking a style off the shelf and using it, though I don't know anything about prettier specifically. If @Elchi3 is OK with the prospect of having a BCD-specific style, then I'm willing to take a closer look at this particular approach. |
Well, BCD’s style is already very close to the Prettier default, so I’d just go with that. |
That's good to know! Though to be clear about myself: if the decision about a style isn't being handed down to us, then I want to be able to articulate what BCD's needs are from a style (and associated tools) and show that Prettier satisfies those needs. (It probably does—I'd imagine several styles would—but we should at least go through the motions to find out.) |
80e0ee1
to
69ccca1
Compare
69ccca1
to
6276802
Compare
6276802
to
59da8ab
Compare
review?(@Elchi3): I’ve rebased this. |
Thanks for your enthusiasm! However, I don't think that we're quite ready to review this one just yet, based upon the previous discussion:
Don't get me wrong, I'm all in favor for enforcing a common code styling. However, we should get an MDN-wide conclusion before making such changes. (I'll be proposing an ADR for this soon, or if you want some extra points, feel free to tackle it. 😉) |
Rather than propose an ADR, I opened up an issue on the main MDN repo to open further discussion and help us come to a final conclusion. (Also because I found some more info that may impact this decision.) mdn/mdn#71 |
Hey @ExE-Boss, it seems like the team is positive about using prettier generally. It also seems like the config doesn't matter too much but what we need most is a system in place that worries about formatting for us. That said, the config provided here should be fine and is hopefully close to how the code already formatted. |
In #3445, regarding c3ba2eb, I looked around, and we actually seem to disregard the |
KumaScript has specifically made the decision to require the |
While re-reviewing this PR, a few ideas came to mind: First, since this modifies a significant number of files, perhaps this should follow the bulk update/migration process we've recently drafted up. In other words, we should separate this PR into three: one for the changes script, one for the data updates, and one for a linter to enforce styling. In other words, perhaps this PR should only include the import and command for Prettier, as well as a script in Second, I'm also thinking that we should maybe consider throwing the Finally, someone submitted #4773 to apply formatting to all the Markdown documentation, however I decided to close it as this PR does the same thing, plus lots more (and we've already been working on this one). There is one change that the other PR introduced, however, that's not in here, which is an enforced line with of 80 characters. While I personally prefer to have no line breaks in my Markdown/rich text, I try to keep my code to 120 characters wide per line when I can. This may be something we wish to enforce in Prettier. None of the above statements should be interpreted as me formally requesting changes to this PR as a BCD peer, but rather as suggestions from a fellow developer and contributor. 😉 @Elchi3, let me know if you agree or disagree with the above as well! |
I agree @vinyldarkscratch 👍 Following the process will likely make this go through a lot smoother. I also agree about linting and thus avoiding regressing this. |
Hey @ExE-Boss, do you plan to return to this PR? It would be nice to get this off the ground and commence the migration process! (I'm also happy to tackle this, while of course giving you credit, if you're unable to. 😉) |
fcda1f5
to
7c8f906
Compare
Thanks for rebasing! However, as mentioned above, we thought it would be much easier if this PR could follow the data migration process we've recently documented. It would be nice if we can get started on that, and break out the data changes from the linter/infra changes! |
This reformats the repository using Prettier.