How do you Prettier on save in Visual Studio 2019? You use Mads Kristensen's extension, JavaScript Prettier. It lets you set it to run on save, which you absolutely must do. It's an 100% godsend.

"But Mads' extension only runs Prettier 1.12.1 if another Prettier isn't installed locally in my project!" I hear you say. "That doesn't put in the extra space between function and () in anonymous declarations! I can't use it!" you complain.

Well, thanks to your resident hacker (maybe not my best separation of concerns, but it works), that's not a problem any more. Open Tools >>> settings, choose Prettier, type in the version you want to use. Poof. The embedded version is the version you entered and you're Prettier-ing.

Why did I bother updating a Prettier extension for Visual Studio? With my current team, I'm the only dev using, um, modern client-side tooling (mostly VS Code). Most folks are using Visual Studio 2019. That's fine. I love VS2019 for C# work. I can see how familiarity sometimes breeds not contempt but content. -Edness. Or something. But we need to use Prettier as a team. The tool's that good. So update it is!

You're welcome. ;^) 

Btw, I really owe Rackis a whiskey of his choice for this one. Being OCD about whitespace myself, I complained at first (okay, I complained like a cat getting a bath) when he told me years ago that I had to use a tool that automatically "corrected" whitespace for me, reformatting the entire file without apology, before I could check in my code. What the heck?! I know how to format code to make it easiest to read and understand. How dare a tool mess with my art?!!?

Then, very quickly, I dropped the pretense and became addicted. 

In a team using Prettier, I never got a file with craptastic whitespace from another coder. 

And, more important selfishly, I found I never wasted another moment making sure the whitespace for my code was perfect.

Get lazy, type some code, hit save, WHAM, competent whitespace is inserted for you. It's instant. It's mindless. It's magical.

Anything that makes coding easier and standardizes something subjective in a way that's Not Wrong is a very good thing. You should use it. Now. You can thank me later for the recommendation... and the extension, if you're still a Visual Studio 2019 addict.

Labels: , , ,