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 relative type imports with patterns configured #4494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion packages/eslint-plugin/src/rules/no-restricted-imports.ts
Expand Up @@ -146,7 +146,13 @@ export default createRule<Options, MessageIds>({
typeof restrictedPattern === 'object' &&
restrictedPattern.allowTypeImports
) {
allowedImportTypeMatchers.push(ignore().add(restrictedPattern.group));
// Following how ignore is configured in the base rule
allowedImportTypeMatchers.push(
ignore({
allowRelativePaths: true,
ignoreCase: !restrictedPattern.caseSensitive,
}).add(restrictedPattern.group),
);
}
}
function isAllowedTypeImportPattern(importSource: string): boolean {
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts
Expand Up @@ -217,6 +217,20 @@ ruleTester.run('no-restricted-imports', rule, {
code: "export * from 'foo';",
options: ['import1'],
},
{
code: "import type { MyType } from './types';",
options: [
{
patterns: [
{
group: ['fail'],
message: "Please do not load from 'fail'.",
allowTypeImports: true,
},
],
},
],
},
],
invalid: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/typings/eslint-rules.d.ts
Expand Up @@ -905,6 +905,7 @@ declare module 'eslint/lib/rules/no-restricted-imports' {
| {
group: string[];
message?: string;
caseSensitive?: boolean;
// extended
allowTypeImports?: boolean;
}[];
Expand Down