Skip to content

Conversation

lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Jul 29, 2025

Prerequisites checklist

What is the purpose of this pull request?

Which language are you using?

CommonMark and GFM.

What did you do?

I've tried using consecutive backslashes in the no-missing-atx-heading-space, no-missing-label-refs, and no-reversed-media-syntax rules, but they reported false positives and false negatives as shown below:

What did you expect to happen?

no-missing-atx-heading-space

  • Only an even number of backslashes should be reported, as \\\\ is not interpreted as an escape backslash character in Markdown. However, it also reports odd numbers of backslashes greater than three.

    image

no-missing-label-refs

  • When consecutive backslashes appear, it fails to report them, resulting in false negatives:

    image

    According to the AST, the foo\\ is a valid label reference.

    image

no-reversed-media-syntax

  • When consecutive backslashes appear, it fails to report them, resulting in false negatives:

    image

What actually happened?

It's also mentioned in the "What did you expect to happen?" section.

Link to minimal reproducible Example

<!-- eslint markdown/no-missing-atx-heading-space: ["error", { checkClosedHeadings: true }] -->

<!-- OK -->
# Heading 1\# 
# Heading 1\\#
# Heading 1\\\\#
# Heading 1\\\\\\#

<!-- NOT OK -->
# Heading 1\\\#
# Heading 1\\\\\#
<!-- eslint markdown/no-missing-label-refs: "error" -->

<!-- OK -->
[foo]
\[foo\]
\\\[foo\\\]

<!-- NOT OK -->
\\[foo\\]
\\\\[foo\\\\]
<!-- eslint markdown/no-reversed-media-syntax: "error" -->

<!-- OK -->
(hi)[hi]
\(hi)[hi]
\\\(hi)[hi]

<!-- NOT OK -->
\\(hi)[hi]
\\\\(hi)[hi]

What changes did you make? (Give an overview)

In this PR, I've addressed false positives and negatives in no-missing-atx-heading-space, no-missing-label-refs, and no-reversed-media-syntax rules that were caused by consecutive backslash handling.

Previously, we used the following regex patterns to avoid matching backslash escapes:

  • (?<!\\) and (?<!(?<!\\)\\)

However, these patterns are incorrect because they don't properly handle consecutive backslash escapes metioned above.

So, I've updated them to use the following regex correctly:

  • (?<=(?<!\\)(?:\\{2})*)
(?<=(?<!\\)(?:\\{2})*)a
a           // even
\a          // odd
\\a         // even
\\\a        // odd
\\\\a       // even
\\\\\a      // odd
\\\\\\a     // even
image image

Related Issues

Ref: #452 (comment)

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

In JavaScript, \\\\\\\\ (8 backslashes) is interpreted as \\\\ (4 backslashes) in Markdown, and is ultimately recognized as \\ (2 backslashes). In this case, an even number of backslashes is not treated as an escape character and is recognized as a normal backslash.

@lumirlumir lumirlumir added this to Triage Aug 2, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Aug 2, 2025
Copy link
Contributor

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Aug 13, 2025
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Aug 22, 2025
@lumirlumir lumirlumir changed the title fix: false positives for consecutive backslashes fix: false positives and negatives for consecutive backslashes Aug 27, 2025
@lumirlumir lumirlumir removed the Stale label Aug 27, 2025
@lumirlumir lumirlumir marked this pull request as ready for review August 27, 2025 11:52
@lumirlumir lumirlumir requested a review from a team August 27, 2025 11:52
@mdjermanovic mdjermanovic changed the title fix: false positives and negatives for consecutive backslashes feat: false positives and negatives for consecutive backslashes Aug 28, 2025
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.

2 participants