DEV Community

How to properly set up Prettier in less than 2 minutes

Boris on June 20, 2022

My step-by step guide to set up Prettier in any project, and integrate it with ESLint and Git Hooks I’ve been using Prettier for mor...
Collapse
 
slidenerd profile image
slidenerd • • Edited

Would you like to hear a one line command that literally does half the things in your article :) ?

npx mrm lint-staged

Run this, it ll install husky, modify package.json to add husky folder, create the pre-commit file with lint-staged, install lint-staged, create package.json lint-staged...with all their related dependencies and more
yes sir you read that right

Collapse
 
willytjandra profile image
Willy Tjandra •

In addition, you can also enable format on save in vscode, which will run prettier to format your code.

I prefer this before developer commit their code.

Collapse
 
bokub profile image
Boris •

If you're developing an open-source product for example, you cannot force every contributor to use vscode and configure it exactly like you expect !

Collapse
 
patoi profile image
István Pató •

lint-staged with husky gives ultimate power to manage your code

Collapse
 
tagvi profile image
Otar Natsvaladze •

You can also use yarn dlx instead of npx.

Collapse
 
snowlyg profile image
snowlyg •

what's the npx commad?

Collapse
 
bokub profile image
Boris •

npx is a tool which comes with Node.js & npm

By default, when you run npx <command>, npx will check whether <command> exists in $PATH, or in the local project binaries, and execute that. If <command> is not found, it will be installed prior to execution.

Collapse
 
andrewbaisden profile image
Andrew Baisden •
Collapse
 
harithzainudin profile image
Muhammad Harith Zainudin •

Thank you for sharing! Will try and use this for my next project!

Collapse
 
plabankr profile image
Plaban Kumar Mondal •

Can you add commands for pnpm also?

Collapse
 
bokub profile image
Boris •

Sorry, I've never used it, but if you manage to find working commands, please post them in a comment and I'll add them to the guide!