Skip to content

Commit 4a6d217

Browse files
authored
fix(eslint-plugin): [no-restricted-imports] allow relative type imports with patterns configured (typescript-eslint#4494)
* fix(eslint-plugin): [no-restricted-imports] allow relative type imports * refactor: add caseSensitive typedef
1 parent 41c6474 commit 4a6d217

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

packages/eslint-plugin/src/rules/no-restricted-imports.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ export default createRule<Options, MessageIds>({
146146
typeof restrictedPattern === 'object' &&
147147
restrictedPattern.allowTypeImports
148148
) {
149-
allowedImportTypeMatchers.push(ignore().add(restrictedPattern.group));
149+
// Following how ignore is configured in the base rule
150+
allowedImportTypeMatchers.push(
151+
ignore({
152+
allowRelativePaths: true,
153+
ignoreCase: !restrictedPattern.caseSensitive,
154+
}).add(restrictedPattern.group),
155+
);
150156
}
151157
}
152158
function isAllowedTypeImportPattern(importSource: string): boolean {

packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ ruleTester.run('no-restricted-imports', rule, {
217217
code: "export * from 'foo';",
218218
options: ['import1'],
219219
},
220+
{
221+
code: "import type { MyType } from './types';",
222+
options: [
223+
{
224+
patterns: [
225+
{
226+
group: ['fail'],
227+
message: "Please do not load from 'fail'.",
228+
allowTypeImports: true,
229+
},
230+
],
231+
},
232+
],
233+
},
220234
],
221235
invalid: [
222236
{

packages/eslint-plugin/typings/eslint-rules.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ declare module 'eslint/lib/rules/no-restricted-imports' {
905905
| {
906906
group: string[];
907907
message?: string;
908+
caseSensitive?: boolean;
908909
// extended
909910
allowTypeImports?: boolean;
910911
}[];

0 commit comments

Comments
 (0)
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