Skip to content

Instantly share code, notes, and snippets.

@Mohamed3on
Last active January 7, 2025 03:23
Show Gist options
  • Select an option

  • Save Mohamed3on/840b34ecb7e9abf06ace035183b7f1fc to your computer and use it in GitHub Desktop.

Select an option

Save Mohamed3on/840b34ecb7e9abf06ace035183b7f1fc to your computer and use it in GitHub Desktop.
Run prettier on all JS files in a directory
  1. Install prettier
  2. Make a .prettierignore file, and add directories you'd like prettier to not format, for example: **/node_modules
  3. Run prettier --write "**/*.js" *Don't forget the quotes.
  4. Optional: if you want to format JSON/SCSS files too, replace js with json/scss.
@Haugen

Haugen commented Oct 27, 2018

Copy link
Copy Markdown

Thanks for an easy and straightforward solution. My only suggestion would be to mention that you can add options, and maybe link to https://prettier.io/docs/en/options.html.

@tuanluu-agilityio

Copy link
Copy Markdown
 *Don't forget the quotes.

It saves my life πŸ‘

Thanks

@ameernormie

Copy link
Copy Markdown
 *Don't forget the quotes.

It saves my life πŸ‘

Thanks

Thanks. That's what I was missing. πŸ‘ŒπŸ»

@melroy89

melroy89 commented Nov 16, 2021

Copy link
Copy Markdown

I'm using: prettier --write "src/**/*.js"

Or within the package.json file, within the "scripts" section:

    "pretty": "prettier --write \"src/**/*.js\""

@ankurparihar

ankurparihar commented Feb 5, 2022

Copy link
Copy Markdown

For multiple file formats

prettier --write "**/*.{css,js,json}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment