Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a "no-undefined-types" rule #423

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kraenhansen
Copy link

@kraenhansen kraenhansen commented Aug 30, 2024

This fixes #348 and #349 by adding a new "no-undefined-types" rule to the eslint-plugin-tsdoc package.

NOTE: This is currently in draft as I want a bit of feedback before sinking more time into this.

I see two issues with the implementation as is:

Incorrect scoping

Comment are read using sourceCode.getAllComments(), which means the node to which the comment related gets lost and this entails that any identifiers used in {@link } tags gets resolved relative to the global scope (and its decedents). I am contemplating adding more granular "visitors" to to the RuleListener returned from the rule's create method, but that would probably elevate the complexity quite a bit.

Determining if a type is defined, means running the TypeScript type-checker

Take this example

foo.ts

class MyClass {
    foo() {}
}

bar.ts

/**
 * A {@link MyClass.foo} referencing a member of a class which can't be read out of the AST of the file itself.
 */
const bar = "whatever";

The easiest way would probably be to take an optional peer dependency on @typescript-eslint/utils and implement a typed rule.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eslint-plugin-tsdoc: Rule to mark types referenced through {@link} and {@inheritDoc} as used
1 participant