0

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

prettier --check --write --ignore-unknown "**/*.{!js,jsx,vue}"
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90

1 Answers1

6

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)
thorn0
  • 9,362
  • 3
  • 68
  • 96
  • Thanks, that was very informative. What if I want to check if files are formatted, if not, `--write` them? I suppose `--write` just writes everything without checking. Using `--write` with `--check` outputs a short message, whereas just `--write` will output everything that's been formatted, which is not what I wanted. – Wenfang Du Feb 24 '21 at 00:40
  • 1
    Apparently it works that way, but it's not documented. – thorn0 Feb 24 '21 at 01:03