Skip to content
Merged
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
13 changes: 7 additions & 6 deletions src/language/markdown-source-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
*/

Expand All @@ -46,15 +47,15 @@ class InlineConfigComment {

/**
* The position of the comment in the source code.
* @type {SourceLocation}
* @type {Position}
*/
position;

/**
* 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();
Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:SourceLocation}>}} Information
* @returns {{problems:Array<FileProblem>,configs:Array<{config:{rules:RulesConfig},loc:Position}>}} Information
* 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:Position}>} */
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 @@ -124,6 +124,18 @@ typeof processorPlugins satisfies {};
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
}

{
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;
Expand All @@ -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 {
Expand Down