I want to run prettier on every single file in my project, is there a way I can set it up to do so?
There isn't a way in this extension to do that, but from the CLI you can just do:
prettier --write "**/*.js"
perfect, thank you!
Regarding the prettier CLI more than this extension, but what about CSS, JSON, Markdown, GraphQL, etc. etc. ? Ideally there would be a way format everything without having to maintain a list of extensions that may grow over time as Prettier updates. I just got no results googling for a glob that includes all currently supported file extensions.
We'll probably do that in prettier v2. https://github.com/prettier/prettier/issues/3503
@jaydenseric actually I just released a CLI tool to help with setting prettier up on new/legacy codebases. It also has a command formatAll which extracts all supported extensions right from the local prettier and formats all code except node_modules.
Any feedback greatly appreciated.
@capaj thats a handy looking project, although I think I'll wait for such functionality to be shipped in Prettier v2.
You guys should add @azz comment to CLI help. Its really not clear how to run it. ( especially if you tell people to run it as part of the check flag)
"prettier --print-width 80 --no-semi --single-quote --trailing-comma es5 --write src/**/*.js"
You can change/add more optional stuff.
"prettier --print-width 80 --no-semi --single-quote --trailing-comma es5 --write src/**/*.js"
You can change/add more optional stuff.
@idanlevi1 I think you messed up the quotes. the path part after --write should be in quotes and command shouldn't start with a quote as first char. I just ran into an issue where putting the path in quotes fixed it so it does matter...
"prettier --print-width 80 --no-semi --single-quote --trailing-comma es5 --write src/**/*.js"
You can change/add more optional stuff.@idanlevi1 I think you messed up the quotes. the path part after --write should be in quotes and command shouldn't start with a quote as first char. I just ran into an issue where putting the path in quotes fixed it so it does matter...
I copy that from my scripts so the quotes it's ok... and about the path, i think it no matters, for me its work well.
There isn't a way in this extension to do that, but from the CLI you can just do:
prettier --write "**/*.js"
In case you would like to match multiple file extensions in one run:
prettier --write '**/*.{ts,js,css,html}'
You could also add this to your projects package.json under scripts to simply run npm run prettier to format your code before committing it:
{
...
"scripts": {
"prettier": "prettier --write '**/*.{ts,js,css,html}'"
}
...
}
` "prettier": "prettier --write '*/.{ts,js,css,html}'"
If you're using windows, remove the single quotes:
` "prettier": "prettier --write */.{ts,js,css,html}"
You should do this anyway to be friends with your Windows devs friends
@4dams yeah no worries that there is like 40 other file types that prettier can format and those files stay not formatted after you run this command.
@capaj This was just an example, duh. You can of course add any other file extension you'd like, I just used these because I don't want prettier to take even longer formatting other file types I don't really use.
If you don't want to keep a record of all the extensions in the CLI, consider using:
prettier --write "./**/*.*"
The extensions which needs to ignored can also be added in .prettierignore or .eslintignore, etc.
prettier --write "./**/*.*" --ignore-path path/to/prettier-ignore
A combination of find and xargs worked for me
find . -name "*" | xargs prettier --write
If you are on a git repo
git ls-files | xargs prettier --write
Ref: How to run Prettier (or any other command) on all files in a directory
There isn't a way in this extension to do that, but from the CLI you can just do:
prettier --write "**/*.js"
works like a charm! THX
Had to prepend npx
npx prettier --write "**/*.js"
npx prettier --write "**/*.js"
Will this command respect .prettierrc that exists in the project's root?
@AndrewBogdanovTSS you can use --config options like prettier --config /path/to/.prettierrc --write '**/.*.{ts,tsx,js,jsx,html,css,less}'
I found out that it's respected by default
From the CLI - Prettier Documentation, I found this:
prettier --write .
This command formats all files supported by Prettier in the current directory and its subdirectories.
Most helpful comment
There isn't a way in this extension to do that, but from the CLI you can just do: