Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes false positives in the no-reversed-media-syntax rule when inline elements (HTML comments, HTML tags, images, inline code) appear in patterns that superficially resemble reversed media syntax.
Key Changes:
- Replaced skip-range checking with whitespace masking approach
- Inline elements are masked with spaces before pattern matching
- Fix generation now extracts from original source using positions from masked matches
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/rules/no-reversed-media-syntax.js |
Refactored to use whitespace masking instead of skip ranges; removed unused helper function and import; inlined logic into visitor methods |
tests/rules/no-reversed-media-syntax.test.js |
Added 5 test cases covering false positives with HTML comments, HTML tags, images, and inline code |
The implementation is sound and correctly handles the reported false positive cases. The whitespace masking approach is borrowed from the existing no-space-in-emphasis rule and effectively prevents inline elements from interfering with pattern matching while preserving the original content for fix generation. The test coverage adequately validates the fix for the reported issues.
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prerequisites checklist
What is the purpose of this pull request?
Which language are you using?
CommonMark and GFM.
What did you do?
I expected the following examples to be ignored and not to generate errors, but they generate errors (false positives).
Within each section of the code snippet there are HTML comments, HTML, images, and inline code, so these parts shouldn't be interpreted as error-prone link syntax (
[description](URL)).What did you expect to happen?
I expected the above examples to be ignored and not to generate errors, but they generate errors (false positives).
Link to minimal reproducible Example
The following Markdown code may help identify the problem:
What changes did you make? (Give an overview)
In this PR, I've fixed false positives for inline elements in
no-reversed-media-syntax.The previous logic only checked the
startOffsetof the ignored position, as shown below:markdown/src/rules/no-reversed-media-syntax.js
Lines 84 to 86 in 07dac6e
So, the following code was ignored as expected:
However, for the following snippets it doesn't work as expected and produces false positives:
A concrete way to resolve this problem is to test the regex against whitespace-masked text, rather than checking only the
startOffset.For example, the previous logic checked the following code, which caused false positives:
However, after this change, the text is tested against whitespace-masked text, so it no longer causes false positives.
( ] ^----^ Now, The text is whitespace-masked.The whitespace-masking idea was inspired by the existing
no-space-in-emphasisrule, and I've modified its logic slightly.markdown/src/rules/no-space-in-emphasis.js
Lines 111 to 138 in 07dac6e
Related Issues
N/A
Is there anything you'd like reviewers to focus on?
The
findReversedMediaSyntaxhelper function was only used in one place, so I've moved it directly under:matches(heading, paragraph, tableCell):exit.