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
Rule Change: Add importNames
to patterns
in no-restricted-imports rule
#15236
Comments
Thanks for the suggestion. You didn’t actually explain the proposal (code examples aren’t enough), how it would work, or how this would benefit users. Please take some time to document those on this issue and then we can take a look. |
Hi @nzakas , I thought the example I provided would be enough, can you tell me which part is not clear? My idea is to add the Let's say we want to restrict an import of Currently to do that I would have to go with
But I don't really like that as it forces me to provide a name and a message each time even though they are the same. If
and quickly add more sources if they come up without any boilerplate. Is it clearer now? |
Yes, much clearer, thank you. This seems like a reasonable addition to me, and may have been an oversight based on how paths already supports it. Let’s see what the team thinks. |
This looks like a duplicate of #14274, as the proposed schema is same as in #14274 (comment).
Note that this wouldn't be equivalent. /* eslint no-restricted-imports: ["error", {
patterns: [
{
group: ['emotion-theming', '@react-navigation/native'],
message: "Use 'useTheme' from the 'theme' module instead.",
},
]
}]*/
import { useTheme } from "emotion-theming"; // error
import { useTheme as useTheme1 } from "foo/emotion-theming"; // also error
import { useTheme as useTheme2 } from "emotion-theming/foo"; // also error |
yup, seems like they are the same, thanks for explanation and for pointing me there! |
What rule do you want to change?
no-restricted-imports
What change to do you want to make?
Generate more warnings
How do you think the change should be implemented?
Other
Example code
What does the rule currently do for this code?
It's a change in the rule's options in eslint config. What I'm proposing is to add an
importNames
property forpatterns
same as we have inpaths
.Sometimes you want to restrict the same import from multiple sources, you can accomplish that by providing separate objects for each source, but this way is redundant as you need to provide a name and a message each time.
E.g.
Instead of:
We could have:
What will the rule do after it's changed?
The rule would work exactly the same, it's just an easier way of providing multiple sources of the same restricted import.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: