In this section, we are going to install another extension in Visual Studio Code, called Prettier, which will automatically format our code. As well as putting a stop to all the ongoing debates over styles, it will help us adhere to some of the TSLint rules:
- Let's open Visual Studio Code, go to the Extensions area, and type prettier in the search box. The extension is called Prettier - Code formatter and was published by Esben Petersen:
- We need to click the Install option to install the extension.
- After it has been installed, we'll need to reload Visual Studio Code for the extension to become enabled.
- The last step is to make sure the Format on Save option is ticked in User Settings. Press Ctrl +, (comma) to open the settings screen and type Format On Save in the search box to find the setting. If the setting isn't ticked, then tick it:
Now that this extension is installed, when we save our TypeScript code, it will automatically be formatted nicely for us.