By utilizing a tool, the whole team could have a consistent code formatting style.
Prettier is an opinionated code formatter with support for:
- JavaScript, including ES2017
- JSX
- Flow
- TypeScript
- CSS, Less, and SCSS
- JSON
- GraphQL
- Markdown, including GFM
- YAML
Download Visual Studio Code
and install this extension.
- Open
Extensions
- Search
Prettier - Code formatter
with publisher nameEsben Petersen
- Click
Install
npm install --save-dev --save-exact prettier
- Right click code area and select
Format Document
, or - Use shortcut
Ctrl + Alt + F
on Windows, or - Enable
format on save
# user manual: https://prettier.io/docs/en/cli.html
npx prettier ./test/format-me.ts --write
Settings will be read from (listed by priority):
- A Prettier configuration file, e.g: .prettierrc
- An EditorConfig file, e.g.: .editorconfig
We should use a .editorconfig
file together, as modern editors like Visual Studio Code could make use of it.