Exclude Particular File Type From Prettier Auto Formatting

Last updated on 2 Aug, 2022

I am using Visual Studio Code to write this blog. I created a custom component to be used in React Interview Questions page. A problem which I faced was when using a markdown syntax inside a JSX component, the markdown is not getting rendered.

For that the solution is to put an extra line after and before the JSX component tags. But, Prettier automatically removes the extra line on saving the file. Then I looked for ways to prevent auto formatting only for .mdx files.

The solution is very easy. I had to add a .prettierignore file in my Gatsby project root. Then I added below content in that file.

*.mdx

The prettier plugin in Visual Studio Code respects that and will prevent auto formatting of .mdx files.