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` should support `importNames` on `patterns` exclusions

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?

Neither, it makes configuration more powerful

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

New options to the rule schema

Please provide some example code that this change will affect:

import { Foo, Bar } from '../../my/relative-module' import { Foo } from '../../../my/relative-module'

What does the rule currently do for this code?

It’s not currently possible to ban importing only a named import from a pattern ban. Nor is it possible to include a message for those bans.

What will the rule do after it’s changed?

Could be configured as follows:

'no-restricted-imports: [
  'error',
  {
    patterns: [ '**/my/relative-module'],
    importNames: ['Foo'], // currently not supported for patterns
    message: 'Don't import Foo from my/relative-module. Instead import from @repo/foo', // currently not supported for patterns
  }
]

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

Potentially, but I’d like some guidance and my time is limited due to having young kids.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
brandongregoryscottcommented, Jun 26, 2022

I took a stab at this over the weekend - will throw up a PR for feedback later today!

2reactions
snitin315commented, Oct 16, 2021
"no-restricted-imports": ["error", {            
    "patterns": [{
        "group": ["**/my/relative-module"],
        "importNames": ["Foo"],
        "message": "Don't import Foo from my/relative-module. Instead import from @repo/foo"
    }]
}]

So, the above config will result in the following behaviour:

import { Foo } from '../../../my/relative-module' // error
import { Foo, Bar } from '../../../my/relative-module' // error
import { Bar } from '../../../my/relative-module' // ok

It makes sense to me as well. I am also 👍🏻 on this. I can submit a PR for this if accepted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - 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 no-restricted-imports - prevent an import from from ...
First, make sure you don't have set import/no-relative-parent-imports , or any ../ import would fail. Second, if this really follows ...
Read more >
eslint
c3ce521 fix: Ensure unmatched glob patterns throw an error (#16462) ... 7023628 feat: add importNames support for patterns in no-restricted-imports (#16059) ...
Read more >
node_modules/eslint/CHANGELOG.md · master · tbrousso ...
196c102 Fix: valid-jsdoc should allow optional returns for async (fixes ... 0cf081e Update: add importNames option to no-restricted-imports ...
Read more >
eslint | Yarn - Package Manager
... for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a...
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