Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/rules/no-invalid-label-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Examples of **incorrect** code for this rule:
[eslint][ ]

[eslint][

]
Comment on lines 32 to 33
Copy link
Member Author

@lumirlumir lumirlumir Sep 30, 2025

Choose a reason for hiding this comment

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

The following example was correct code, so I've updated it to show incorrect code.

(I've also added a test for it.)

[eslint][

]
image

```

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-invalid-label-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function findInvalidLabelReferences(node, sourceCode) {
const startColumn = nodeStartColumn + startColumnOffset;
const endLine = nodeStartLine + endLineOffset;
const endColumn =
(endLine === startLine ? nodeStartColumn : 0) + endColumnOffset;
(endLine === startLine ? nodeStartColumn : 1) + endColumnOffset;
Copy link
Member Author

Choose a reason for hiding this comment

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

The column is a 1-indexed value, so it needs to be 1, not 0.

/**
* The column number at which the parser starts counting.
* @type {0|1}
*/
columnStart = 1;


invalid.push({
label: label.trim(),
Expand Down
42 changes: 41 additions & 1 deletion tests/rules/no-invalid-label-refs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ruleTester.run("no-invalid-label-refs", rule, {
"[foo][]\n\n[foo]: http://bar.com/image.jpg",
"![foo][]\n\n[foo]: http://bar.com/image.jpg",
"[ foo ][]\n\n[foo]: http://bar.com/image.jpg",
"[eslint][\n\n]",
],
invalid: [
{
Expand Down Expand Up @@ -68,7 +69,20 @@ ruleTester.run("no-invalid-label-refs", rule, {
line: 3,
column: 2,
endLine: 4,
endColumn: 1,
endColumn: 2,
},
],
},
{
code: "[\nfoo\n][\n ]\n\n[foo]: http://bar.com/image.jpg",
errors: [
{
messageId: "invalidLabelRef",
data: { label: "foo" },
line: 3,
column: 2,
endLine: 4,
endColumn: 3,
},
],
},
Expand Down Expand Up @@ -166,5 +180,31 @@ ruleTester.run("no-invalid-label-refs", rule, {
},
],
},
{
code: "[eslint][ ]",
errors: [
{
messageId: "invalidLabelRef",
data: { label: "eslint" },
line: 1,
column: 9,
endLine: 1,
endColumn: 12,
},
],
},
{
code: "[eslint][\n]",
errors: [
{
messageId: "invalidLabelRef",
data: { label: "eslint" },
line: 1,
column: 9,
endLine: 2,
endColumn: 2,
},
],
},
],
});