Skip to content

Bug: recognize carriage return (\r) as a line break in JSONSourceCode #159

@sethamus

Description

@sethamus

Environment

ESLint version: 9.36.0
@eslint/json version: 0.13.2
Node version:
npm version:
Operating System:

Which language are you using?

jsonc

What did you do?

import { JSONLanguage, JSONSourceCode } from "@eslint/json";

const file = { body: "{\r/* CR */\r}" };
const language = new JSONLanguage({
    mode: "jsonc"
});
const parseResult = language.parse(file);
const sourceCode = new JSONSourceCode({
  text: file.body,
  ast: parseResult.ast,
});

console.log(sourceCode.lines);

What did you expect to happen?

  • JSONSourceCode.lines returns the correct array of lines.
  • getLocFromIndex and getIndexFromLoc return correct line/column positions.

What actually happened?

Lines containing CR were not split, causing incorrect line/column calculations.

Link to Minimal Reproducible Example

n/a

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

According to the JSON specification (RFC 8259, Section 2), the allowed whitespace characters are:

  • Space ( , U+0020)
  • Horizontal tab (\t, U+0009)
  • Line feed (\n, U+000A)
  • Carriage return (\r, U+000D)

No response

Metadata

Metadata

Assignees

Labels

acceptedbugSomething isn't workingrepro:yesIssues with a reproducible example

Type

No type

Projects

Status

Ready to Implement

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions