Skip to content
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

[bug] blocks will be reset on preprocess every time and will break .md in .md #181

Closed
JounQin opened this issue Mar 18, 2021 · 5 comments · Fixed by #183
Closed

[bug] blocks will be reset on preprocess every time and will break .md in .md #181

JounQin opened this issue Mar 18, 2021 · 5 comments · Fixed by #183

Comments

@JounQin
Copy link
Contributor

JounQin commented Mar 18, 2021

The will not work when writing markdown codes in code blocks.

Lifecycle:

preprocess('.md') -> preprocess('.md/0_0.md') -> postprocess('.md/0_0.md') -> postprocess('.md')

This was not a problem before because .md files are not linted by eslint before. By adding esling-plugin-mdx which support .md files, it will be a problem.

Originally posted by @JounQin in #178 (comment)


@btmills

It's clear to be an bug

https://github.com/eslint/eslint-plugin-markdown/blob/main/lib/processor.js#L219

@btmills
Copy link
Member

btmills commented Mar 18, 2021

Thanks for opening this so we can dig in. I think I follow what you're saying, but to be sure, can you provide an example Markdown document that triggers the bug?

@btmills btmills added this to Needs Triage in Triage via automation Mar 18, 2021
@btmills btmills moved this from Needs Triage to Triaging in Triage Mar 18, 2021
@JounQin
Copy link
Contributor Author

JounQin commented Mar 18, 2021

@btmills

This issue will only occur when integrating with other plugins like eslint-plugin-mdx which will lint original .md files by preprocess too.

Here is the fake version for testing.

https://github.com/eslint/eslint-plugin-markdown/pull/183/files#diff-83e0a2056017ee834945f51308072e4a883a4ed96193581fe4aabc41cb98710a

@JounQin
Copy link
Contributor Author

JounQin commented Mar 18, 2021

So maybe I shouldn't flag it as bug but a better compatibility with other markdown related ESLint plugins based on eslint-plugin-markdown.

@btmills
Copy link
Member

btmills commented Mar 27, 2021

This seems related to https://github.com/eslint/eslint/pull/14227/files#r602802758. I can reproduce this today in a test if I configure this plugin to run on .md and .markdown files and have a README.md file containing a markdown code block. If #14227 changes ESLint to run processors directly recursively, this would be even easier to reproduce.

@btmills btmills moved this from Triaging to Pull Request Opened in Triage Mar 27, 2021
@JounQin
Copy link
Contributor Author

JounQin commented Mar 28, 2021

Yes, I should simplify the test case in current PR.

btmills added a commit that referenced this issue Mar 30, 2021
The current implementation assumes the `blocks` module-level variable
will only be used once per physical file. If the file contains a nested
Markdown code block, the processor will be recursively run on the code
block's virtual file.
Triage automation moved this from Pull Request Opened to Complete Apr 5, 2021
btmills pushed a commit that referenced this issue Apr 5, 2021
…183)

* Fix: use blocksCache instead of single blocks instance

pass through lint messages from other plugins

* refactor: use Map and delete map after postprocess

remove unnecessary mdx example

* Chore: add test case for blocksCache

* Revert: downgrade remark-parse and unified

* chore: remove unnecessary fallback check

* refactor: simplify return statement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Triage
Complete
Development

Successfully merging a pull request may close this issue.

2 participants