Skip to content

Rule proposal: Warn when deprecated APIs are used (eslint-plugin-deprecation) #8988

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
6 tasks done
JoshuaKGoldberg opened this issue Apr 24, 2024 · 7 comments · Fixed by #9783
Closed
6 tasks done
Labels
enhancement: new plugin rule New rule request for eslint-plugin 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 team assigned A member of the typescript-eslint team should work on this.

Comments

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Apr 24, 2024

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Re-opening #1223: being able to lint against usage of an API marked as @deprecated is a common request for TypeScript developers. It was a TSLint rule back in those days, and now is provided primarily by https://github.com/gund/eslint-plugin-deprecation. eslint-plugin-deprecation existing is why #1223 was closed by a docs change pointing folks externally.

But! Since then:

Proposal: let's write a new implementation of a deprecation rule in this repo?

Fail Cases

/** @deprecated */
declare function v1(): unknown;

v1();

Pass Cases

declare function v2(): unknown;

v2();

Additional Info

Note that the licensing here is tricky. https://github.com/gund/eslint-plugin-deprecation includes the following README.md note:

This rule was originally ported from the SonarJS repository.

...and is licensed under the GNU Lesser General Public License.

We need to be very sure that if this issue is accepted, any code added to our project is not based on the GNU license, and is at most licensed under MIT. If this is accepted, I think a member of the typescript-eslint team should work on it.

Other references of related licensed rules are:

cc @gund - you've done a great job for a while of keeping eslint-plugin-deprecation afloat ❤️. If you have any thoughts here, that'd be great.

@JoshuaKGoldberg JoshuaKGoldberg added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look enhancement: new plugin rule New rule request for eslint-plugin labels Apr 24, 2024
@JoshuaKGoldberg JoshuaKGoldberg added the team assigned A member of the typescript-eslint team should work on this. label Jun 3, 2024
@JoshuaKGoldberg JoshuaKGoldberg removed the triage Waiting for team members to take a look label Jul 9, 2024
@Zamiell
Copy link
Contributor

Zamiell commented Aug 12, 2024

Josh, I see that back in June, you reiterated that you wanted a core TSESLint member to work on this. However, in the meantime, TSESLint 8 was released, and eslint-plugin-deprecation is no longer compatible, so the need to have this rule working is much greater nowadays. (i.e. people are blocked from upgrading or have to chose to drop deprecation linting altogether)

In order to try and help, I implemented a short and sweet version of the rule, coming in at only 63 lines:
Zamiell@4c44df0

My short version probably doesn't cover as many cases as the 298 line version created by luca-script, but it might be easier to maintain. Ultimately, I would just like some version the rule to exist in TSESLint sooner than later. Any thoughts?

@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Aug 12, 2024

Yeah this is really painful 😬 I've had to disable the rule in my own projects and know a lot of other folks have had to choose between sticking with typescript-eslint 7 / ESLint 8 or losing the rule too, as you're saying.

Edit: or, as @ST-DDT notes, using @eslint/compat.

I actually started prototyping a reimplementation of the rule myself last week, but haven't had the time to get it to completion. The v8 release and other ESLint v9 compatibility work did a number on our schedules. #9783 has the work so far. It's on my todolist for this week to try to clean it up and get it in review.

@ST-DDT
Copy link
Contributor

ST-DDT commented Aug 12, 2024

Yeah this is really painful 😬 I've had to disable the rule in my own projects and know a lot of other folks have had to choose between sticking with typescript-eslint 7 / ESLint 8 or losing the rule too, as you're saying.

You can enable the rule using the eslint compatibility package.

https://github.com/faker-js/faker/blob/bb1a73ca3a0ac3b3cf7a0ec25740bf6e872887ae/eslint.config.js#L138

import { fixupPluginRules } from '@eslint/compat';
import eslintPluginDeprecation from 'eslint-plugin-deprecation';

...

  {
    plugins: {
      deprecation:
        // https://github.com/gund/eslint-plugin-deprecation/issues/78
        // @ts-expect-error: Types aren't matching, but it works
        fixupPluginRules(eslintPluginDeprecation),
    },
    rules: {
      'deprecation/deprecation': 'error',
    },
  },

I would prefer a solution that works out of the box though.

@karlhorky
Copy link

@JoshuaKGoldberg thanks for @typescript-eslint/no-deprecated in typescript-eslint@8.3.0, just migrated from eslint-plugin-deprecation and we've observed it working 👍

Feels quite a bit slower than eslint-plugin-deprecation in the first runs, but maybe that's a temporary problem.

@BurningEnlightenment
Copy link

I'm a bit late to the party, but would it be possible to add an option to differentiate between libraries and user code? I find it very useful to flag and address deprecated APIs during the dependency upgrade cycle, but if it flags deprecated APIs from my own code base the moment I annotate them as such, I'd effectively need to go ahead and remove the API entirely. Should I open a feature request for this?

@Zamiell
Copy link
Contributor

Zamiell commented Aug 27, 2024

@BurningEnlightenment Yes, please open a new issue for a feature request.

@bradzacher
Copy link
Member

As per our contributing guidelines please open new issues for feature requests or bug reports. Or if you'd like to chat with us please visit our discord.

https://typescript-eslint.io/contributing/issues

@typescript-eslint typescript-eslint locked and limited conversation to collaborators Aug 27, 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin 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 team assigned A member of the typescript-eslint team should work on this.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants