Skip to content

Commit edaa3c1

Browse files
authored
fix(eslint-plugin): [no-restricted-imports] fix crash when no options given (typescript-eslint#3947)
1 parent 0868725 commit edaa3c1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
22
import baseRule, {
3-
ArrayOfStringOrObjectPatterns,
43
ArrayOfStringOrObject,
4+
ArrayOfStringOrObjectPatterns,
55
} from 'eslint/lib/rules/no-restricted-imports';
66
import ignore, { Ignore } from 'ignore';
77
import {
8-
InferOptionsTypeFromRule,
9-
InferMessageIdsTypeFromRule,
108
createRule,
119
deepMerge,
10+
InferMessageIdsTypeFromRule,
11+
InferOptionsTypeFromRule,
1212
} from '../util';
1313

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

122+
if (options.length === 0) {
123+
return {};
124+
}
125+
122126
const restrictedPaths = getRestrictedPaths(options);
123127
const allowedTypeImportPathNameSet: Set<string> = new Set();
124128
for (const restrictedPath of restrictedPaths) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ruleTester = new RuleTester({
88

99
ruleTester.run('no-restricted-imports', rule, {
1010
valid: [
11+
"import foo from 'foo';",
1112
{
1213
code: "import foo from 'foo';",
1314
options: ['import1', 'import2'],

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