Bug: no-invalid-label-refs reports escaped label references
- Dominant language
- JavaScript
- Stars
- 581
- Forks
- 92
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 11
Description
### 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
```js
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",
},
},
]);
```
```md
\[foo][ ]
\\\[foo][ ]
[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:
```md
\[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:
```md
[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
- [x] I am willing to submit a pull request for this issue.
### AI acknowledgment
- [ ] I did not use AI to generate this issue report.
- [x] (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](https://github.com/eslint-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.
Contributor guide
Assessment
This issue has not been assessed yet.