Skip to content

Conversation

@lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Sep 5, 2025

Prerequisites checklist

What is the purpose of this pull request?

Which language are you using?

CommonMark and GFM.

What did you do?

When using the fenced-code-language rule, the endColumn error location is reported incorrectly in the 'What did you expect to happen' example below:

What did you expect to happen?

First Problem

I expected the error location to end at the last backtick or tilde character, but it extends endlessly when there are spaces after the backtick or tilde.

  • Result
image
  • Configuration
<!-- eslint markdown/fenced-code-language: "error" -->
  • Source Code
```                                                                                                           
console.log("Hello, world!");
```

Second Problem

I expected the endColumn error location to be 17, but it reports 20, which exceeds the actual line length.

  • Result
image
  • Configuration
<!-- eslint markdown/fenced-code-language: ["error", { required: ["js"] }] -->
  • Source Code (The code below creates a valid Code node: AST)
   ```javascript
console.log("Hello, world!");
```

The following error location would help identify the problem:

{
    messageId: "disallowedLanguage",
    data: { lang: "javascript" },
    line: 1,
    column: 4,
    endLine: 1,
+   endColumn: 17,
-   endColumn: 20,
},

Link to minimal reproducible Example

Adding the following test cases to the invalid tests in tests/rules/fenced-code-language.test.js causes the tests to fail due to incorrect error reporting location.

First Problem

		{
			code: "```     \nconsole.log('Hello, world!');\n```",
			errors: [
				{
					messageId: "missingLanguage",
					line: 1,
					column: 1,
					endLine: 1,
					endColumn: 4,
				},
			],
		},

Second Problem

		{
			code: `   \`\`\`javascript
console.log("Hello, world!");
\`\`\``,
			options: [{ required: ["js"] }],
			errors: [
				{
					messageId: "disallowedLanguage",
					data: { lang: "javascript" },
					line: 1,
					column: 4,
					endLine: 1,
					endColumn: 17,
				},
			],
		},

What changes did you make? (Give an overview)

I've updated the rule so it reports the error location correctly.

Also, I've added test cases.

Related Issues

N/A

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

N/A

@eslint-github-bot eslint-github-bot bot added the bug label Sep 5, 2025
@eslintbot eslintbot added this to Triage Sep 5, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Sep 5, 2025
}

/** @type {number} */
let openingCodeFenceEndOffset;
Copy link
Member Author

Choose a reason for hiding this comment

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

I got the variable name from the CommonMark specification.

https://spec.commonmark.org/0.31.2/#fenced-code-block

image

@lumirlumir lumirlumir marked this pull request as ready for review September 8, 2025 13:50
@lumirlumir lumirlumir requested a review from a team September 8, 2025 13:51
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Sep 9, 2025
@mdjermanovic mdjermanovic moved this from Triaging to Implementing in Triage Sep 9, 2025
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 c532194 into main Sep 9, 2025
23 checks passed
@mdjermanovic mdjermanovic deleted the fix-wrong-location-reporting-in-fenced-code-language branch September 9, 2025 13:50
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants