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`: setting to to allow renames

See original GitHub issue

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

Does this change cause the rule to produce more or fewer warnings? Fewer, if a setting is enabled

How will the change be implemented? (New option, new default behavior, etc.)? New option

Please provide some example code that this change will affect:

{
  rules: {
    'no-restricted-imports': [
      'error',
      {
        paths: [{ name: 'lib', importNames: ['Option'] }],
      },
    ],
  },
}
import { Option as LibOption } from 'lib';

What does the rule currently do for this code?

Errors

What will the rule do after it’s changed?

Not error, if a setting is enabled, e.g. allowRenames: true.

I want to disallow this code:

import { Option } from 'lib';

But allow this code:

import { Option as LibOption } from 'lib';

That is, I want to ban importing the named import Option from lib, but I want to allow that named import to be used if it is renamed to something else.

Example of using this setting:

{
  rules: {
    'no-restricted-imports': [
      'error',
      {
        paths: [{ name: 'lib', importNames: ['Option'], allowRenames: true }],
      },
    ],
  },
}

Are you willing to submit a pull request to implement this change? Yes

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Aug 24, 2019

Personally, I lean towards this being an edge case, and would suggest creating a custom rule using eslint-rule-composer which could filter out linting reports for your specific case.

That’s just my opinion; other team members might feel differently.

0reactions
kaicataldocommented, Sep 30, 2019

I agree with @platinumazure. This feels like a muddying of responsibilities of this rule. If you know what identifiers you want to allow, this should also be able to be enforced with no-restricted-syntax.

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 >
no-restricted-imports - ESLint Config
no-restricted-imports ... Turn on. Disallow renaming import, export, and destructured assignments to the same name ... Require let or const instead of var ......
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
ESLint - Shows Issue Trying to Lint but Lints File
I set-up the js files in the cypress folder (my e2e tests) to have different rules by anding overrides in the .eslintrc.js file,...
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