Issue #63 (Format on Save & Prettier)07/05/23
If you're accustomed to working with VS Code's
Format On Save option, there's a related option you'll want to be familiar with as well, especially if you work on a lot of large, inherited projects. But first a quick review of Format on Save.
Format on Save allows you to auto-format any file you're working in whenever you save the document. You can enable the feature by searching for "Format On Save" in your settings:
You'll see three settings, one for the editor, one for enabling in notebooks, and another I'll describe below. In order for this setting to work, you have to enable some type of formatter for the language you're working in.
Look up "Formatter" in your settings and from there you can specify a default formatter. VS Code includes some built-in formatters, but likely you'll want to choose your own. Prettier is a popular option that many of you are probably already using.
Once that's enabled, saving a document will format the whole thing according to the rules of your formatter. It's generally recommended to specify different formatters for different languages, which you can do in VS Code's JSON settings. Below I've set Prettier as the default formatter for JavaScript, with no default formatter in general.
As I mentioned at the beginning, the related option is
Format On Save Mode, which allows you to specify whether Format On Save applies to the entire file or only the modifications made.
The latter value is
useful if you're working on a big file that's inherited or it's another project that you don't own or generally work on, but you're just contributing. This way you can avoid the team needing to review a large pull request that's mostly just formatting corrections that weren't requested in the first place.
Now on to this week's hand-picked links!