Skip to content

Commit 95c6238

Browse files
authored
fix: correct the return type of applyInlineConfig (#162)
* fix: correct the return type of `applyInlineConfig` * wip: add type test * wip * wip * wip
1 parent 6fef00d commit 95c6238

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"dependencies": {
8686
"@eslint/core": "^0.16.0",
8787
"@eslint/plugin-kit": "^0.4.0",
88-
"@humanwhocodes/momoa": "^3.3.9",
88+
"@humanwhocodes/momoa": "^3.3.10",
8989
"natural-compare": "^1.4.0"
9090
},
9191
"devDependencies": {

src/languages/json-source-code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
//-----------------------------------------------------------------------------
2121

2222
/**
23-
* @import { DocumentNode, AnyNode, Token } from "@humanwhocodes/momoa";
24-
* @import { SourceLocation, FileProblem, DirectiveType, RulesConfig } from "@eslint/core";
23+
* @import { DocumentNode, AnyNode, Token, LocationRange } from "@humanwhocodes/momoa";
24+
* @import { FileProblem, DirectiveType, RulesConfig } from "@eslint/core";
2525
* @import { JSONSyntaxElement } from "../types.ts";
2626
* @import { JSONLanguageOptions } from "./json-language.js";
2727
*/
@@ -248,13 +248,13 @@ export class JSONSourceCode extends TextSourceCodeBase {
248248
/**
249249
* Returns inline rule configurations along with any problems
250250
* encountered while parsing the configurations.
251-
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:SourceLocation}>}} Information
251+
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:LocationRange}>}} Information
252252
* that ESLint needs to further process the rule configurations.
253253
*/
254254
applyInlineConfig() {
255255
/** @type {Array<FileProblem>} */
256256
const problems = [];
257-
/** @type {Array<{config:{rules:RulesConfig},loc:SourceLocation}>} */
257+
/** @type {Array<{config:{rules:RulesConfig},loc:LocationRange}>} */
258258
const configs = [];
259259

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

tests/types/types.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
NumberNode,
2020
ObjectNode,
2121
StringNode,
22+
LocationRange,
2223
} from "@humanwhocodes/momoa";
2324
import type { SourceLocation, SourceRange } from "@eslint/core";
2425

@@ -43,6 +44,18 @@ json.configs.recommended.plugins satisfies object;
4344
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
4445
}
4546

47+
{
48+
type ApplyInlineConfigLoc = ReturnType<
49+
JSONSourceCode["applyInlineConfig"]
50+
>["configs"][0]["loc"];
51+
52+
// Check that `applyInlineConfig`'s return type includes correct `loc` structure.
53+
const loc: ApplyInlineConfigLoc = {
54+
start: { line: 1, column: 1, offset: 0 },
55+
end: { line: 1, column: 1, offset: 0 },
56+
};
57+
}
58+
4659
// Check that types are imported correctly from `@humanwhocodes/momoa`.
4760
({
4861
start: { line: 1, column: 1, offset: 1 },
@@ -80,6 +93,10 @@ json.configs.recommended.plugins satisfies object;
8093
sourceCode.getParent(node) satisfies AnyNode | undefined;
8194
sourceCode.getAncestors(node) satisfies JSONSyntaxElement[];
8295
sourceCode.getText(node) satisfies string;
96+
sourceCode.applyInlineConfig().configs[0].loc.start
97+
.offset satisfies LocationRange["start"]["offset"];
98+
sourceCode.applyInlineConfig().configs[0].loc.end
99+
.offset satisfies LocationRange["end"]["offset"];
83100
}
84101

85102
return {

0 commit comments

Comments
 (0)