Skip to content

Conversation

@lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Oct 8, 2025

Prerequisites checklist

What is the purpose of this pull request?

Which language are you using?

CommonMark and GFM.

What did you do?

@eslint/markdown is unable to recognize CR line endings in the MarkdownSourceCode class, as well as in rules and processors.

What did you expect to happen?

I expect CR line endings to be recognized as valid line endings throughout the Markdown plugins.

According to the Markdown(CommonMark) specification, LF, CR, and CRLF can all be used for line endings.

https://spec.commonmark.org/0.31.2/#line-ending

Image

Link to minimal reproducible Example

Adding the following test case to the tests/language/markdown-source-code.test.js would help identify the problem:

	describe("lines", () => {
		it("should parse CRLF line endings", () => {
			const text = "lumir\r\nlumir";
			const sourceCodeWithCRLF = new MarkdownSourceCode({
				text,
				ast: fromMarkdown(text),
			});

			assert.deepStrictEqual(sourceCodeWithCRLF.lines, [
				"lumir",
				"lumir",
			]);
		});

		it("should parse CR line endings", () => {
			const text = "lumir\rlumir";
			const sourceCodeWithCR = new MarkdownSourceCode({
				text,
				ast: fromMarkdown(text),
			});

			assert.deepStrictEqual(sourceCodeWithCR.lines, ["lumir", "lumir"]);
		});

		it("should parse LF line endings", () => {
			const text = "lumir\nlumir";
			const sourceCodeWithLF = new MarkdownSourceCode({
				text,
				ast: fromMarkdown(text),
			});

			assert.deepStrictEqual(sourceCodeWithLF.lines, ["lumir", "lumir"]);
		});

		it("should parse CRLF CR LF line endings", () => {
			const text = "lumir\r\nlumir\rlumir\nlumir";
			const sourceCodeWithCRLFCRLF = new MarkdownSourceCode({
				text,
				ast: fromMarkdown(text),
			});

			assert.deepStrictEqual(sourceCodeWithCRLFCRLF.lines, [
				"lumir",
				"lumir",
				"lumir",
				"lumir",
			]);
		});
	});

What changes did you make? (Give an overview)

This PR originated from #493. While working on that, I found the scope had become too large, so I split this fix into a separate PR.

In this PR, I've fixed an issue where MarkdownSourceCode and the Front Matter utility could not handle CR line endings.

Notable changes:

  • Update MarkdownSourceCode to recognize CR line endings.
  • Update frontmatterHasTitle utility to recognize CR and CRLF line endings.

Related Issues

Ref: #493, eslint/css#275

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

I'll update the rules and processors to recognize CR in #493. This PR is separate from that one to keep the scope smaller.

@eslint-github-bot eslint-github-bot bot added the bug label Oct 8, 2025
@eslintbot eslintbot added this to Triage Oct 8, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 8, 2025
@lumirlumir lumirlumir changed the title fix: add CR to MarkdownSourceCode fix: add CR to MarkdownSourceCode and Front Matter Oct 8, 2025
@lumirlumir lumirlumir changed the title fix: add CR to MarkdownSourceCode and Front Matter fix: recognize CR in MarkdownSourceCode and Front Matter Oct 8, 2025
@lumirlumir lumirlumir changed the title fix: recognize CR in MarkdownSourceCode and Front Matter fix: handle CR in MarkdownSourceCode and Front Matter Oct 8, 2025
@lumirlumir lumirlumir marked this pull request as ready for review October 8, 2025 10:37
@lumirlumir lumirlumir changed the title fix: handle CR in MarkdownSourceCode and Front Matter fix: handle CR in MarkdownSourceCode and Front Matter util Oct 8, 2025
Copy link
Member

@nzakas nzakas 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!

@nzakas nzakas merged commit d1ad828 into main Oct 8, 2025
23 checks passed
@nzakas nzakas deleted the fix-add-cr-to-the-lineendingpattern branch October 8, 2025 14:57
@github-project-automation github-project-automation bot moved this from Needs Triage to Complete in Triage Oct 8, 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