Search code examples
javascriptnode.jsjslintpackage.jsonprettier

How to use files with multiple extensions with Prettier?


I have following Prettier commands:

prettier --parser typescript --write ./src/**/*.ts
prettier --parser typescript --write ./src/**/*.tsx

I would like to merge them to single one - use some king of regex to listen (write) on both .ts and also .tsx extensions.

Something like:

prettier --write ./src/**/*.ts(x?)

Solution

  • Just found solution. Following command will target both ts and tsx:

    prettier --write "./src/**/*.{ts,tsx}"
    

    Prettier is using Glob syntax which is syntax similar to Regex, used in shell.

    See GLOB syntax details: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer