Skip to content

Commit

Permalink
fix(eslint-plugin): [no-restricted-imports] allow type import as long…
Browse files Browse the repository at this point in the history
… as there's one matching pattern (#4898)

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

* chore: simplify .some expression

Co-authored-by: Josh Goldberg <me@joshuakgoldberg.com>
  • Loading branch information
Josh-Cena and JoshuaKGoldberg committed May 3, 2022
1 parent 42a5309 commit 0419d28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
Expand Up @@ -157,10 +157,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))
);
}

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

0 comments on commit 0419d28

Please sign in to comment.