From c267379ebf8e196dce7dd11c8131200adf405adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Wed, 1 Oct 2025 22:47:54 +0900 Subject: [PATCH 1/4] fix: correct the return type of `applyInlineConfig` --- src/languages/json-source-code.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/languages/json-source-code.js b/src/languages/json-source-code.js index df92569..55c188b 100644 --- a/src/languages/json-source-code.js +++ b/src/languages/json-source-code.js @@ -21,9 +21,10 @@ import { /** * @import { DocumentNode, AnyNode, Token } from "@humanwhocodes/momoa"; - * @import { SourceLocation, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; + * @import { FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; * @import { JSONSyntaxElement } from "../types.ts"; * @import { JSONLanguageOptions } from "./json-language.js"; + * @typedef {Token['loc']} LocationRange */ //----------------------------------------------------------------------------- @@ -248,13 +249,13 @@ export class JSONSourceCode 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:LocationRange}>}} 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:LocationRange}>} */ const configs = []; this.getInlineConfigNodes().forEach(comment => { From 7345379d1817cf385096021e2941dd155551273d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 2 Oct 2025 15:41:12 +0900 Subject: [PATCH 2/4] wip: add type test --- tests/types/types.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/types/types.test.ts b/tests/types/types.test.ts index f9b9fa0..f7352e5 100644 --- a/tests/types/types.test.ts +++ b/tests/types/types.test.ts @@ -6,6 +6,7 @@ import type { JSONRuleVisitor, } from "@eslint/json/types"; import type { + Token, AnyNode, ArrayNode, BooleanNode, @@ -43,6 +44,18 @@ json.configs.recommended.plugins satisfies object; null as AssertAllNamesIn; } +{ + type ApplyInlineConfigLoc = ReturnType< + JSONSourceCode["applyInlineConfig"] + >["configs"][0]["loc"]; + + // Check that `applyInlineConfig`'s return type includes correct `loc` structure. + const loc: ApplyInlineConfigLoc = { + start: { line: 1, column: 1, offset: 0 }, + end: { line: 1, column: 1, offset: 0 }, + }; +} + // Check that types are imported correctly from `@humanwhocodes/momoa`. ({ start: { line: 1, column: 1, offset: 1 }, @@ -80,6 +93,10 @@ json.configs.recommended.plugins satisfies object; sourceCode.getParent(node) satisfies AnyNode | undefined; sourceCode.getAncestors(node) satisfies JSONSyntaxElement[]; sourceCode.getText(node) satisfies string; + sourceCode.applyInlineConfig().configs[0].loc.start + .offset satisfies Token["loc"]["start"]["offset"]; + sourceCode.applyInlineConfig().configs[0].loc.end + .offset satisfies Token["loc"]["end"]["offset"]; } return { From a2b75dac5af81569338a89b728250bb66d247313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 2 Oct 2025 15:43:24 +0900 Subject: [PATCH 3/4] wip --- src/languages/json-source-code.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/languages/json-source-code.js b/src/languages/json-source-code.js index 55c188b..4830625 100644 --- a/src/languages/json-source-code.js +++ b/src/languages/json-source-code.js @@ -24,7 +24,6 @@ import { * @import { FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; * @import { JSONSyntaxElement } from "../types.ts"; * @import { JSONLanguageOptions } from "./json-language.js"; - * @typedef {Token['loc']} LocationRange */ //----------------------------------------------------------------------------- @@ -249,13 +248,13 @@ export class JSONSourceCode extends TextSourceCodeBase { /** * Returns inline rule configurations along with any problems * encountered while parsing the configurations. - * @returns {{problems:Array,configs:Array<{config:{rules:RulesConfig},loc:LocationRange}>}} Information + * @returns {{problems:Array,configs:Array<{config:{rules:RulesConfig},loc:JSONSyntaxElement['loc']}>}} Information * that ESLint needs to further process the rule configurations. */ applyInlineConfig() { /** @type {Array} */ const problems = []; - /** @type {Array<{config:{rules:RulesConfig},loc:LocationRange}>} */ + /** @type {Array<{config:{rules:RulesConfig},loc:JSONSyntaxElement['loc']}>} */ const configs = []; this.getInlineConfigNodes().forEach(comment => { From 4d71e0e1a1daf8171a4fed2296a55156fbb383ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Thu, 2 Oct 2025 15:44:25 +0900 Subject: [PATCH 4/4] wip --- tests/types/types.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/types/types.test.ts b/tests/types/types.test.ts index f7352e5..e84a1ae 100644 --- a/tests/types/types.test.ts +++ b/tests/types/types.test.ts @@ -6,7 +6,6 @@ import type { JSONRuleVisitor, } from "@eslint/json/types"; import type { - Token, AnyNode, ArrayNode, BooleanNode, @@ -94,9 +93,9 @@ json.configs.recommended.plugins satisfies object; sourceCode.getAncestors(node) satisfies JSONSyntaxElement[]; sourceCode.getText(node) satisfies string; sourceCode.applyInlineConfig().configs[0].loc.start - .offset satisfies Token["loc"]["start"]["offset"]; + .offset satisfies JSONSyntaxElement["loc"]["start"]["offset"]; sourceCode.applyInlineConfig().configs[0].loc.end - .offset satisfies Token["loc"]["end"]["offset"]; + .offset satisfies JSONSyntaxElement["loc"]["end"]["offset"]; } return {