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.
How to stop VSCode/prettier to stop formatting these to the same line on save?
"Prettier Ignore" entire File?
Support prettier-ignore-start/end for other languages (not only Markdown)
`prettier-ignore-start` and `prettier-ignore-end` is ignored on html
Videos
Sometimes multiple statements can be wrapped in a block with // prettier-ignore in front of it:
// prettier-ignore
{
abcRouter('/api/abc', server);
xRouter ('/api/x', server);
}
Of course, that doesn't make sense for block-level const declarations, but you wrote that was not your actual code and just an example. So that's a solution that works in some but not in all cases. Overall, the strategy is to wrap multiple things in one thing that can be prettier-ignored.
Another option is to move all the code you don't want to format (e.g., because it's generated) to a separate file excluded by .prettierignore.
prettier-ignore-start and prettier-ignore-end are supported only in Markdown.
You can ignore a code block is not supported at the moment, your option is is to only use // prettier-ignore
example below:
// prettier-ignore
const a = 'a';
const b = 'b';
// prettier-ignore
function xyz() {
console.log({a, b})
}
known issue -> https://github.com/prettier/prettier/issues/5287
Docs -> https://prettier.io/docs/en/ignore.html#javascript
» npm install prettier-ignore