diff --git a/src/languages/json-source-code.js b/src/languages/json-source-code.js index df92569..4830625 100644 --- a/src/languages/json-source-code.js +++ b/src/languages/json-source-code.js @@ -21,7 +21,7 @@ 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"; */ @@ -248,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:SourceLocation}>}} 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:SourceLocation}>} */ + /** @type {Array<{config:{rules:RulesConfig},loc:JSONSyntaxElement['loc']}>} */ const configs = []; this.getInlineConfigNodes().forEach(comment => { diff --git a/tests/types/types.test.ts b/tests/types/types.test.ts index f9b9fa0..e84a1ae 100644 --- a/tests/types/types.test.ts +++ b/tests/types/types.test.ts @@ -43,6 +43,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 +92,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 JSONSyntaxElement["loc"]["start"]["offset"]; + sourceCode.applyInlineConfig().configs[0].loc.end + .offset satisfies JSONSyntaxElement["loc"]["end"]["offset"]; } return {