Skip to content

Conversation

@jaymarvelz
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request?

This PR updates MarkdownRuleVisitor so that the parent parameter has a precise type for non-root nodes.

What changes did you make? (Give an overview)

  • Added ParentOf<T> utility to infer correct parent types.
  • For non-root nodes, the parent parameter is now precisely typed; for root, only the node is passed.
  • Introduced MarkdownSyntaxElement, consistent with the CSS and JSON plugins.
  • Updated MarkdownSourceCode to reference MarkdownSyntaxElement.

Related Issues

Is there anything you'd like reviewers to focus on?

@eslintbot eslintbot added this to Triage Oct 29, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 29, 2025
* - For nodes, include every parent `P` where `T` is assignable to one of
* `P['children'][number]` (i.e. `T` can appear in `P.children`).
*/
type ParentOf<T extends MarkdownNode> = T extends Root
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be static for performance and simplicity reasons as the parent of the various markdown nodes should be easily groupable (inside paragraph (e.g. Strong and Emphasis) and root (e.g. Heading and Code).

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Also, deeply nested conditional types make the code somewhat unclear to me.

@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Oct 31, 2025
Copy link
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

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

Hi, @jaymarvelz

Could you share any PRs or issues that motivated this change, and also update the PR description to include the bug templates?

I'm having trouble understanding what's happening here.


Also, if this PR includes bug fixes, could you update tests/types/types.test.ts to verify the behavior before and after the change?

Comment on lines -15 to -39
Definition,
Emphasis,
Heading,
Html,
Image,
ImageReference,
InlineCode,
Link,
LinkReference,
List,
ListItem,
Paragraph,
Root,
Strong,
Text,
ThematicBreak,
// Extensions (GFM)
Delete,
FootnoteDefinition,
FootnoteReference,
Table,
TableCell,
TableRow,
// Extensions (front matter)
Yaml,
Copy link
Member

Choose a reason for hiding this comment

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

Originally, there was consensus not to use the RootContent type.

Currently, the Nodes type is equivalent to Root | RootContent, so I'm not sure that using Nodes here is the desired approach.

I personally prefer not to use the Nodes type and to keep the original enumeration style.

Ref: #334 (comment)

@lumirlumir lumirlumir moved this from Implementing to Evaluating in Triage Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Evaluating

Development

Successfully merging this pull request may close these issues.

3 participants