Skip to content

Commit 4a6d217

Browse files
authoredJan 30, 2022
fix(eslint-plugin): [no-restricted-imports] allow relative type imports with patterns configured (#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

+7-1
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

+14
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

+1
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)
Please sign in to comment.