Skip to content

Conversation

lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Oct 1, 2025

Prerequisites checklist

What is the purpose of this pull request?

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. Also loc.source is missing.

What did you expect to happen?

I expect the types of loc.start and loc.end to include an offset property, and for loc.source to be present.

Link to minimal reproducible Example

import { CSSSourceCode, CSSLanguage } from "./src/index.js";

const file = {
	body: '/* eslint css/no-important: "error" */',
	path: "test.css",
};
const language = new CSSLanguage();
const parseResult = language.parse(file);
const cssSourceCode = new CSSSourceCode({
	text: file.body,
	ast: parseResult.ast,
	comments: parseResult.comments,
});

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

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

# Output
{
  source: 'test.css',
  start: { offset: 0, line: 1, column: 1 },
  end: { offset: 38, line: 1, column: 39 }
}

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 CssLocationRange type from @eslint/css-tree as shown below, so technically it doesn’t match the SourceLocation type.

  • CssLocationRange
interface CssLocationRange {
    source: string;
    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 CssLocationRange type from @eslint/css-tree.

Related Issues

Ref: eslint/markdown#548, eslint/json#162

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

N/A

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 1, 2025
@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Oct 1, 2025
@lumirlumir lumirlumir marked this pull request as ready for review October 2, 2025 06:19
@lumirlumir lumirlumir requested a review from a team October 2, 2025 06:19
@fasttime fasttime moved this from Needs Triage to Implementing in Triage Oct 6, 2025
@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 6, 2025
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 386f42a into main Oct 6, 2025
22 checks passed
@fasttime fasttime deleted the fix-correct-the-return-type-of-applyinlineconfig branch October 6, 2025 10:52
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug Something isn't working
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

2 participants