Skip to content

Commit

Permalink
fix(eslint-plugin): [no-restricted-imports]: report type-only imports…
Browse files Browse the repository at this point in the history
… properly (#3996)
  • Loading branch information
rafaelss95 committed Oct 18, 2021
1 parent 076d65a commit 283cdf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
Expand Up @@ -4,13 +4,13 @@ import {
ArrayOfStringOrObjectPatterns,
} from 'eslint/lib/rules/no-restricted-imports';
import ignore, { Ignore } from 'ignore';
import { getESLintCoreRule } from '../util/getESLintCoreRule';
import {
createRule,
deepMerge,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../util';
import { getESLintCoreRule } from '../util/getESLintCoreRule';

const baseRule = getESLintCoreRule('no-restricted-imports');

Expand Down Expand Up @@ -150,9 +150,12 @@ export default createRule<Options, MessageIds>({
}
}
function isAllowedTypeImportPattern(importSource: string): boolean {
return allowedImportTypeMatchers.every(matcher => {
return matcher.ignores(importSource);
});
return (
allowedImportTypeMatchers.length > 0 &&
allowedImportTypeMatchers.every(matcher => {
return matcher.ignores(importSource);
})
);
}

return {
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts
Expand Up @@ -535,5 +535,19 @@ ruleTester.run('no-restricted-imports', rule, {
},
],
},
{
code: "import type { InvalidTestCase } from '@typescript-eslint/experimental-utils/dist/ts-eslint';",
options: [
{
patterns: ['@typescript-eslint/experimental-utils/dist/*'],
},
],
errors: [
{
messageId: 'patterns',
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
],
});

0 comments on commit 283cdf2

Please sign in to comment.