Search code examples
javascriptglobprettier

Exclude a folder from glob pattern matching


Using Prettier to format js code. Prettier seems to be using globby under the hood.

I tried the following:

$ prettier './**/*.{js, css}' '!assets/**'
$ prettier './**/*.{js, css}' '!(assets/**)'
$ prettier './**/*.{js, css}' '!assets/**/*.*'
$ prettier './**/*.{js, css}' '!(assets/**/*.*)'
$ prettier './**/*.{js, css}' 'assets/**/!*.*'

And in all cases, files in the assets folder were included.

What's the correct way to do this ?


Solution

  • Here's the PR where that was merged. Here's the syntax. Here's what I have working in my package.json:

    
    "prettier-fix": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss}\" \"!\\.next/**\""
    

    Lint all matching except .next directory. Note the quotes.