Skip to content

Conversation

@lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Oct 1, 2025

Prerequisites checklist

What is the purpose of this pull request?

Which language are you using?

JSONC and JSON5

What did you do?

I expected the return type of applyInlineConfig().configs — specifically loc.start and loc.end — to include an offset property, but they don't.

What did you expect to happen?

I expect the types of loc.start and loc.end to include an offset property.

Link to minimal reproducible Example

import { JSONSourceCode, JSONLanguage } from "./src/index.js";

const file = {
	body: '/* eslint json/no-duplicate-keys: "error" */ {}',
	path: "test.jsonc",
};
const language = new JSONLanguage({ mode: "jsonc" });
const parseResult = language.parse(file);
const jsonSourceCode = new JSONSourceCode({
	text: file.body,
	ast: parseResult.ast,
});

console.log(jsonSourceCode.applyInlineConfig().configs[0].loc);

If you run the code above, you'll see that jsonSourceCode.applyInlineConfig().configs[0].loc.start and jsonSourceCode.applyInlineConfig().configs[0].loc.end include an offset property. However, the return type doesn't reflect that offset property.

# Output
{
  start: { line: 1, column: 1, offset: 0 },
  end: { line: 1, column: 45, offset: 44 }
}

What changes did you make? (Give an overview)

Looking at the origin of the loc property returned by applyInlineConfig, you'll find that it directly uses the comment.loc.

loc: comment.loc,

The comment.loc property uses the JSONSyntaxElement['loc'] (LocationRange) type from @humanwhocodes/momoa as shown below, so technically it doesn’t match the SourceLocation type.

  • JSONSyntaxElement['loc'] (LocationRange)
interface LocationRange {
    start: {
        line: number;
        column: number;
        offset: number;
    }
    end: {
        line: number;
        column: number;
        offset: number;
    }
}
  • SourceLocation
interface SourceLocation {
    start: {
        line: number;
        column: number;
    }
    end: {
        line: number;
        column: number;
    }
}

To provide a more accurate return type, I've replaced the SourceLocation type with the JSONSyntaxElement['loc'] (LocationRange) type from @humanwhocodes/momoa.

Related Issues

Ref: eslint/markdown#548, eslint/css#281

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

N/A

@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Oct 1, 2025
@eslintbot eslintbot added this to Triage Oct 1, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 1, 2025
@lumirlumir
Copy link
Member Author

Pending until humanwhocodes/momoa#197 is merged.

@lumirlumir
Copy link
Member Author

Friendly ping @fasttime@humanwhocodes/momoa v3.3.10 has been released, and I've updated the PR accordingly: d19588e.

@lumirlumir lumirlumir requested a review from fasttime October 21, 2025 13:43
Copy link
Member

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

@fasttime fasttime merged commit 95c6238 into main Oct 21, 2025
23 checks passed
@fasttime fasttime deleted the fix-correct-the-return-type-of-applyinlineconfig branch October 21, 2025 14:25
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted bug Something isn't working

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants