Skip to content

Conversation

@lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Sep 30, 2025

Prerequisites checklist

What is the purpose of this pull request?

Which language are you using?

CommonMark and GFM.

What did you do?

The error location reported by no-invalid-label-refs is correct for single-line text, but in multi-line text, it's one index(offset) behind where I expect.

image

What did you expect to happen?

I expected the error location to begin at [ and end at ], but in multi-line text the end column is one index behind.

Link to minimal reproducible Example

Adding the following test case to the invalid section would help identify the problem.

		{
			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: 2,
				},
			],
		},

Originally, the endColumn was 1, but it needs to be 2 so it includes ] as it does for single-line text.

What changes did you make? (Give an overview)

In this PR, I've fixed wrong location reporting in no-invalid-label-refs.

Related Issues

N/A

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

N/A

@eslintbot eslintbot added this to Triage Sep 30, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Sep 30, 2025
Comment on lines 32 to 33
[eslint][

]
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

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;

@lumirlumir lumirlumir marked this pull request as ready for review September 30, 2025 13:24
@lumirlumir lumirlumir requested a review from a team September 30, 2025 13:24
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit e0f7d23 into main Sep 30, 2025
24 checks passed
@mdjermanovic mdjermanovic deleted the fix-wrong-location-reporting-in-no-invalid-label-refs branch September 30, 2025 15:04
@github-project-automation github-project-automation bot moved this from Needs Triage to Complete in Triage Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants