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: disable comments do not work for individual named imports #12282

Closed
OliverJAsh opened this issue Sep 18, 2019 · 5 comments · Fixed by #12711
Closed

no-restricted-imports: disable comments do not work for individual named imports #12282

OliverJAsh opened this issue Sep 18, 2019 · 5 comments · Fixed by #12711
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@OliverJAsh
Copy link
Contributor

Tell us about your environment

  • ESLint Version: 5.16.0
  • Node Version: 10.16.3
  • npm Version: 6.11.3

What parser (default, Babel-ESLint, etc.) are you using?

Please show your full configuration:

Configuration
{
  rules: {
    'no-restricted-imports': [
      'error',
      {
        name: 'lodash',
        importNames: ['zip'],
      },
    ],
  },
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import {
  zip, // eslint-disable-line no-restricted-imports
  pickBy,
} from 'lodash';
eslint

What did you expect to happen?
No error

What actually happened? Please include the actual, raw output from ESLint.
Error

'lodash' import is restricted from being used.

To workaround this you must disable the rule for the whole import statement. However this is not ideal because this could accidentally silence errors that we want to hear about, for other named imports:

// eslint-disable-next-line no-restricted-imports
import {
  zip,
  pickBy,
} from 'lodash';

Are you willing to submit a pull request to fix this bug?

@OliverJAsh OliverJAsh added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Sep 18, 2019
@g-plane g-plane added accepted There is consensus among the team that this change meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Sep 27, 2019
@g-plane
Copy link
Member

g-plane commented Sep 27, 2019

I can reproduce this bug at our ESLint Demo.

I think the rule should only report the restricted items. For the example from @OliverJAsh , the rule should report zip only.

@kaicataldo kaicataldo added help wanted The team would welcome a contribution from the community for this issue Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Sep 30, 2019
@kaicataldo kaicataldo removed the Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ label Nov 19, 2019
@eclectrony
Copy link

Just so that I understand this rule more clearly:

If we didn't have the eslint-disable-line comment, should "pickBy" still be allowed to be imported even as "zip" is disallowed, or should "import { zip, pickBy, } from 'lodash';" be disallowed entirely because of the presence of "zip" in the import statement?

@OliverJAsh
Copy link
Contributor Author

The former

@mdjermanovic
Copy link
Member

It seems that reporting zip identifier node instead of the whole import statement would fix this issue. Would be probably nice to have a different error message in this case.

This change also means that the rule can now report multiple errors for the same import statement.

@fanich37
Copy link
Contributor

I'm gonna check it and send a PR till New Year.

@mdjermanovic mdjermanovic removed the help wanted The team would welcome a contribution from the community for this issue label Jan 13, 2020
kaicataldo pushed a commit that referenced this issue Jan 16, 2020
#12711)

* Process importNames

* Update test cases

* Fix rebase issue

* Update importNames logic

* Remove useless funcs, update tests

* Fix naming, fix everything imported w/o importNames

* Fix typo, fix specifier clause, fix rebase issue

* Process importNames with the same name

* Clean code in receiving specifier data, remove debug

* Fix type def, add empty name check, replace concat with push
montmanu pushed a commit to montmanu/eslint that referenced this issue Mar 4, 2020
…#12282) (eslint#12711)

* Process importNames

* Update test cases

* Fix rebase issue

* Update importNames logic

* Remove useless funcs, update tests

* Fix naming, fix everything imported w/o importNames

* Fix typo, fix specifier clause, fix rebase issue

* Process importNames with the same name

* Clean code in receiving specifier data, remove debug

* Fix type def, add empty name check, replace concat with push
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 16, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants