Skip to content

refactor: migrate type declarations to use the @import syntax #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented May 9, 2025

Prerequisites checklist

What is the purpose of this pull request?

Hello,

In this PR, I’ve migrated the type declarations to use the @import syntax and added support for MessageIds.

This change was briefly discussed in #336 (comment).

I believe this migration will help ensure consistent type declarations across plugin repositories.

However, one concern I have is that the type module path for RuleModule and MarkdownRuleDefinition has changed from @eslint/markdown to @eslint/markdown/types. While this path is already used in the CSS and JSON plugins, I’m worried it could introduce a breaking change.

I’d appreciate any suggestions on how to avoid making this a breaking change, if possible.

What changes did you make? (Give an overview)

I’ve migrated the type declarations to use the @import syntax and added support for MessageIds.

Related Issues

ref: #336 (comment)

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

Prerequisite

@lumirlumir lumirlumir marked this pull request as draft May 9, 2025 06:59
@lumirlumir lumirlumir added this to Triage May 9, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage May 9, 2025
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage May 9, 2025
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've followed the script from JSON.

@lumirlumir lumirlumir marked this pull request as ready for review May 9, 2025 11:26
@lumirlumir lumirlumir requested a review from fasttime May 9, 2025 11:27
@lumirlumir lumirlumir changed the title refactor: align rule typedefs with conventions from other plugins refactor: migrate type declarations to use the @import syntax May 9, 2025
@lumirlumir lumirlumir self-assigned this May 9, 2025
@lumirlumir lumirlumir marked this pull request as draft May 10, 2025 08:45
@lumirlumir
Copy link
Member Author

I've updated this PR to incorporate the latest changes from #383.

There are no longer any breaking changes in this PR.

@lumirlumir lumirlumir marked this pull request as ready for review June 21, 2025 11:52
@lumirlumir lumirlumir requested review from nzakas and snitin315 June 21, 2025 11:52
@lumirlumir
Copy link
Member Author

The missing type checking issue reported in #432 has been addressed in this PR, so type checking now works as expected for all files.

* @typedef {import("./types.ts").MarkdownRuleDefinition<Options>} MarkdownRuleDefinition<Options>
* @template {Partial<import("./types.ts").MarkdownRuleDefinitionTypeOptions>} [Options={}]
* @import { Linter } from "eslint";
* @import { MarkdownRuleVisitor as MRV, MarkdownRuleDefinition as MRD, MarkdownRuleDefinitionTypeOptions } from "./types.js";
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use the regular names? I think that makes things a lot easier to understand.

Suggested change
* @import { MarkdownRuleVisitor as MRV, MarkdownRuleDefinition as MRD, MarkdownRuleDefinitionTypeOptions } from "./types.js";
* @import { MarkdownRuleVisitor , MarkdownRuleDefinition, MarkdownRuleDefinitionTypeOptions } from "./types.js";

Copy link
Member Author

@lumirlumir lumirlumir Jun 23, 2025

Choose a reason for hiding this comment

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

I initially tried using the original name, but without an alias, it results in a duplicate type definitions error when running the tsc command, since the same name is declared again in the following lines using the @typedef syntax.

(This redeclaration is intentional, for the reason I mentioned here.)

However, if we decide to remove these types from the @eslint/markdown export path and move them to the @eslint/markdown/types path, then these lines can be safely removed. (ref: here)

Comment on lines +25 to +29
* @typedef {MRV} MarkdownRuleVisitor
*/

/**
* @typedef {MRD<Options>} MarkdownRuleDefinition<Options>
Copy link
Member

Choose a reason for hiding this comment

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

Then I don't think we need these.

Copy link
Member Author

@lumirlumir lumirlumir Jun 23, 2025

Choose a reason for hiding this comment

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

This is because the type tests in types.test.js currently depend on these type definitions.
So, removing them in this PR would introduce a breaking change:

import markdown, {
MarkdownSourceCode,
MarkdownRuleDefinition,
MarkdownRuleVisitor,
type RuleModule,
} from "@eslint/markdown";

Personally, I think it would be better to keep this PR non-breaking and create a separate PR to remove these types and move them under the @eslint/markdown/types path when importing.

Both the JSON and CSS plugins follow a similar approach, so it would make sense to organize the types this way:

If it’s acceptable, I can open a separate PR with the breaking changes by tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

4 participants