Home > Back-end >  Prettier format all subfolders
Prettier format all subfolders

Time:11-22

Im trying to use the https://github.com/trivago/prettier-plugin-sort-imports lib which on the root diercotry but not in my subdirectories.

This is my project structure:

---TheAPP
  | subfolder1
     package.json
  | subfolder2
     package.json
package.json

The library works on the root but not the subfolders. This is added to my package.json in the root:

scripts: {"prettier": "prettier --write \"**/*.{js,ts,tsx}\""},

How do i target the subfolder? Is the problem that each subfolder has its own package.json so i need to install the library to each subfolders package.json?

CodePudding user response:

I guess this answers your question..... definitely, you will have to install the library to each subfolder.

How does import sort work? The plugin extracts the imports which are defined in importOrder. These imports are considered as local imports. The imports which are not part of the importOrder is considered as third party imports. https://github.com/trivago/prettier-plugin-sort-imports

CodePudding user response:

The path is not right, you should go in subfolder `./**/*.{js,ts,tsx}

Try this command:


"prettier": "prettier --write \"./**/*.{js,ts,tsx}\"",
  • Related