npm install --save-dev --save-exact prettier
npm install pretty-quick husky --save-dev
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
If you describe someone as opinionated, you mean that they have very strong opinions and refuse to accept that they may be wrong. - COBUILD Advanced English Dictionary
Synonyms: dogmatic, prejudiced, biased, arrogant
Runs Prettier on your changed files.
Git hooks made easy
In package.json append:
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged --verbose \"src/**/*.tsx?\""
}
Create file .prettierrc.js at the root
module.exports = {
useTabs: false, // Indent lines with tabs instead of spaces.
singleQuote: true, // Use single quotes instead of double quotes.
/**
* Print trailing commas wherever possible.
* Valid options:
* - "none" - no trailing commas
* - "es5" - trailing commas where valid in ES5 (objects, arrays...)
* - "all" - trailing commas wherever possible (function arguments)
*/
trailingComma: 'es5',
parser: 'typescript',
<ruleName>: <Value>,
}
Create .prettierignore file at the root
*.map
package.json
tsconfig.json
tslint.json
tsconfig.*.json
package-lock.json