-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Docs: no-restricted-imports #18454
Comments
Hi @ArielGueta, thanks for the issue!
Can you clarify with a few examples of code that should and code that shouldn't error what you mean by "exact"? If you want to restrict imports |
Sure. // Should be lint error
import { Foo_Enum } from '@app/api';
// These should be OK
import { Foo_Enum } from '@app/api/bar';
import { Foo_Enum } from '@app/api/baz'; |
Hi @ArielGueta, to prevent the files inside eslint no-restricted-imports: ["error", { patterns: [{
"importNamePattern": "_Enum$",
"group": ["@app/api", "!@app/api/"]
}]}]
// error
import { Foo_Enum } from '@app/api';
// no error
import { Foo_Enum } from '@app/api/bar';
import { Foo_Enum } from '@app/api/baz'; let us know if this solves your issue! |
Works like a charm. Thanks! It'll be valuable example to add to the docs. |
It looks like there wasn't enough information for us to know how to help you, so we're closing the issue. Thanks for your understanding. |
Hi, How can I allow only one import while exclude the others. This doesn't work from some reason:
|
To achieve this we have to write a series of patterns like this: /*eslint no-restricted-imports: ["error", { patterns: [{
"importNamePattern": "_Enum$",
"group": ["@app/api", "!@app/api/", "@app/api/**", "!@app/api/enums"]
}]}]*/
// error
import { Foo_Enum } from '@app/api';
import { Bar_Enum } from '@app/api/bar';
import { Baz_Enum } from '@app/api/baz';
// no error
import { B_Enum } from '@app/api/enums'; |
Thanks! I wish it was simple as just one regex. |
You can open an issue for this idea. |
Docs page(s)
https://eslint.org/docs/latest/rules/no-restricted-imports
What documentation issue do you want to solve?
I have the following configuration:
The issue is that it also errors for "@app/api/foo" etc. How can I make it exact?
What do you think is the correct solution?
To include "exact" example
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: