Skip to content

Bug: no-invalid-label-refs reports escaped label references #717

Description

@KumJungMin

Environment

ESLint version: 10.8.0
@eslint/markdown version: 8.0.3
Node version: 22.18.0
npm version: 10.9.3

Which language are you using?

commonmark

What did you do?

Configuration
import { defineConfig } from "eslint/config";
import markdown from "@eslint/markdown";

export default defineConfig([
    {
        files: ["**/*.md"],
        plugins: {
            markdown,
        },
        language: "markdown/commonmark",
        rules: {
            "markdown/no-invalid-label-refs": "error",
        },
    },
]);
<!-- eslint markdown/no-invalid-label-refs: "error" -->

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

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

What did you expect to happen?

he rule should not report the cases with an odd number of backslashes before the opening bracket:

\[foo][ ]
\\\[foo][ ]

In these cases, the opening bracket is escaped, so the text does not form a label reference.

The rule should report only the cases where the opening bracket is not escaped:

[foo][ ]
\\[foo][ ]
\\\\[foo][ ]

An even number of backslashes does not escape the opening bracket,
so these cases still form invalid label references.

What actually happened?

no-invalid-label-refs reports the cases where the opening bracket is escaped:

   5:7   error  Label reference 'foo' is invalid due to white space between [ and ]  markdown/no-invalid-la...

The rule appears to detect the ][ ] portion and search backward for an opening bracket without checking whether that bracket is escaped. As a result, escaped text is incorrectly treated as an invalid label reference.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/vitejs-vite-ddfg51us?file=eslint.config.js,test.md

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

Disclosure: I'm a participant of open source contribution program OSSCA

A related case was addressed in #490, which updated several rules to distinguish escaped syntax based on whether it is preceded by an odd or even number of consecutive backslashes.

That change covered no-missing-label-refs, no-reversed-media-syntax, and no-missing-atx-heading-space. However, no-invalid-label-refs appears to perform a separate label-reference check that does not account for whether the opening bracket is escaped.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

  • Status
    Ready to Implement

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions