Skip to content

Commit c015363

Browse files
committed
fix IMarkdownSourceCode
1 parent 4e326af commit c015363

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/language/markdown-source-code.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { findOffsets } from "../util.js";
3232
/** @typedef {import("@eslint/core").SourceRange} SourceRange */
3333
/** @typedef {import("@eslint/core").FileProblem} FileProblem */
3434
/** @typedef {import("@eslint/core").DirectiveType} DirectiveType */
35+
/** @typedef {import("../types.ts").IMarkdownSourceCode} IMarkdownSourceCode */
3536

3637
//-----------------------------------------------------------------------------
3738
// Helpers
@@ -135,6 +136,7 @@ function extractInlineConfigCommentsFromHTML(node) {
135136

136137
/**
137138
* Markdown Source Code Object
139+
* @implements {IMarkdownSourceCode}
138140
*/
139141
export class MarkdownSourceCode extends TextSourceCodeBase {
140142
/**

src/types.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
RuleDefinition,
1818
RuleDefinitionTypeOptions,
1919
RuleVisitor,
20+
SourceLocation,
2021
TextSourceCode,
2122
} from "@eslint/core";
2223

@@ -58,23 +59,27 @@ export type RuleType = "problem" | "suggestion" | "layout";
5859
/**
5960
* The `SourceCode` interface for Markdown files.
6061
*/
61-
export interface IMarkdownSourceCode extends TextSourceCode {
62+
export interface IMarkdownSourceCode
63+
extends TextSourceCode<{
64+
LangOptions: {};
65+
RootNode: Root;
66+
SyntaxElementWithLoc: Node;
67+
ConfigNode: { value: string; position: SourceLocation };
68+
}> {
6269
/**
6370
* Gets the entire source text split into an array of lines.
64-
* @returns {Array<string>} The source text as an array of lines.
65-
* @public
71+
* @returns The source text as an array of lines.
6672
*/
6773
get lines(): Array<string>;
6874

6975
/**
7076
* Gets the source code for the given node.
71-
* @param {object} [node] The AST node to get the text for.
72-
* @param {number} [beforeCount] The number of characters before the node to retrieve.
73-
* @param {number} [afterCount] The number of characters after the node to retrieve.
74-
* @returns {string} The text representing the AST node.
75-
* @public
77+
* @param node The AST node to get the text for.
78+
* @param beforeCount The number of characters before the node to retrieve.
79+
* @param afterCount The number of characters after the node to retrieve.
80+
* @returns The text representing the AST node.
7681
*/
77-
getText(node?: object, beforeCount?: number, afterCount?: number): string;
82+
getText(node?: Node, beforeCount?: number, afterCount?: number): string;
7883
}
7984

8085
export interface MarkdownRuleVisitor

tests/types/types.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import markdown, {
2+
IMarkdownSourceCode,
23
MarkdownNode,
34
MarkdownRuleVisitor,
45
ParentNode,
56
RootNode,
7+
SourceLocation,
68
TextNode,
79
type RuleModule,
810
} from "@eslint/markdown";
@@ -45,16 +47,22 @@ typeof processorPlugins satisfies {};
4547

4648
const rule: RuleModule = {
4749
create({ sourceCode }): MarkdownRuleVisitor {
50+
sourceCode satisfies IMarkdownSourceCode;
51+
52+
sourceCode.ast satisfies RootNode;
53+
sourceCode.lines satisfies string[];
54+
4855
return {
4956
// Root selector
5057
root(node) {
5158
node satisfies RootNode;
5259
},
5360

54-
// Known node selector, sourceCode.getText() used in visitor
61+
// Known node selector, sourceCode methods used in visitor
5562
text(node) {
5663
node satisfies TextNode;
57-
sourceCode.getText(node);
64+
sourceCode.getText(node) satisfies string;
65+
sourceCode.getLoc(node) satisfies SourceLocation;
5866
},
5967

6068
// Known node selector with parent

0 commit comments

Comments
 (0)