Skip to content

Commit ec2846b

Browse files
authored
fix: replace IMarkdownSourceCode with MarkdownSourceCode (#336)
* fix: update type reference for `MarkdownRuleDefinition` * wip: fix CI failure * wip: fix CI issues * wip: remove `IMarkdownSourceCode` interface and replace it with `MarkdownSourceCode` * wip: export `TextSourceCode` * wip: replace `MarkdownTextSourceCodeOptions` with `SourceCodeBaseTypeOptions` * wip: add types to generic
1 parent 6bc0765 commit ec2846b

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"prettier": "^3.3.3",
7777
"rollup": "^4.19.0",
7878
"rollup-plugin-copy": "^3.5.0",
79+
"rollup-plugin-delete": "^3.0.1",
7980
"typescript": "^5.5.4",
8081
"yorkie": "^2.0.0"
8182
},

rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy from "rollup-plugin-copy";
2+
import del from "rollup-plugin-delete";
23

34
export default {
45
input: "src/index.js",
@@ -10,6 +11,7 @@ export default {
1011
},
1112
],
1213
plugins: [
14+
del({ targets: "dist/*" }),
1315
copy({
1416
targets: [{ src: "src/types.ts", dest: "dist/esm" }],
1517
}),

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { processor } from "./processor.js";
1111
import { MarkdownLanguage } from "./language/markdown-language.js";
12+
import { MarkdownSourceCode } from "./language/markdown-source-code.js";
1213
import recommendedRules from "./build/recommended-config.js";
1314
import rules from "./build/rules.js";
1415

@@ -139,3 +140,4 @@ const plugin = {
139140
recommendedPlugins.markdown = processorPlugins.markdown = plugin;
140141

141142
export default plugin;
143+
export { MarkdownSourceCode };

src/language/markdown-source-code.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ import { findOffsets } from "../util.js";
2626
/** @typedef {import("@eslint/core").File} File */
2727
/** @typedef {import("@eslint/core").TraversalStep} TraversalStep */
2828
/** @typedef {import("@eslint/core").VisitTraversalStep} VisitTraversalStep */
29-
/** @typedef {import("@eslint/core").TextSourceCode} TextSourceCode */
3029
/** @typedef {import("@eslint/core").ParseResult<RootNode>} ParseResult */
3130
/** @typedef {import("@eslint/core").SourceLocation} SourceLocation */
3231
/** @typedef {import("@eslint/core").SourceRange} SourceRange */
3332
/** @typedef {import("@eslint/core").FileProblem} FileProblem */
3433
/** @typedef {import("@eslint/core").DirectiveType} DirectiveType */
3534
/** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
36-
/** @typedef {import("../types.ts").IMarkdownSourceCode} IMarkdownSourceCode */
35+
/**
36+
* @typedef {import("@eslint/core").TextSourceCode<Options>} TextSourceCode<Options>
37+
* @template {SourceCodeBaseTypeOptions} [Options=SourceCodeBaseTypeOptions]
38+
*/
39+
/** @typedef {import("../types.ts").MarkdownLanguageOptions} MarkdownLanguageOptions */
40+
/** @typedef {import("../types.ts").SourceCodeBaseTypeOptions} SourceCodeBaseTypeOptions */
3741

3842
//-----------------------------------------------------------------------------
3943
// Helpers
@@ -137,7 +141,7 @@ function extractInlineConfigCommentsFromHTML(node) {
137141

138142
/**
139143
* Markdown Source Code Object
140-
* @implements {IMarkdownSourceCode}
144+
* @implements {TextSourceCode<{LangOptions: MarkdownLanguageOptions, RootNode: RootNode, SyntaxElementWithLoc: MarkdownNode, ConfigNode: { value: string; position: SourceLocation }}>}
141145
*/
142146
export class MarkdownSourceCode extends TextSourceCodeBase {
143147
/**

src/types.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
SourceLocation,
2222
TextSourceCode,
2323
} from "@eslint/core";
24+
import type { MarkdownSourceCode } from "./index.js";
2425

2526
//------------------------------------------------------------------------------
2627
// Helpers
@@ -73,29 +74,13 @@ export interface MarkdownLanguageOptions extends LanguageOptions {
7374
export type MarkdownLanguageContext = LanguageContext<MarkdownLanguageOptions>;
7475

7576
/**
76-
* The `SourceCode` interface for Markdown files.
77+
* Generic options for the `SourceCodeBase` type.
7778
*/
78-
export interface IMarkdownSourceCode
79-
extends TextSourceCode<{
80-
LangOptions: MarkdownLanguageOptions;
81-
RootNode: Root;
82-
SyntaxElementWithLoc: Node;
83-
ConfigNode: { value: string; position: SourceLocation };
84-
}> {
85-
/**
86-
* Gets the entire source text split into an array of lines.
87-
* @returns The source text as an array of lines.
88-
*/
89-
get lines(): Array<string>;
90-
91-
/**
92-
* Gets the source code for the given node.
93-
* @param node The AST node to get the text for.
94-
* @param beforeCount The number of characters before the node to retrieve.
95-
* @param afterCount The number of characters after the node to retrieve.
96-
* @returns The text representing the AST node.
97-
*/
98-
getText(node?: Node, beforeCount?: number, afterCount?: number): string;
79+
export interface SourceCodeBaseTypeOptions {
80+
LangOptions: LanguageOptions;
81+
RootNode: unknown;
82+
SyntaxElementWithLoc: unknown;
83+
ConfigNode: unknown;
9984
}
10085

10186
export interface MarkdownRuleVisitor
@@ -121,7 +106,7 @@ export type MarkdownRuleDefinition<
121106
// Language specific type options (non-configurable)
122107
{
123108
LangOptions: MarkdownLanguageOptions;
124-
Code: IMarkdownSourceCode;
109+
Code: MarkdownSourceCode;
125110
Visitor: MarkdownRuleVisitor;
126111
Node: Node;
127112
} & Required<

tests/types/types.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import markdown, {
2-
IMarkdownSourceCode,
2+
MarkdownSourceCode,
33
MarkdownNode,
44
MarkdownRuleDefinition,
55
MarkdownRuleVisitor,
@@ -48,7 +48,7 @@ typeof processorPlugins satisfies {};
4848

4949
(): RuleModule => ({
5050
create({ sourceCode }): MarkdownRuleVisitor {
51-
sourceCode satisfies IMarkdownSourceCode;
51+
sourceCode satisfies MarkdownSourceCode;
5252

5353
sourceCode.ast satisfies RootNode;
5454
sourceCode.lines satisfies string[];

0 commit comments

Comments
 (0)