I'm trying to run the Prettier CLI tool and what I wanted to do is running it against multiple files at once, is that possible?
I know we can use glob patterns but those files not be easily matched to a pattern. Because I'm trying to run the CLI tool against staged files in a pre-commit hook.
So I was hoping to do something like: prettier --write "file.js, src/file2.js, src/somepath/file2.js"
Is that possible?
From the directory you want to format, run Prettier with --write : prettier --write . This will format the entire directory recursively with Prettier.
To debug Prettier locally, you can either debug it in Node (recommended) or the browser. The easiest way to debug it in Node is to create a local test file with some example code you want formatted and either run it in an editor like VS Code or run it directly via ./bin/prettier. js <your_test_file> .
Benefits of using Prettier and ESLint As mentioned earlier, whereas Prettier takes care of your code formatting, ESLint takes care of your code style. The former does everything automatically for you. If you have set up Prettier, you can configure it to format your file on saving it.
You should be able to use curly brackets:
prettier --write "src/file{1,2}.js"
In your example:
prettier --write "{file1,src/file2,src/somepath/file2}.js"
It might be simpler just write out a list of files:
prettier --write -- file1.js src/file2.js src/somepath/file2.js
(--
is explained in https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With