From ea6e23843e3a9754dad15789d206a07d192ff847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Wed, 1 Oct 2025 22:43:50 +0900 Subject: [PATCH 1/2] fix: correct the return type of `applyInlineConfig` --- src/language/markdown-source-code.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/language/markdown-source-code.js b/src/language/markdown-source-code.js index 46d6f8cb..6127be89 100644 --- a/src/language/markdown-source-code.js +++ b/src/language/markdown-source-code.js @@ -20,8 +20,9 @@ import { findOffsets } from "../util.js"; //----------------------------------------------------------------------------- /** + * @import { Position } from "unist"; * @import { Root, Node, Html } from "mdast"; - * @import { TraversalStep, SourceLocation, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; + * @import { TraversalStep, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; * @import { MarkdownLanguageOptions } from "../types.js"; */ @@ -46,7 +47,7 @@ class InlineConfigComment { /** * The position of the comment in the source code. - * @type {SourceLocation} + * @type {Position} */ position; @@ -54,7 +55,7 @@ class InlineConfigComment { * Creates a new instance. * @param {Object} options The options for the instance. * @param {string} options.value The comment text. - * @param {SourceLocation} options.position The position of the comment in the source code. + * @param {Position} options.position The position of the comment in the source code. */ constructor({ value, position }) { this.value = value.trim(); @@ -127,7 +128,7 @@ function extractInlineConfigCommentsFromHTML(node) { /** * Markdown Source Code Object - * @extends {TextSourceCodeBase<{LangOptions: MarkdownLanguageOptions, RootNode: Root, SyntaxElementWithLoc: Node, ConfigNode: { value: string; position: SourceLocation }}>} + * @extends {TextSourceCodeBase<{LangOptions: MarkdownLanguageOptions, RootNode: Root, SyntaxElementWithLoc: Node, ConfigNode: { value: string; position: Position }}>} */ export class MarkdownSourceCode extends TextSourceCodeBase { /** @@ -261,13 +262,13 @@ export class MarkdownSourceCode 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:Position}>}} 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:Position}>} */ const configs = []; this.getInlineConfigNodes().forEach(comment => { From e56ad44e02a2a0f8e02eec3f8ff60e82dee0c92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Wed, 1 Oct 2025 23:48:34 +0900 Subject: [PATCH 2/2] wip: add type test --- tests/types/types.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/types/types.test.ts b/tests/types/types.test.ts index 16ab22c1..f7aa43dd 100644 --- a/tests/types/types.test.ts +++ b/tests/types/types.test.ts @@ -124,6 +124,18 @@ typeof processorPlugins satisfies {}; null as AssertAllNamesIn; } +{ + type ApplyInlineConfigLoc = ReturnType< + MarkdownSourceCode["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 }, + }; +} + (): MarkdownRuleDefinition => ({ create({ sourceCode }): MarkdownRuleVisitor { sourceCode satisfies MarkdownSourceCode; @@ -145,6 +157,10 @@ typeof processorPlugins satisfies {}; sourceCode.getParent(node) satisfies Node | undefined; sourceCode.getAncestors(node) satisfies Node[]; sourceCode.getText(node) satisfies string; + sourceCode.applyInlineConfig().configs[0].loc.start + .offset satisfies Position["start"]["offset"]; + sourceCode.applyInlineConfig().configs[0].loc.end + .offset satisfies Position["end"]["offset"]; } return {