Prettier: Pros and Cons
(prettier author here)
I would encourage you to set the few flags that prettier has to match what your existing codebase uses and to run it through your codebase, do git diff and see how it behaves.
If it's not outputting code that's too crazy in your opinion, then don't use it :)
More on reddit.comIs using Prettier to format code bad.
Prettier removing camelCasing from css-in-js?
I've been wanting to use camelCase in my cssjs code too for some time.
I like react css convensions and I've used this for a while, and when I moved to jss (which is like emotion) I've used react conventions in my code as well using their library require('react/lib/CSSPropertyOperations');.
Hope it helps
More on reddit.com[AskJS] eslint or prettier or both with vim + ALE? Can I get rid of prettier or is it required?
Videos
One of my co-workers recently adopted Prettier, and at first I thought it sounded great. Automated formatting so you never have style complaints in PRs again? Sign me up.
But then I tried actually using it, and its ESLint plug-in, and was mildly horrified to discover that Prettier (through ESLint) was telling me to get rid of my trailing commas! It's not the 1990's anymore: trailing commas have been embraced throughout the JS community. Heck, even ESlint itself requires them by default.
Then I went and read the Prettier site, and it was basically full of quotes to the effect of "our team used to think about stuff, but thinking is hard, so now we use Prettier and just conform to whatever it wants, and now no one thinks anymore. Yay." And the rest of the site make site also makes it clear that Prettier is an opinionated library.
So, I was hoping to hear from people who have used Prettier and can share their experiences. Is banning trailing commas just one poor decision in an otherwise great library, or does adopting Prettier basically mean being shoehorned into whatever the Prettier people feel is best (even if they're wrong)?
To be fair, I know you can re-enable trailing commas with a flag. I'm just more worried about other "opinionated" calls the library might make that don't have flags (and which I might not discover until we've completely adopted Prettify).
(prettier author here)
I would encourage you to set the few flags that prettier has to match what your existing codebase uses and to run it through your codebase, do git diff and see how it behaves.
If it's not outputting code that's too crazy in your opinion, then don't use it :)
As I'm sure you've noticed, the JS world has endless disagreements about style:
-
Tabs vs. spaces
-
Semicolons vs. no semicolons
-
Trailing commas vs. no trailing commas
-
Single quote vs. double quote
I am sure you can think of many others. In each of these debates, each side has has compelling arguments with different trade-offs. After all, if there was an obvious "best way", we wouldn't even be having these debates.
The prettier project has identified a handful of these issues that are deal-breakers for some people, and have made those configurable. Specifically, they let you adjust indentation, quotes, semicolons, trailing commas, and bracket spacing. These are the hot-button issues that nobody can agree on, and you are encouraged to configure them as you like. Prettier has some default settings that reflect what's popular right now, but those defaults aren't binding. Just change them and be happy.
Where prettier really shines is in breaking long statements over multiple lines. Before I adopted prettier, I would use a whole bunch of different styles without even realizing it. For example, I would do things like:
somethingReallyLong(parameterOne, parameterTwo,
someCall (
longParameter,
anotherLongParameter
))
It's not really clear what the "right" way to format this statement would be, and there are multiple valid approaches. With prettier, however, I know that I will always get the following:
somethingReallyLong(
parameterOne,
parameterTwo,
someCall(longParameter, anotherLongParameter)
)
It's self-consistent, and it looks good. More importantly, I don't waste any brain cycles thinking about line breaking anymore. I just write the statement in one long line, and when I'm done, I hit the "format document" shortcut to make everything flow. Whenever I collaborate with a coworker, I am always amazed how much time they spend formatting code. Copy-paste, re-indent, fix brackets, adjust long lines, rinse, and repeat. With prettier, all this monkey work is a thing of the past. For that, I am willing to pay the price of a few minor style quibbles (everything else I have configured to taste).
» npm install prettier
Recently joined a agency as an Contract React developer. I was assigned a task to edit some inline Scss code.
Being a Prettier user I formatted the code, made the necessary changes and submitted a pull request.
Next day the senior developer reviewed my code and asked me to stop using Prettier and assigned me a task to change back the Scss code manually to inline Scss.
When I asked why should I not use prettier to format code. He said it's bad and time consuming and other team members started telling me a story how one time prettier wasn't working and started throwing errors.
That's why they never use it.
I wanted to say that It was showing error because you were doing something wrong.
Just because you once had an bad experience doesn't mean it's bad.
Plus they use one big single Scss file for the whole project.
When I question it too and asked them to use separate files and how it can effect the performance.
One team member answered it doesn't matter, how they don't care about the performance and I should be open minded and learn from them. The boss has 18 years of experience.
What should I learn why not to follow good practices!