Skip to content
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

no-restricted-imports does not show which member is deprecated or allow for message customization per member #14342

Closed
RyanCCollins opened this issue Apr 19, 2021 · 4 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon
Projects

Comments

@RyanCCollins
Copy link

RyanCCollins commented Apr 19, 2021

What rule do you want to change?
no-restricted-imports

The DX of this rule does not indicate which member is deprecated when using importNames, nor does it allow message customization per member in the importNames list. I would like the rule to handle this to improve the developer experience and make it useful for deprecations across a distributed organization.

Does this change cause the rule to produce more or fewer warnings?
More potentially

How will the change be implemented? (New option, new default behavior, etc.)?
There are a few options:

  1. The configuration allows multiple paths with the same name so that you can have different custom messages for specific importName members.
  2. The configuration allows a list of messages that map to the importNames.

Please provide some example code that this change will affect:

For #1 above:

    'no-restricted-imports': [2, {
      'paths': [
        {
          'name': '@someorg/api',
          'importNames': [
            'fetchThings',
          ],
          'message': 'fetchThings has been deprecated as of April 19, please use fetchWidgets instead.'
        },
        {
          'name': '@someorg/api',
          'importNames': [
            'postThings',
          ],
          'message': 'postThings has been deprecated as of April 19, please use getWidgets instead.'
        },
        {
          'name': '@someorg/api',
          'importNames': [
            'parseCSV',
          ],
          'message': 'parseCSV has been deprecated as of April 18 and will not be replaced.'
        },
      ],
    }],

For #2 above:

    'no-restricted-imports': [2, {
      'paths': [
        {
          'name': '@someorg/api',
          'importNames': [
            'fetchThings',
            'postThings',
            'parseCSV',
          ],
          'messages': [
            'fetchThings has been deprecated as of April 19, please use fetchWidgets instead.',
            'postThings has been deprecated as of April 19, please use getWidgets instead.',
            'parseCSV has been deprecated as of April 18 and will not be replaced.',
          ]
        },
      ],
    }],

What does the rule currently do for this code?
For #1, only the last path in the list works, the others are ignored.
For #2, it breaks because messages is not recognized.

What will the rule do after it's changed?
It will allow for specific messages per member so that the warning is specific to the member, providing better user/developer experience.

Are you willing to submit a pull request to implement this change?
I wish I was able to, but unfortunately don't have the bandwidth at the moment. We rely on this tool for work and would really appreciate this change being implemented. I will attempt it in a few months if not.

@RyanCCollins RyanCCollins added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Apr 19, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Apr 19, 2021
@RyanCCollins RyanCCollins changed the title no-restricted-imports does not show which member is deprecated or allow for message customization per-member no-restricted-imports does not show which member is deprecated or allow for message customization per member Apr 19, 2021
@RyanCCollins
Copy link
Author

By the way, if I am misusing this rule and there is a way to do this currently, I would much appreciate some advice! Thank you!

@nzakas
Copy link
Member

nzakas commented Apr 20, 2021

Have you checked the discussion on these issues?

#14220
#14274

@RyanCCollins
Copy link
Author

RyanCCollins commented Apr 20, 2021

Have you checked the discussion on these issues?

#14220

#14274

Awesome, the no-restricted-syntax looks like a good solution. Thank you @nzakas!

That said, I would still like to be on the record to say that I expected no-restricted-import to have a way to specify separate messages per member. Otherwise, there is no way the consumer would know which specific members are deprecated from a large module that has only a few members.

@nzakas
Copy link
Member

nzakas commented Apr 21, 2021

Noted, given that it’s already tracked in another issue, I’m going to close this one.

@nzakas nzakas closed this as completed Apr 21, 2021
Triage automation moved this from Needs Triage to Complete Apr 21, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Oct 19, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants