8000 Bug: no-unused-vars does not account for references in JsDoc · Issue #8902 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: no-unused-vars does not account for references in JsDoc #8902

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

Closed
4 tasks done
matthieusieben opened this issue Apr 11, 2024 · 5 comments
Closed
4 tasks done

Bug: no-unused-vars does not account for references in JsDoc #8902

matthieusieben opened this issue Apr 11, 2024 · 5 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@matthieusieben
Copy link
matthieusieben commented Apr 11, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

not-applicable

Repro Code

// a.ts
export type Foo = { bar: 42 }
// b.ts
import { Foo } from './a.js'

/**
 * @see {@link Foo.bar}
 */
export function example () {}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unused-vars": ["error"],
  },
};

tsconfig

{
  "compilerOptions": {
  }
}

Expected Result

Foo is used in JsDoc, and correctly references the original definition in vs-code (alt + click goes to the definition)

Actual Result

@typescript-eslint/no-unused-vars considers this is an unused var, while typescript does not.

Additional Info

Note that if the reference is removed from the JSdoc, typescript starts complaining about an unused var as well.

@matthieusieben matthieusieben added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 11, 2024
@matthieusieben matthieusieben changed the title Bug: [rule name here] <short description of the issue> Bug: no-unused-vars does not account for references in JsDoc Apr 11, 2024
@auvred
Copy link
Member
auvred commented Apr 11, 2024

Duplicate of #5017, #6967, #7944, #8258.

@auvred auvred closed this as completed Apr 11, 2024
@auvred auvred added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels Apr 11, 2024
@auvred auvred closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
@matthieusieben
Copy link
Author
matthieusieben commented Apr 11, 2024

Is there any chance to re-consider this ? I get that @bradzacher thinks "JSDoc is not real code" but the typescript compiler actually disagrees with this. It is a shame that typescript-eslint does not follow the conventions abopted typescript...

@Josh-Cena
Copy link
Member

@matthieusieben: ts-eslint models the "TypeScript language" part of typescript. There's also a "JavaScript linting" part of typescript which includes JSDoc and lots of heuristic-based inference to make "idiomatic JS" work without any rewriting. We never explicitly have support for this part. Similarly, TypeScript has cross-module checking features, but we don't, because it's delegated to eslint-plugin-import. For JSDoc, you would want to use eslint-plugin-jsdoc instead.

@matthieusieben
Copy link
Author

Thanks for the detailed explanation. These tools are so complicated to get working (e.g. one would assume that typescript-eslint is on par feature wise with typescript), I find it a missed opportunity. But that's just me (and probably a few other from those other issues). Thanks for your work anyways.

@bradzacher
Copy link
Member

JSDoc is not real code

JSDoc is a very, very loosely defined spec for how it works. It's not even really a spec - it's more of a convention. There's a lot of ambiguity in it and TS does not enforce that you write it in a specific way - it just loosely handles the comments as best it can.

When we parse TS code we use TS's parser. Code is well defined with a grammar and there's little ambiguity (there is technically some but the TS parser handles and hides that ambiguity) and we get one concrete AST representation for the file. We don't need to worry about problems like "what if someone provides two return type annotations?" Cos you cannot provide two return type annotations on a function that's a syntax error to even try it.

OTOH JSDoc comments do not have the same concrete representation.
For example this is a valid annotation:

/**
 * @returns {string}
 * @returns {number}
 * @return {boolean}
 * @return {null}
 */

What does it mean? Who knows really - the interpretation is left up to the consumer.
For TS it will error on this comment and mark the last 3 as an error with 'returns' tag already specified. However TS emits a JSDoc AST for this and that AST contains FOUR JSDocReturnTag nodes.

So you can see how this gets complicated - what do we do here? Well we have to research and understand exactly how JSDoc is handled by TS internally so that we can model that exact same behaviour. That means every TS release we also need to review TS's JSDoc handling again to determine if anything changed.

It's a huge maintenance burden for us as volunteer maintainers.

So instead we have chosen to not handled JSDoc at all and instead, as Josh mentioned, we tell people to use eslint-plugin-jsdoc which is built in its own way with its own rules and parser for handling JSDoc.

I.e. instead of us trying to understand JSDoc ourselves whilst we're working to understand TS - we leave that responsibility to a separate project which has the knowledge and resources that can do that. This separation of concerns creates a higher quality result with less stress/burden on any one group and is a core tenet of how the ESLint ecosystem has evolved and grown.


I definitely understand the reason behind wanting this - but ultimately it's a very niche usecase within the TypeScript ecosystem. A very, very small fraction of people annotate JSDoc this way.

Which is why it's not worth us as bandwidth-limited, volunteer maintainers to dedicate time to supporting this. The cost:value ratio isn't there for us when eslint-plugin-jsdoc is there for people to opt-in to support these usecases.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
@bradzacher bradzacher marked this as a duplicate of #11208 May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants
0