Skip to content

Commit

Permalink
fix(eslint-plugin): [no-restricted-imports] fix crash when no options…
Browse files Browse the repository at this point in the history
… given (#3947)
  • Loading branch information
rafaelss95 committed Oct 3, 2021
1 parent 0868725 commit edaa3c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
@@ -1,14 +1,14 @@
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
import baseRule, {
ArrayOfStringOrObjectPatterns,
ArrayOfStringOrObject,
ArrayOfStringOrObjectPatterns,
} from 'eslint/lib/rules/no-restricted-imports';
import ignore, { Ignore } from 'ignore';
import {
InferOptionsTypeFromRule,
InferMessageIdsTypeFromRule,
createRule,
deepMerge,
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../util';

export type Options = InferOptionsTypeFromRule<typeof baseRule>;
Expand Down Expand Up @@ -119,6 +119,10 @@ export default createRule<Options, MessageIds>({
const rules = baseRule.create(context);
const { options } = context;

if (options.length === 0) {
return {};
}

const restrictedPaths = getRestrictedPaths(options);
const allowedTypeImportPathNameSet: Set<string> = new Set();
for (const restrictedPath of restrictedPaths) {
Expand Down
Expand Up @@ -8,6 +8,7 @@ const ruleTester = new RuleTester({

ruleTester.run('no-restricted-imports', rule, {
valid: [
"import foo from 'foo';",
{
code: "import foo from 'foo';",
options: ['import1', 'import2'],
Expand Down

0 comments on commit edaa3c1

Please sign in to comment.