-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Rule to mark types in JSDoc as used #858
Comments
I personally prefer to use However, as a separate rule, not on by default, I'd be open to a PR, but am not really inclined to work on this, as again, I kind of view it as an anti-pattern, albeit an approach supported by TypeScript and I think meriting accommodation to projects which want to use it. |
I see. I do prefer to split the marking types as used feature into a separate rule, because then it would be purely syntactical (detecting /** @typedef {import('react').ComponentType} ComponentType */
/** @see {@link ComponentType} */
export type Foo = number;
|
Does this work for you? /** @typedef {typeof import(https://github.com/facebook/react/).ComponentType} ComponentType */ One admitted problem with the |
If I'm understanding this issue correctly, we would also like this feature as users of the Closure Compiler. We import types that are only used in JsDoc with
but we have to add I looked into doing this myself but we are moving towards es modules rather than closure modules so it wasn't worth implementing. But it would probably be useful to anyone using Closure Compiler. |
I also would appreciate seeing this implemented. My use-case is also for @link. It works great with VS Code, but without marking the variables as used, other ES Lint plugin grumble. |
As discovered in #507 (referenced also in #99), there was an eslint issue which pointed to an issue in marking variables used on program exit (i.e., as when examining comment nodes which are not attached to other AST). As per that issue, we might need to implement our own custom scope analysis in place of |
@brettz9 do you think something changed upstream that might make it more feasible to implement now? |
@kraenhansen : While there were some architectural changes on But if you were to do so, I think you'd have to disable/reimplement the TypeScript |
@brettz9: Looking more at the code, it looks to me as if the inline The parsed comment returned from eslint-plugin-jsdoc/src/iterateJsdoc.js Lines 1141 to 1149 in ec278a2
returns no
It looks like the tokenizers used by the underlying implementation is configurable: ... so I wonder if I'd have to implement that as well or if I'm missing something obvious 🤔 |
No, inline tags are indeed not tokenized. You'd have to get at them through the block or tag descriptions. Same with synonyms, |
Just to clarify: Would you consider that the responsibility of |
|
A good deal of this issue has now been resolved by #1062 and #1065. In short, there is no new rule, but new config ( Note that a variable will still not be marked as used if it is not among the defined types; if someone wants to trust all used types (even potentially misspelled ones), let us know. Thanks to @kraenhansen 's work, inline tags (such as However, as mentioned earlier, the ESLint API on which we still rely, |
On second thought, since the remaining issue, |
Motivation
Consider the following code:
TypeScript compiler understands that
ComponentType
is used in JSDoc and hence will not flag it as unused; TS-ESLint, on the other hand, reports@typescript-eslint/no-unused-vars
, because it's unaware of JSDoc.ESLint offers the
markVariableAsUsed
API that we can leverage to mark this type as used.eslint-plugin-react
takes advantage of this to markReact
as used when there's JSX. I don't know if it's portable to types, but hopefully it is.Current behavior
Reports error.
Desired behavior
Should not give
@typescript-eslint/no-unused-vars
Alternatives considered
This could also be an extension in TS-ESLint, but AFAIK they never handle JSDoc, so I decided to see if you would consider it first.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: