question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
fanich37commented, Dec 24, 2019

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

0reactions
mdjermanoviccommented, Dec 3, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - ESLint - Pluggable JavaScript Linter
This rule allows you to specify imports that you don't want to use in your application. It applies to static imports only, not...
Read more >
Disallow specific imports (no-restricted-imports) - ESLint
This rule allows you to specify imports that you don't want to use in your application. It applies to static imports only, not...
Read more >
eslint no-restricted-imports - prevent an import from from path ...
What I'm trying to do is restrict imports from parent index files - as this is causing issues with cyclical dependencies (I am...
Read more >
Importing into the United States A Guide for Commercial ...
Imported goods are not legally entered until after the shipment has arrived ... Customs brokers are private individuals or firms licensed by CBP...
Read more >
no-restricted-imports | typescript-eslint
How to Use​ ·.exports = { · "rules": { · // Note: you must disable the base rule as it can report incorrect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found