editor-config
How to use Prettier
- Install the config and prettier:
yarn add @sixfold/editor-config prettier -D
- Add the following line in the target service's package.json:
"prettier": "@sixfold/editor-config/prettier"
- Add the following scripts to your package.json
"prettier": "prettier \"./src/**/**\"",
"prettier:check": "yarn prettier --check",
"prettier:fix": "yarn prettier --write",
- Add a
.prettierignore
file at the source of the repository, containing at least the following:
package.json
.DS_Store
Make sure to include .prettierignore
in your docker (test) if you check prettier formatting as part of the tests.
- Configure your IDE to use
Prettier
:
- VS Code
- WebStorm (Should be installed by default, but you need to configure it.)
- Add
yarn prettier:check
as part of the test
or build
script to ensure that code is consistently formatted
Using prettier config with prettier APIs
When generating code programmatically, same configuration can be used to format generated output:
import * as prettier from 'prettier';
import * as prettierConfig from '@sixfold/editor-config';
const source = 'function main(){console.log("Hello")};main()';
console.log(prettier.format(source, prettierConfig));