Setting up Prettier and EditorConfig
Prettier is a code formatter that works with a lot of different source files. Among the supported file types, we have plain JavaScript, Flow, TypeScript, HTML, CSS, SASS, Markdown, and many more. Prettier is also integrated into many different editors such as Atom, Emacs, Sublime Text, Vim, Visual Studio, or VS Code.
Let’s dig into installing and configuring the Prettier formatter:
- Such as the previous tools, Prettier can be installed locally or globally. Adding Prettier to an existing project can be done by installing the
prettier
package from the npm registry:$ npm install prettier --save-dev
- Prettier can format JavaScript code even without any configuration. To run Prettier on an existing code file, you can use the
prettier
utility withnpx
. For instance, to apply formatting to your previous code file, you can run:$ npx prettier index.js
export function div(a, b) {
return a / b;
}
In this case, Prettier just...