Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/languages/json-source-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
*/
Expand Down Expand Up @@ -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<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:SourceLocation}>}} Information
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:JSONSyntaxElement['loc']}>}} Information
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use LocationRange directly from @humanwhocodes/momoa, but that type isn't exported.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably an oversight. You could open a PR at the momoa repo to fix that.

* that ESLint needs to further process the rule configurations.
*/
applyInlineConfig() {
/** @type {Array<FileProblem>} */
const problems = [];
/** @type {Array<{config:{rules:RulesConfig},loc:SourceLocation}>} */
/** @type {Array<{config:{rules:RulesConfig},loc:JSONSyntaxElement['loc']}>} */
const configs = [];

this.getInlineConfigNodes().forEach(comment => {
Expand Down
16 changes: 16 additions & 0 deletions tests/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ json.configs.recommended.plugins satisfies object;
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
}

{
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 },
Expand Down Expand Up @@ -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 {
Expand Down