Thoughts about using prettier
See original GitHub issueMany of us have been using prettier for a while now and have found it wonderful for formatting code.
Prettier obviously doesn’t replace most of the lint rules in Airbnb’s style guide (c.f. #1307), but it can definitely compliment it by freeing up a developer to not have to worry about code style (where should line breaks happen, how much should this be indented) and instead worry about more important things (like not using for-of
#1122). The prettier website has a bunch of other people’s reasons why they like prettier.
Obviously people can use prettier with Airbnb’s style guide currently (as many of us have been), but I was wondering if Airbnb had considered making this the default.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11
Top Results From Across the Web
Pros, Cons, Tips and Tricks when using Prettier in a large ...
When collaborating on code, tools like Prettier can be incredibly useful for productivity. They free developers from having to format their code ...
Read more >Why the Prettier Code Formatter is a Big Deal
Prettier is a big deal (as is any other robust code formatter for that matter). This article will showcase why it is so...
Read more >Why aren't you using Prettier? - Hexacta Engineering
The more you use Prettier the less you are distracted about formatting. You may not realize how good this feels until you experience...
Read more >I don't like prettier : r/javascript - Reddit
Typing speed is not an issue for me, I spend more time thinking about the problem then typing and formatting my code. I...
Read more >Why I Recommend Using Prettier on Front End Projects
Code faster without having to think about formatting. Prettier lets me get really sloppy while typing out my thoughts. I don't have to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the quick reply. Unfortunately this reply is not nearly so short 😢
Instead I’m simply recommending extending
eslint-plugin-prettier
and either manually disabling all the rules which conflict (or by using the list fromeslint-config-prettier
but I’m guessing you’d prefer to be explicit rather than depending on another list).object-shorthand
ordot-notation
, we could let you worry about that for us.We’ve been using Airbnb’s style guide with
eslint-plugin-prettier
andeslint-config-prettier
for a couple of months now on a few hundred thousands of code in our codebase and have found it to be a very similar experience of freeing the mind to worry about more important things. It’s hard to describe, but not needing to worry about whitespace (which is really all prettier does) has allowed me to concentrate better on the actual code that I’m writing. I’d highly encourage you to try it. Many in the company were highly dubious at first but were quickly won over.eslint-plugin-prettier
does exactly that. You can simply consider prettier as a souped up indentation and line break lint rule (it does a couple of extra things with parens).That said, that’s a bit of a cheats argument and I’m guessing not what you were after.
The indentation rule in ESLint has gone through massive rewrites in ESLint 4. That said, it still won’t say that
This is the trivial example often cited, but it goes much further, how do you break up ternaries on multiple lines, how do you indent arrow functions in big promise chains, etc. With prettier I don’t need to remember, I just hit save and it reformats it in a way that looks pretty good.
I used to think that developers should worry about all aspects of code style, but having tried prettier for a few months now I’m glad to now have to worry about it.
The only two options you’d need for prettier are
--single-quote
and--trailing-comma all
.It’s hard for me to know exactly what is different between using prettier to manage “style” and airbnb’s rules. One way to see the differences would be to study the source code of
eslint-config-prettier
.Another way (what I’ve done below) is see the practical differences we have on our codebase between the two. Please note that we don’t use JSX and so I can’t speak of any differences there.
Running prettier over our codebase for the first time reformatted a lot of whitespace changes that Airbnb’s style guide didn’t enforce. As for actual differences (as in places where the two disagree), the main one we found in our codebase (by number of lines) is:
That said, 7.1 of the airbnb style guide forbids function declarations like this, we just haven’t cleaned all of ours up yet 😰.
As for the actual differences, these are all that I have found:
One more that I will add is that is seems that using
eslint-config-prettier
means that the following seems to be enforced. I haven’t worked out exactly where that’s coming from as it’s not prettier as you can see from the playgroundSo to summarise, the conflicts between the two style guides all seem very minor and I do think that adding prettier as an ESLint rule would actually work really well as part of Airbnb’s style guide. That said, it’s not my guide, so all I can do is ask you to consider it.
@ljharb is that feasible with the current eslint autofix primitives? See eg this comment from the eslint repo owner.
Given the core functionality of prettier - line length - I’m not sure that any eslint fix could be made in a form other than “run prettier and use it as an eslint rule”, which is what eslint-plugin-prettier accomplishes.
It might be worth your time to experiment with the tool; I think you may find it interesting.
Perhaps Airbnb could fork prettier, and align its output with your own style. I imagine it would be popular.