Skip to content

[deprecation] Warns when deprecated APIs are used. #1223

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
htho opened this issue Nov 18, 2019 · 14 comments · Fixed by #1611
Closed

[deprecation] Warns when deprecated APIs are used. #1223

htho opened this issue Nov 18, 2019 · 14 comments · Fixed by #1611
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

Comments

@htho
Copy link

htho commented Nov 18, 2019

Repro

{
  "rules": {
    "@typescript-eslint/deprecation": ["warn"]
  }
}
// CASE 1: for functions
/** @deprecated use f2 instead */
function f1(): void {return;}
function f2(): void {return;}

f1(); // WARN: "f1 is deprecated: use f2 instead

// CASE 2: for interfaces
interface Test {
  /** @deprecated use b instead */
  public a?: string;
  public b?: string;
}

const x: Test = {
  a: "foo"; // WARN: "Test.a is deprecated: use b instead
}

Expected Result
In both cases there should be a warning, that the function or property are depricated.

Actual Result
The @depricated comments are ignored.

Additional Info
There is a TSLint Rule: deprication and a long discussion at the TypeScript Bugtracker

I did not check the implementation for TSLint, but there are many things to consider. They should be configurable.

  1. For interfaces a depricated property must be optional (otherwise one could not not use the property)
  2. There should be a warning if a private or protected property is marked as depricated. (at least private properties should be updated as soon as a property is depricated)
  3. A @depricated tag must be followed by an explanation and/or alternative.
@htho htho added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 18, 2019
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for team members to take a look labels Nov 18, 2019
@ark120202
Copy link

Related: https://github.com/SonarSource/SonarJS/issues/1432, SonarSource/SonarJS#1715

Later we can contribute this rule to typescript-plugin for eslint.

@gund
Copy link
Contributor

gund commented Feb 15, 2020

Now that this rule was implemented and merged in SonarJS - are there any plans to bring this to typescript-eslint?

@bradzacher
Copy link
Member

We don't have any. If someone wants to PR it, we would be happy to review it.

@gund
Copy link
Contributor

gund commented Feb 16, 2020

I believe it's just a matter of copy-pasting this rule from sonarjs repo?

@bradzacher
Copy link
Member

It's not quite as simple as a copy paste job, as that code has its own licence.
Someone needs to discuss with the maintainers, and make sure they're okay with the port.

Also, the code would have to be updated to fit our coding standards in this repo, as the style is reasonably different.

@gund
Copy link
Contributor

gund commented Feb 16, 2020

Well SonarJS repo uses LGPL which allows any redistribution of source code but under either GPL or LGPL licence. Which is not gonna work because this repo is using BSD like license.

However, it is possible to port that rule into eslint plugin (say eslint-plugin-deprecation) and licence it under LGPL and then use it here as external library.

Maybe it makes more sense to just create another repo for this rule?

@bradzacher
Copy link
Member

If someone wants to port the rule to an independent eslint plugin, feel free!
If someone wants to simply document how to use the sonar rule, they can do that instead.
If someone wants to independently implement the rule based on tslint's implementation, they can do that too.

@gund
Copy link
Contributor

gund commented Feb 16, 2020

Alright, I've ported the rule into separate plugin https://github.com/gund/eslint-plugin-deprecation

@bradzacher
Copy link
Member

happy if you update the docs to point at your plugin, and then we can consider this closed.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md#maintainability

(note the docs currently point at an eslint-plugin-import rule, which is not as good as a rule using typescript types, like your ported rule does)

@webmaster128
Copy link

Thank you @gund!

If someone stumbles upon this, I think t would still be cool to have a port of the tslint implementation (as suggested by @bradzacher) in this repo due to licensing reasons and for fewer dependencies.

@nicmosc

This comment was marked as off-topic.

@nicmosc

This comment was marked as off-topic.

@gund

This comment was marked as off-topic.

@bradzacher

This comment was marked as off-topic.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Mar 6, 2020
@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants