Skip to content

feat: add no-reversed-media-syntax rule #398

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xbinaryx
Copy link

@xbinaryx xbinaryx commented Jun 1, 2025

Prerequisites checklist

What is the purpose of this pull request?

This PR adds a new rule no-reversed-media-syntax to enforce correct link and image syntax in Markdown.

What changes did you make? (Give an overview)

Added the no-reversed-media-syntax rule, along with documentation and tests.

Related Issues

Fixes #386

Is there anything you'd like reviewers to focus on?

@lumirlumir lumirlumir added this to Triage Jun 1, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 1, 2025
Copy link
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this PR.

I've left some comments about false negatives and test cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you take a look at the false negatives in nested text nodes?

Currently, nested text nodes using emphasis (*), strong (**), strikethrough (~), and inline code blocks using backticks result in false negatives.

(*foo*)[]

(**foo**)[]

(~~foo~~)[]

(`foo`)[]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm these produce 3 text nodes. This should complicate things 😅

@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Jun 3, 2025
// Helpers
//-----------------------------------------------------------------------------

const reversedPattern = /(?<!\\)\(((?:\\.|[^()\\])*)\)\[((?:\\.|[^\]\\])*)\]/gu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment showing what this regex is meant to match?

Comment on lines +65 to +68
const {
lineOffset: endLineOffset,
columnOffset: endColumnOffset,
} = findOffsets(text, matchIndex + matchLength);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the regex only matches single lines, you can just add matchLength to startColumnOffset to get this location instead of calculating it from scratch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

New Rule: no-reversed-links
3 participants