gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.08k stars 155 forks source link

An equivalent rule for unused imported `@typedef` similar to `no-unused-vars` #1165

Open leekahung opened 9 months ago

leekahung commented 9 months ago

Motivation

Hey everyone, been digging around the issues with regards to rules that relates to @typedef, but I don't see one so far or I might have missed it. If there is an issue already resolved or closed, would be happy to be linked to that. For now, I would like to open a feature request for the following.

At the moment, there's no way to check if an imported @typedef is no longer in use from existing rules in the plugin that's similar to an unused declared variable or unused library/package. ESLint does not produces no warnings or errors for @typedefs. Thus it up to the developer to manually spot and remove code that's no longer in use.

Current behavior

Currently, there are no warnings/errors for unused @typedefs from ESLint.

Desired behavior

With this new feature, it'll produce a warning or error for unused @typedefs from ESLint.

Alternatives considered

Creating a custom rule (no-unused-typedefs) specifically for @typedef

leekahung commented 9 months ago

Oh, never mind. Looks like it's possible to import JSDoc typedefs now.

Screen Shot 2023-10-21 at 15 40 43

Sorry for the inconvinence, I'll close this issue.

leekahung commented 9 months ago

Actually, it would seem like the problem would still persist if I were to import it instead with JavaScript since importing just JSDoc types wouldn't be supported.

For example, if I were to have:

// typedefs.js
/**
 * @exports foo
 * @typedef {object} foo
 * @property {string} bar
 */

exports.unused = {};

And import { foo } from "typedefs.js" in a different file to use it, the editor would pick it up, but would the browser would complain when starting a dev/production server since it's not exactly a "module" and you're not really importing "foo". The original idea from the description might still be better.