Prettier is an opinionated code formatter that automatically makes code more consistent and readable. It breaks up long lines and applies formatting rules, replacing manual cleanup and team debates with a shared default. section 1.3.2 section 2.3
Add Prettier to a project and run it from the command line:
- Install it as a development dependency, then create an empty .prettierrc file to keep configuration project-local and signal that Prettier is enabled. section 2.3.1
- Run npx prettier --write . to format project files. Use .prettierignore to exclude files such as package-lock.json. section 2.3.1
Listing 2.13 A Prettier-formatted JavaScript module
const generateNinjaTurtleAction = () => {
const randomNumber = Math.random();
if (randomNumber < 0.1) {
return "Fight Shredder";
} else if (randomNumber < 0.5) {
return "Rescue April";
} else {
return "Eat pizza";
}
};
A messy JavaScript module becomes consistently indented, spaced, and punctuated after formatting. section 2.3.1

