Skip to content

Commit 386f42a

Browse files
authored
fix: correct the return type of applyInlineConfig (#281)
* fix: correct the return type of `applyInlineConfig` * wip: add type test
1 parent ed0c0f1 commit 386f42a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/languages/css-source-code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { visitorKeys } from "./css-visitor-keys.js";
2020
//-----------------------------------------------------------------------------
2121

2222
/**
23-
* @import { CssNode, CssNodePlain, Comment, Lexer, StyleSheetPlain } from "@eslint/css-tree"
24-
* @import { SourceRange, SourceLocation, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"
23+
* @import { CssNode, CssNodePlain, CssLocationRange, Comment, Lexer, StyleSheetPlain } from "@eslint/css-tree"
24+
* @import { SourceRange, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"
2525
* @import { CSSSyntaxElement } from "../types.js"
2626
* @import { CSSLanguageOptions } from "./css-language.js"
2727
*/
@@ -202,13 +202,13 @@ export class CSSSourceCode extends TextSourceCodeBase {
202202
/**
203203
* Returns inline rule configurations along with any problems
204204
* encountered while parsing the configurations.
205-
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:SourceLocation}>}} Information
205+
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:CssLocationRange}>}} Information
206206
* that ESLint needs to further process the rule configurations.
207207
*/
208208
applyInlineConfig() {
209209
/** @type {Array<FileProblem>} */
210210
const problems = [];
211-
/** @type {Array<{config:{rules:RulesConfig},loc:SourceLocation}>} */
211+
/** @type {Array<{config:{rules:RulesConfig},loc:CssLocationRange}>} */
212212
const configs = [];
213213

214214
this.getInlineConfigNodes().forEach(comment => {

tests/types/types.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import type {
5151
ValuePlain,
5252
WhiteSpace,
5353
CssNodePlain,
54+
CssLocationRange,
5455
} from "@eslint/css-tree";
5556
import type { CSSRuleDefinition, CSSRuleVisitor } from "@eslint/css/types";
5657

@@ -73,6 +74,19 @@ css.configs.recommended.plugins satisfies object;
7374
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
7475
}
7576

77+
{
78+
type ApplyInlineConfigLoc = ReturnType<
79+
CSSSourceCode["applyInlineConfig"]
80+
>["configs"][0]["loc"];
81+
82+
// Check that `applyInlineConfig`'s return type includes correct `loc` structure.
83+
const loc: ApplyInlineConfigLoc = {
84+
source: "source",
85+
start: { line: 1, column: 1, offset: 0 },
86+
end: { line: 1, column: 1, offset: 0 },
87+
};
88+
}
89+
7690
(): CSSRuleDefinition => ({
7791
create({ sourceCode }): CSSRuleVisitor {
7892
sourceCode satisfies CSSSourceCode;
@@ -91,6 +105,12 @@ css.configs.recommended.plugins satisfies object;
91105
sourceCode.getParent(node) satisfies CssNodePlain | undefined;
92106
sourceCode.getAncestors(node) satisfies CssNodePlain[];
93107
sourceCode.getText(node) satisfies string;
108+
sourceCode.applyInlineConfig().configs[0].loc
109+
.source satisfies CssLocationRange["source"];
110+
sourceCode.applyInlineConfig().configs[0].loc.start
111+
.offset satisfies CssLocationRange["start"]["offset"];
112+
sourceCode.applyInlineConfig().configs[0].loc.end
113+
.offset satisfies CssLocationRange["end"]["offset"];
94114
}
95115

96116
return {

0 commit comments

Comments
 (0)