8000 fix(eslint-plugin): [no-explicit-any] error with ignoreRestArgs (#1796) · shishkin/typescript-eslint@638d84d · GitHub
[go: up one dir, main page]

Skip to content

Commit 638d84d

Browse files
authored
fix(eslint-plugin): [no-explicit-any] error with ignoreRestArgs (typescript-eslint#1796)
1 parent 4fa7107 commit 638d84d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/eslint-plugin/src/rules/no-explicit-any.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ export default util.createRule<Options, MessageIds>({
131131
*/
132132
function isGreatGrandparentRestElement(node: TSESTree.Node): boolean {
133133
return (
134-
typeof node.parent !== 'undefined' &&
135-
typeof node.parent.parent !== 'undefined' &&
136-
typeof node.parent.parent.parent !== 'undefined' &&
134+
node?.parent?.parent?.parent != null &&
137135
isNodeRestElementInFunction(node.parent.parent.parent)
138136
);
139137
}
@@ -146,11 +144,8 @@ export default util.createRule<Options, MessageIds>({
146144
*/
147145
function isGreatGreatGrandparentRestElement(node: TSESTree.Node): boolean {
148146
return (
149-
typeof node.parent !== 'undefined' &&
150-
typeof node.parent.parent !== 'undefined' &&
147+
node.parent?.parent?.parent?.parent != null &&
151148
isNodeValidTSType(node.parent.parent) &&
152-
typeof node.parent.parent.parent !== 'undefined' &&
153-
typeof node.parent.parent.parent.parent !== 'undefined' &&
154149
isNodeRestElementInFunction(node.parent.parent.parent.parent)
155150
);
156151
}

packages/eslint-plugin/tests/rules/no-explicit-any.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,17 @@ const test = <T extends Partial<never>>() => {};
925925
},
926926
],
927927
},
928+
{
929+
code: `type Any = any;`,
930+
options: [{ ignoreRestArgs: true }],
931+
errors: [
932+
{
933+
messageId: 'unexpectedAny',
934+
line: 1,
935+
column: 12,
936+
},
937+
],
938+
},
928939
{
929940
code: `function foo5(...args: any) {}`,
930941
options: [{ ignoreRestArgs: true }],

0 commit comments

Comments
 (0)
0