From 774a6a779424222def31e7c0e46ca18755a2f983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Wed, 1 Oct 2025 22:46:11 +0900 Subject: [PATCH 1/2] fix: correct the return type of `applyInlineConfig` --- src/languages/css-source-code.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/languages/css-source-code.js b/src/languages/css-source-code.js index 705f70b..ec98a51 100644 --- a/src/languages/css-source-code.js +++ b/src/languages/css-source-code.js @@ -20,8 +20,8 @@ import { visitorKeys } from "./css-visitor-keys.js"; //----------------------------------------------------------------------------- /** - * @import { CssNode, CssNodePlain, Comment, Lexer, StyleSheetPlain } from "@eslint/css-tree" - * @import { SourceRange, SourceLocation, FileProblem, DirectiveType, RulesConfig } from "@eslint/core" + * @import { CssNode, CssNodePlain, CssLocationRange, Comment, Lexer, StyleSheetPlain } from "@eslint/css-tree" + * @import { SourceRange, FileProblem, DirectiveType, RulesConfig } from "@eslint/core" * @import { CSSSyntaxElement } from "../types.js" * @import { CSSLanguageOptions } from "./css-language.js" */ @@ -202,13 +202,13 @@ export class CSSSourceCode extends TextSourceCodeBase { /** * Returns inline rule configurations along with any problems * encountered while parsing the configurations. - * @returns {{problems:Array,configs:Array<{config:{rules:RulesConfig},loc:SourceLocation}>}} Information + * @returns {{problems:Array,configs:Array<{config:{rules:RulesConfig},loc:CssLocationRange}>}} Information * that ESLint needs to further process the rule configurations. */ applyInlineConfig() { /** @type {Array} */ const problems = []; - /** @type {Array<{config:{rules:RulesConfig},loc:SourceLocation}>} */ + /** @type {Array<{config:{rules:RulesConfig},loc:CssLocationRange}>} */ const configs = []; this.getInlineConfigNodes().forEach(comment => { From 0d4ba3b55242571ca73e66f278c3977dc7708674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 2 Oct 2025 15:15:18 +0900 Subject: [PATCH 2/2] wip: add type test --- tests/types/types.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/types/types.test.ts b/tests/types/types.test.ts index 776de11..8091cce 100644 --- a/tests/types/types.test.ts +++ b/tests/types/types.test.ts @@ -51,6 +51,7 @@ import type { ValuePlain, WhiteSpace, CssNodePlain, + CssLocationRange, } from "@eslint/css-tree"; import type { CSSRuleDefinition, CSSRuleVisitor } from "@eslint/css/types"; @@ -73,6 +74,19 @@ css.configs.recommended.plugins satisfies object; null as AssertAllNamesIn; } +{ + type ApplyInlineConfigLoc = ReturnType< + CSSSourceCode["applyInlineConfig"] + >["configs"][0]["loc"]; + + // Check that `applyInlineConfig`'s return type includes correct `loc` structure. + const loc: ApplyInlineConfigLoc = { + source: "source", + start: { line: 1, column: 1, offset: 0 }, + end: { line: 1, column: 1, offset: 0 }, + }; +} + (): CSSRuleDefinition => ({ create({ sourceCode }): CSSRuleVisitor { sourceCode satisfies CSSSourceCode; @@ -91,6 +105,12 @@ css.configs.recommended.plugins satisfies object; sourceCode.getParent(node) satisfies CssNodePlain | undefined; sourceCode.getAncestors(node) satisfies CssNodePlain[]; sourceCode.getText(node) satisfies string; + sourceCode.applyInlineConfig().configs[0].loc + .source satisfies CssLocationRange["source"]; + sourceCode.applyInlineConfig().configs[0].loc.start + .offset satisfies CssLocationRange["start"]["offset"]; + sourceCode.applyInlineConfig().configs[0].loc.end + .offset satisfies CssLocationRange["end"]["offset"]; } return {