Skip to content
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

fix(eslint-plugin): [no-restricted-imports] allow type import as long as there's one matching pattern #4898

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
Expand Up @@ -158,9 +158,8 @@ export default createRule<Options, MessageIds>({
function isAllowedTypeImportPattern(importSource: string): boolean {
return (
allowedImportTypeMatchers.length > 0 &&
allowedImportTypeMatchers.every(matcher => {
return matcher.ignores(importSource);
})
// As long as there's one matching pattern that allows type import
allowedImportTypeMatchers.some(matcher => matcher.ignores(importSource))
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts
Expand Up @@ -231,6 +231,28 @@ ruleTester.run('no-restricted-imports', rule, {
},
],
},
{
code: `
import type { foo } from 'import1/private/bar';
import type { foo } from 'import2/private/bar';
`,
options: [
{
patterns: [
{
group: ['import1/private/*'],
message: 'usage of import1 private modules not allowed.',
allowTypeImports: true,
},
{
group: ['import2/private/*'],
message: 'usage of import2 private modules not allowed.',
allowTypeImports: true,
},
],
},
],
},
],
invalid: [
{
Expand Down