Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking multiple files at one using prettier

Tags:

prettier

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?

like image 491
thitemple Avatar asked Mar 11 '19 14:03

thitemple


People also ask

How do I run Prettier for all files?

From the directory you want to format, run Prettier with --write : prettier --write . This will format the entire directory recursively with Prettier.

How do you debug 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> .

Do I need ESLint with Prettier?

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.


1 Answers

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)

like image 131
AnC Avatar answered Sep 30 '22 07:09

AnC