I'm currently using Prettier for my projects on Visual Studio Code. Whenever I save, it formats. However, I recently wanted to ignore a specific file from formatting, so I did some research and found out about the .prettierignore
file. But for some reason, it didn't work for me. I used the commands in the Terminal to debug the issue, and it seems like the Format on Save feature is ignoring or overriding this file.
I'm trying to ignore src/main.tsx
, below I can see that it works from Prettiers side:
PS C:\Users\X> npx prettier --debug-check src/main.tsx
PS C:\Users\X> npx prettier --debug-check src/main.css
src\main.css
Can I somehow make it check for a .prettierignore
file before formatting?
After encountering this issue and investigating further, I discovered that the problem was related to my workspace setup, which included multiple projects. Here was my folder structure:
| ctx-frontend
--| .prettierrc
--| .prettierignore
| ctx-backend
--| .prettierrc
The key issue was that I had opened Visual Studio Code at the root directory that contained both the ctx-frontend
and ctx-backend
folders. This configuration probably confused VSC when it came to determining which .prettierignore
file to respect, as each project had its own Prettier configuration.
Solution:
To resolve this issue, I needed to open the ctx-frontend
project directly in Visual Studio Code rather than the root directory. Doing this ensured that VS Code correctly identified and utilized the .prettierignore
file for that specific project.