My Prettier configuration.
Install @danielgiljam/prettierrc and prettier.
npm i @danielgiljam/prettierrc prettier@^2.3.1
Create a file called .prettierrc.js
.
touch .prettierrc.js
Export @danielgiljam/prettierrc from .prettierrc.js
.
const prettierrc = require("@danielgiljam/prettierrc")
module.exports = prettierrc
The recommended way to use @danielgiljam/prettierrc is together with @danielgiljam/eslint-config and ESLint.
ESLint catches/fixes potential bugs and problems and Prettier reprints the code to ensure the format is right and the style is consistent.
You can implement these tools into your development workflow however you like. However, my personal favorite ways of implementing them are the following:
- Modify your
package.json
to include the following NPM scripts:{ "scripts": { "fix": "eslint --fix .", "format": "prettier --write .", "ff": "npm run fix && npm run format" } }
- Typing
npm run ff
in your terminal then applies @danielgiljam/eslint-config and @danielgiljam/prettierrc to your source code.
- Install the following extensions:
- Make the following changes to your settings:
{ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": false, "editor.codeActionsOnSave": [ "source.fixAll.eslint", "source.fixAll.format" ] }
- Now when you save a file, it will first be fixed and then formatted in place.
View changelog.