-
-
Notifications
You must be signed in to change notification settings - Fork 206
Description
What version of eslint
are you using?
8.55.0
What version of prettier
are you using?
3.1.0
What version of eslint-plugin-prettier
are you using?
5.0.1
Please paste any applicable config files that you're using (e.g. .prettierrc
or .eslintrc
files)
https://stackblitz.com/edit/node-mhr6sb?file=README.md,eslint.config.js
What source code are you linting?
See the Stackblitz link above
What did you expect to happen?
With fine-grained files
option in the flat config, Prettier should be able to format virtual files created by eslint-plugin-markdown
to format the code snippet in Markdown.
What actually happened?
There is a hard-coded logic to ignore any virtual file created in markdown as well as a few other extensions:
eslint-plugin-prettier/worker.js
Lines 129 to 152 in 1882a36
} else { | |
// Similar to https://github.com/prettier/stylelint-prettier/pull/22 | |
// In all of the following cases ESLint extracts a part of a file to | |
// be formatted and there exists a prettier parser for the whole file. | |
// If you're interested in prettier you'll want a fully formatted file so | |
// you're about to run prettier over the whole file anyway. | |
// Therefore running prettier over just the style section is wasteful, so | |
// skip it. | |
const parserBlocklist = [ | |
'babel', | |
'babylon', | |
'flow', | |
'typescript', | |
'vue', | |
'markdown', | |
'html', | |
'mdx', | |
'angular', | |
'svelte', | |
]; | |
if (parserBlocklist.includes(/** @type {string} */ (inferredParser))) { | |
return; | |
} | |
} |
I consider it a valid default as it might cause nested formatting when users enable eslint-plugin-prettier
to all files.
But with the new Flat Config, you are able to only enable certain rules with certain options for specific types of files. In the case where we don't config Prettier to format the parent markdown, treating the virtual files as normal formattable code should be allowed.
Proposed solutions
I imagine we could introduce a flag to opt-out of this hard-coded logic, and give the control of ignoring a file to users.
I made a simple implantation, adding a new config called fullControl
: a333607
Let me know if you have a better idea/naming. Thanks!