Skip to content

The no-deprecated-api rule should adhere to the targeted Node.js version #141

Closed
@sindresorhus

Description

@sindresorhus

Same as the no-unsupported-features rule: https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features/es-syntax.md#configured-nodejs-version-range

If my package has "engines": { "node": ">=6" } it should not show:

assert.deepEqual was deprecated since v10.0.0. Use assert.deepStrictEqual or assert.strict.deepEqual instead.  node/no-deprecated-api

As there's no way for me to use the new API, since it's only available in Node.js 10 and I need to support Node.js 6 users. It should only become an error when my engine is >=10.

Activity

mysticatea

mysticatea commented on Nov 5, 2018

@mysticatea
Owner

Thank you for the report.

This is intentional.
If you don't care the future deprecated APIs, you can disable the rule because the deprecated APIs will not be deleted on the current version.

In assert.deepEqual case, you can use assert.deepStrictEqual. The deprecated APIs are the four assert.deepEqual, assert.equal, assert.notDeepEqual, and assert.notEqual.

sindresorhus

sindresorhus commented on Nov 5, 2018

@sindresorhus
Author

Then I think you should add another metadata field of when the replacement API was added, so you at least don't report the error if it's impossible to switch.

For example, with:

assert.deepEqual was deprecated since v10.0.0. Use assert.deepStrictEqual or assert.strict.deepEqual instead.

I now have to manually look up when each of these APIs were introduced. Would be nice if either:

  • The message described in which Node.js version each of the replacement methods were introduced.
  • Only show the replacement methods that works for my engine target, and if none, don't show the message.

For example, in this case, assert.strict.deepEqual was introduced in Node.js 9, so it would not be shown in the message, since my target is >=6.

mysticatea

mysticatea commented on Nov 5, 2018

@mysticatea
Owner

That makes sense.

pward123

pward123 commented on Dec 9, 2018

@pward123

+1 for Only show the replacement methods that works for my engine target, and if none, don't show the message.

julien-f

julien-f commented on Mar 27, 2019

@julien-f

Hi, would be nice if this would get fixed.

I'm not familiar with ESLint nor eslint-plugin-node code's but it looks like it shouldn't be too hard, simply enhance this check to compare it to current target Node version:

if (!ignoredGlobalItems.has(name)) {

@mysticatea do you have any pointers?

mysticatea

mysticatea commented on Mar 29, 2019

@mysticatea
Owner

Hi. Thank you to be interested in.

Yes. You are right. I think this feature needs two steps to implement:

  1. Replace the replacedBy property such as lib/rules/no-deprecated-api.js#L18-L19 to an array that has objects that has a display name and supported version.
  2. Get the configured node versions with lib/util/get-configured-node-version.js and filter the replacedBy array by the configured versions.
julien-f

julien-f commented on Apr 8, 2019

@julien-f

@mysticatea I'm sorry I don't have the time to do this for now, I'll take a look when I can if no one have have take care of this yet.

added a commit that references this issue on May 23, 2019
fd9d19d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sindresorhus@julien-f@mysticatea@pward123

      Issue actions

        The `no-deprecated-api` rule should adhere to the targeted Node.js version · Issue #141 · mysticatea/eslint-plugin-node