directory-structureprettierprettier-vscode

How to configure Prettier to only format files with specific extensions within a set of folders


I'm configuring Prettier in my React project and I'm having difficulties with the .prettierignore file.

I'm passing the following instruction to it:

/*
!src/**/*.{ts,tsx}

The idea was to make Prettier ignore all files and folders and then have it format only the .ts and .tsx files inside the src folder and its subfolders.

Here is a screenshot of my current structure: folders

I did a search on the forums but I didn't find a similar use case. Thanks for your time and your answers.


Solution

  • .prettierignore files work the same as .gitignore. For more information: have a look.

    The way (!src/**/*.{ts,tsx}) that you used is a Prettier-specific usage.

    Finally, the actual rule and its exception must be compatible with each other. Logically, they should address a common goal.

    Solution:

    /**/*.*
    !src/**/*.ts
    !src/**/*.tsx