From 5bacf39592356c4465b151ec3482d1e075c8b037 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Tue, 3 May 2022 18:32:37 +0800 Subject: [PATCH 1/2] fix(eslint-plugin): [no-restricted-imports] allow type import as long as there's one matching pattern --- .../src/rules/no-restricted-imports.ts | 5 ++--- .../tests/rules/no-restricted-imports.test.ts | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-restricted-imports.ts b/packages/eslint-plugin/src/rules/no-restricted-imports.ts index fd724c5fc8b5..f6f5969be339 100644 --- a/packages/eslint-plugin/src/rules/no-restricted-imports.ts +++ b/packages/eslint-plugin/src/rules/no-restricted-imports.ts @@ -158,9 +158,8 @@ export default createRule({ 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)) ); } diff --git a/packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts b/packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts index 1758365e37dc..64f9c91fe7ca 100644 --- a/packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts +++ b/packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts @@ -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: [ { From 6e60c929ab3a5955553e29216a5ee01ec2fc9b89 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 3 May 2022 15:01:56 -0400 Subject: [PATCH 2/2] chore: simplify .some expression --- packages/eslint-plugin/src/rules/no-restricted-imports.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-restricted-imports.ts b/packages/eslint-plugin/src/rules/no-restricted-imports.ts index f6f5969be339..13afc7a895d0 100644 --- a/packages/eslint-plugin/src/rules/no-restricted-imports.ts +++ b/packages/eslint-plugin/src/rules/no-restricted-imports.ts @@ -157,7 +157,6 @@ export default createRule({ } function isAllowedTypeImportPattern(importSource: string): boolean { return ( - allowedImportTypeMatchers.length > 0 && // As long as there's one matching pattern that allows type import allowedImportTypeMatchers.some(matcher => matcher.ignores(importSource)) ); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy