Jakub notes • engineering

Prettier

An opinionated code formatter.
https://prettier.io

Options

Prettier helps to keep code-style consistent and stop debates over styles. Having options goes against it, so default values for options are considered as recommended.
https://prettier.io/docs/en/option-philosophy.html

Unless there is a reason to change default values,.prettierrc is not needed.

Recommendation

My only preferred option is singleQuote. Double quotes are easier for English heavy text with a lot of apostrophes ', so "I'm fine, thanks" doesn't require any escaping. On the other hand, JavaScript is full of strings and imports. Writing double quotes require pressing key shift.

singleQuote: true

ESlint

Prettier can run separately, but the most common is to run as a part of Linter.
Install prettier, eslint-config-prettier, and eslint-plugin-prettier.

eslint-config-prettier

It turns off rules that might conflict with Prettier. It keeps code-quality rules for ESlint, but code-style rules are based on Prettier config.

extends:
  - prettier

eslint-plugin-prettier

The plugin runs Prettier as ESlint rule and reports the issues that are auto-fixable eslint --fix.

plugins:
  - prettier
rules:
  - prettier/prettier: error

When formatting a large codebase for the first time, try temporarily disabling the prettier/prettier rule and run eslint --fix and prettier --write separately.