- Indentation & alignment
Mimic Golang's gofmt
behavior: tabs are used for indentation, spaces are used for alignment.
- Line width
Use 120 rather than 80 for modern PC monitors.
Note that this is not a hard strict, prettier
may allow some lines to exceed this limit as breaking such lines is weird.
- Typing with ease
Prefer no semicolons, single quotes, and no spaces between brackets in object literals, to ease the typing.
Why? prettier
is a modern tool, and
it can automatically add semicolons when necessary,
so it is safe to omit the semicolons except for a few lines.
Moreover, note that prettier
may still use double quotes if the string contains more single quotes than double quotes.
- Consistency
Styles of neighboring code should be consistent, such as consistent property quoting for a literal object, trailing commas for multi-line code, brackets for multi-line JSX code.
- First, install this package as a development dependency. Note this package will not install
prettier
itself automatically.
npm i -D @chipzhang/prettier-config
-
Then, use one of the configuration types supported, for example
-
Add
{"prettier": "@chipzhang/prettier-config"}
to yourpackage.json
file. -
Add a JSON file
.prettierrc
, or.prettierrc.json
with content"@chipzhang/prettier-config"
. -
Add a JS file
.prettierrc.js
, orprettier.config.js
, with contentmodule.exports = '@chipzhang/prettier-config'
, ormodule.exports = require('@chipzhang/prettier-config')
.
-
-
If you are using JS configuration file, you can add your custom settings like
module.exports = {
...require('@chipzhang/prettier-config'),
mySetting: 'value',
}
GNU AFFERO GENERAL PUBLIC LICENSE Version 3