-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
💅 Add Prettier 💇 #628
💅 Add Prettier 💇 #628
Conversation
The current How would this work with this RFC's proposed I would assume we'd want to avoid running duplicate lint tasks, but I do like that the wildcards in these script commands conveniently pick up on similarly-named script commands that application authors may add (such as |
Should we add prettier for handlebars templates too? |
Great question @kpfefferle! I pushed an update in a32ad2d to clarify and show how to fix (tldr; you change from |
I don't think we should do that at this time, but as the formatting behaviors continue to improve in |
@lifeart Prettier for HBS files isn't completely ready for the limelight yet in my opinion. There are still a few kinks to remove before we can do this. :) |
Prettier quest: prettier/prettier#4908 |
The RFC adds lint:hbs:fix. This probably should be added regardless of whether prettier configuration is added. In my experience with prettier, it generates lots of stylistic errors that often obscure "real" problems as well as issues I might temporarily not want autofixed (like debugger statements and console.logs). Is there a way to temporarily disable prettier errors on the command line? If so, can we add that to the config? Is there some way we can add a git precommit hook to the boilerplate as well to automatically run lint:js:fix? I often break prettier linting with only minor touchups and forget to rerun it. |
Sure, but we have to add it somewhere. I guess I could remove
Perhaps, but FWIW, that is also the part that is super freeing for developers. As I mentioned in the RFC, you just author however you want to and let Prettier take care of the final formatting. Editor settings such as format on save or suggested code actions make it very trivial to automatically apply, and if you don't want to fiddle with your editor settings the
Prettier will not remove
I personally dislike precommit hooks as a rule, and violently dislike those that rewrite file contents. In theory we could add one that validates only (see this example), but I'd prefer not to. |
This was/is a holy war for my team. Including Prettier was massively disrupting at first, though we have experimented with it on greenfield projects. That said, why Prettier? Why not Standard? Etc. |
Ya, I totally agree that initial adoption is definitely the most difficult part of the process. One thing to keep in mind is that this RFC is specifically talking about adding this setup to new apps/addons (e.g. greenfield projects). While it is true that
First up, I'll be perfectly frank: I chose Prettier for this RFC because I prefer it and have the most experience with it. Aside from my personal preferences Prettier is much more popular with 9,249,847 weekly downloads vs 265,658 weekly downloads (we all know these download numbers don't mean a ton, but the order of magnitude can tell us something), and (aside from the defaulting of Another data point here is that a very large number of the Ember ecosystem projects are already using Prettier internally. These include |
FWIW I have established a pattern in my apps for using for reference I also include |
Yep, totally agree! Thats exactly the setup proposed here. 😃 |
We discussed this in todays meeting, and are moving into final comment period. |
Doesn’t this overlaps with the current editorconfig? |
Big fan. Prettier caused and removed quite a bit of discussion in many of my projects but it was worth it for the less noisy PRs alone.
module.exports = {
singleQuote: true,
};
module.exports = {
singleQuote: true,
overrides: [
{
files: '**/*.hbs',
options: {
singleQuote: false,
},
},
],
}
module.exports = {
singleQuote: true,
overrides: [
{
files: '**/*{yml,yaml}',
options: {
singleQuote: false,
},
},
],
} All three blocks merged make up the Prettier config that served me well in all recent ember projects. |
This was introduced 4 days ago and has had considerable feedback. Why is it being rushed into FCP? |
@ro0gr asked a similar question inline, but the thread is resolved so it doesn't display. Here was my reply:
|
Thanks for chiming in here @kellyselden! I don’t find that Prettier makes using That initial migration absolutely takes over the |
@kellyselden - Finally back to my computer, and wanted to reply to a few more points you made:
FWIW, initial drafts had a bit of a "history lesson" vibe, but it just wasn't very interesting or useful to the overall proposal. Your point in that PR was 100% correct: a change of this magnitude and impact to the community deserves an RFC. That is what this RFC is. 😸 There was absolutely no malicious intent or burying of facts in leaving it out.
I think this is likely the main point of disagreement here. The entire point of this proposal (and AFAICT Prettier itself) is exactly the opposite: folks should not think about formatting at all when authoring or reviewing code. Your brain power is much better used on solving actual problems in your domain, the computer can do the rote formatting for you. In my experience, having bespoke formatting works when only one person is responsible to maintain it, but once you have a team of folks all with their own "style" you have:
tldr; I believe that in the end, even if you disagree with Prettier's formatting of specific constructs it still lets you build higher, faster, with less team confusion and conflict. THAT is why it is especially important for the Ember ecosystem to adopt. |
FYI - I've done that in 1276199. |
That's exactly the problem I'm refering to. Prettier often, in my experience, takes a simple change and makes it hard to trace in history. Given the example:
Now removing item6 gives you:
Now trying to figure out when item2, for example, change takes two blame lookups. This is a simple example, you can imagine it gets pretty hair in real-world. This is what I meant when I said prettier makes me think of formatting while I'm coding, and the historical context change if I make certain changes to code. All your responses to me seem like you think I'm arguing against the value of linting and autofixing. That's not true. I'm informing people that if you adopt prettier, you're probably going to lose reliable git blames, which was the case for me. (You also will get some pretty awkward one-liners, think array lists, destructuring, etc) |
The array example, and maybe small objects, are the only ones I know of where I personally prefer the non-prettier version. Though, I still prefer prettier overall. If prettier could instead have some way of determining when multi-line arrays can be formatted to look nicer... Then I'd have 0 problems with prettier. But for my case, I had an array with a grid of 5x5 entries in the array, and prettier made it 25 lines. :Shrug: Idk. There seems to be no way to programmatically figure out how to format an array. So many options. |
I just can't agree here. Perhaps you will loose reliable first level |
Nah, I know we agree much more than disagree here.🥇 Most likely I just value the overall reduction in both mental overhead when authoring code (no need to get format "just right") and bikeshedding that you get on teams when using 👋 some other tool 👋 to do stylistic formatting and it is therefore out of your control a little bit more. |
What do you mean by first level? If an array/destructure has lots of activity, prettier will continually collapse and expand the line (seen in real life), adding a new git blame indirection each time. |
I mean doing literally a single
Yep, definitely happens (I've seen it too!), though this seems like an exception and not the normal experience. It will only happen when a given statement is right on the cusp of being too long for the one liner. Ultimately, even if you conclude that this line wrapping (or unwrapping) is not ideal (which I'm not really sure I agree with TBH) the benefits to the overall codebase (and team productivity) far outweigh that cost. |
🎉 Nice to have this adopted as part of the ember's ecosystem and while creating new ember apps, this becomes the perfect way to start. However, I had a question on the default blueprint files that are generated using the The default ember-source blueprints that generate test cases would need to be altered. For example, the default generated unit test case follows:
Now, Prettier would add an error on I believe the codemod you are suggesting (ember-cli-prettier-codemod) should handle this as well as the initial migration? |
@abhilashlr There is no configuration option for this. For why, read https://prettier.io/docs/en/option-philosophy.html Yes, I think it will be necessary to audit our blueprints for prettier errors. |
Yep, I ended up with the same understanding, as the one you mentioned. However, this might tend to be huge changes considering large applications that have numerous files.
Yep, this could also cascade across addons that generate tests, I believe? Although I don't have a concrete number of addons that currently generate test cases, if they do, they also need to update their blueprints. Few quick addons that I came across: |
I'm not sure if we should do it, while the code generated by blueprints is syntactically valid. Technically, apps may have some extra code style rules defined in their own eslint config or something. In this case blueprint output would also conflict with the certain project's codestyle. So in my opinion, this seems to be a pre-existing issue. I think this kind of issue may/should be solved via running(preferably automatically) a |
@ro0gr Let's say, we create a new ember app using |
@abhilashlr if ember-cli automatically runs |
We’ve been using Prettier for JS-files only on a green field codebase at work for about a year now and our experience has been overwhelmingly positive. I’m really excited about this RFC and support it whole-heartedly. Regarding Prettier and HBS templates — this is definitely still ongoing but great progress has been made. When we are collectively happy with Prettier’s handling of HBS templates then we can push for the Prettier team to mark HBS templates as officially supported. |
Ya, definitely a good call out here. The prose in the RFC under the header "Blueprint Changes" is intending to make it clear that all addon provided blueprints (including ember-source, ember-data, ember-cli owned ones) should be updated to satisfy the (new) default linting requirements. Here is a copy of that prose (for easier reference):
|
Ya, this is a good idea, thank you! While I still think blueprints should be updated to conform to the default app/addon blueprint linting requirements (most addons that own blueprint would consider it a bug to have their blueprints fail linting immediately upon generation), running |
I'm a big fan of this change. I'll generally add Prettier to a new app or addon anyway 😄 I mightn't agree with all of Prettier's formatting decisions but the fact that I don't have to think about it is a big win for me. We introduced Prettier on a large repo about 2 years ago and while the initial rollout was a bit bumpy as not everyone had their editors set up correctly, the developer feedback was overwhelmingly positive. At time we found that there was a ~60% reduction in lint errors on CI (~2K errors less to the previous month) as all stylistic lints were now being handled by Prettier. |
Big fan of this change. I've seen firsthand how much PR chatter and code churn is eliminated when everyone is on prettier. In addition, getting eslint + prettier working together can be a bit confusing at first, so getting it all set up as the default is helpful. I also agree with the sentiment here that prettier for hbs isn't quite ready to be the default. It's darn close, but there's at least two issues I know of that would be blockers for some people. |
|
||
The `.gitignore` will be updated to add `.eslintcache` so that when using | ||
`eslint --cache` the cache file itself won't be added to the repositories | ||
history. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't you want to share the cache with your teammates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thought of checking in a cache file gives me the heebie jeebies. I'm fine with just adding it to .gitignore
myself though if I'm alone in that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehulkar - This file would necessarily be changed by every commit that touches a .js
file. That would make it very prone to merge conflicts, and AFAICT (did a quick local test) eslint
doesn't automatically resolve these merge conflicts for you. Checking the file in would result in large amounts of pain, whereas not checking it in "just works" (and after that first linting run locally you get a nice speed boost).
We discussed this RFC at today's framework meeting and believe it's ready to merge. Thanks to everyone for the great conversation. I'm personally really looking forward to this change! |
rendered