-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow only formatting code snippets in markdown, not the markdown file itself #612
Comments
I'm not sure to understand, You can use https://github.com/mdx-js/eslint-mdx/tree/master/packages/eslint-plugin-mdx to enable linting markdown files via eslint already. |
With Flat Config, you can only enable Prettier to format on specific type, export default [
{
files: ['**/*.css'], // <-- this
plugins: {
prettier: pluginPrettier,
},
languageOptions: {
parser: parserPlain,
},
rules: {
'prettier/prettier': ['error', { parser: 'css' }],
},
}
] In my case I only want Prettier to take care all CSS in the pipeline but not Markdown itself. |
I don't think this is how prettier works. |
Prettier is a formatter that can even format a string in the memory, right? I don't see any reason I can't use Prettier to only format a selection of files (or virtual files). |
It can do it, but why it should do it? cc @BPScott |
I don't understand what we are even debating. Do you mean that the only way Prettier should work is to format all files? |
Yes. It should format the whole file, not all files, sorry.
I'd like to listen from @BPScott at the same time. |
Just for context, For Markdown Test
```css
.code { color: red }
```
The virtual file will be .code { color: red } Which from the plugin point of view, it's a single file not a part of the file.
From your words, I feel that currently this plugin is more like an "ESLint integration for Prettier, the opinionated formatting CLI Tools" over an "ESLint plugin using Prettier as the opinionated code formatter" -- Which is also fair, I'd respect that if you position it that way. "Opinionated" is an easy word to close the door I guess, where I see there might still be many interesting possibilities we could explore. |
I was referencing
That's why I said:
|
|
Code snippets linting by What means you can already achieve what you want already. |
Maybe you want https://github.com/ota-meshi/eslint-plugin-css In the feature, ESLint will not only focus on JavaScript ecosystem, it would be very easy to create a language plugin for ESLint, see aslo stylelint/stylelint#6593 |
I'm strongly opposed to adding new options that allow users to do customizations that diverge from the standard "configure prettier using the .prettierrc file" behaviour. The aim is that you should get identical output if you format a file through prettier's CLI or through eslint with Ideally
If I'm understanding this right, you've got a markdown file with a css fenced codeblock inside it, and you want to use ESLint to format the css fenced codeblock content using prettier (as prettier can handle non-js languages). At no point in this process are you trying to format javascript. ESLint concerns itself with formatting JS content, and with plugins like This feels tremendously complicated and like you're trying to push square pegs into round holes. I consider this to use-case to be very convoluted and not something I'd want to support. Prettier does not act in this way - it formats the whole file at a time - if you've got a markdown file with a js/css codeblock in it, then prettier will format both the markdown and the codeblock. There is no way to make it just format just the codeblocks within the markdown file while leaving the markdown content untouched. Because prettier does not act in this way I do not want eslint-plugin-prettier to act in this way either. If you want to format your markdown files I'd recommend running the whole markdown file through the prettier CLI (
This is a noble goal, and the ESLint team are working towards this in eslint/rfcs#99. However I do not feel that this plugin is the place to experiment with such work. I am grateful that you're proactive in coming up with solutions, however I would not merge #613, as I feel that what it is trying to do is directly opposed to the aims of this plugin (i.e. match eslint and prettier's behaviours). It tries to allow formatting of non-js content, which is not what ESLint is currently designed for, and it results in formating only a subset of a markdown file, which prettier does not support. Random aside:
FYI, this isn't a new feature, |
I am quite new to Prettier, I didn't know the "Opinionated" in Prettier expanded into so many aspects. Thanks for your time and detailed explanation, I think they make sense and you made them very clear. I guess Prettier might not be the "formatter" I am looking for, I'll use my fork for now and consider other alternatives. Thank you :) |
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 byeslint-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
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
: a333607Let me know if you have a better idea/naming. Thanks!
The text was updated successfully, but these errors were encountered: