Wenfang Du
Wenfang Du

Reputation: 11337

Prettier - How to ignore certain file types in CLI file patterns?

I want to exclude only js, jsx, and vue files, I imagine something like:

prettier --check --write --ignore-unknown "**/*.{!js,jsx,vue}"

Upvotes: 4

Views: 5171

Answers (1)

thorn0
thorn0

Reputation: 10397

As it's said in the Prettier CLI docs, Prettier uses fast-glob (which in turn uses micromatch) to resolve glob patterns. If you follow the links, you'll find multiple ways to achieve what you need.

You can use negative patterns:

prettier --write --ignore-unknown '**' '!**/*.{js,jsx,vue}'

or

prettier --write . '!**/*.{js,jsx,vue}'

or you can use a syntax called extglob:

prettier --write --ignore-unknown '**/*.!(js|jsx|vue)'

There might be other solutions. fast-glob supports a lot of different things.


BTW, using --write and --check at the same time isn't a supported use case. Whatever it does, don't rely on that, and choose one of the two instead, depending on what you want the command to do:

  • --write to format files
  • --check to check if files are formatted (commonly used on CI)

Upvotes: 9

Related Questions