From 638d84ddd77d07117b3ec7c5431f3b0e44b1995d Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Thu, 26 Mar 2020 13:04:48 +0500 Subject: [PATCH] fix(eslint-plugin): [no-explicit-any] error with ignoreRestArgs (#1796) --- packages/eslint-plugin/src/rules/no-explicit-any.ts | 9 ++------- .../eslint-plugin/tests/rules/no-explicit-any.test.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-explicit-any.ts b/packages/eslint-plugin/src/rules/no-explicit-any.ts index 29fb16651a2..91765c40e26 100644 --- a/packages/eslint-plugin/src/rules/no-explicit-any.ts +++ b/packages/eslint-plugin/src/rules/no-explicit-any.ts @@ -131,9 +131,7 @@ export default util.createRule({ */ function isGreatGrandparentRestElement(node: TSESTree.Node): boolean { return ( - typeof node.parent !== 'undefined' && - typeof node.parent.parent !== 'undefined' && - typeof node.parent.parent.parent !== 'undefined' && + node?.parent?.parent?.parent != null && isNodeRestElementInFunction(node.parent.parent.parent) ); } @@ -146,11 +144,8 @@ export default util.createRule({ */ function isGreatGreatGrandparentRestElement(node: TSESTree.Node): boolean { return ( - typeof node.parent !== 'undefined' && - typeof node.parent.parent !== 'undefined' && + node.parent?.parent?.parent?.parent != null && isNodeValidTSType(node.parent.parent) && - typeof node.parent.parent.parent !== 'undefined' && - typeof node.parent.parent.parent.parent !== 'undefined' && isNodeRestElementInFunction(node.parent.parent.parent.parent) ); } diff --git a/packages/eslint-plugin/tests/rules/no-explicit-any.test.ts b/packages/eslint-plugin/tests/rules/no-explicit-any.test.ts index d065c410987..fa68b09919e 100644 --- a/packages/eslint-plugin/tests/rules/no-explicit-any.test.ts +++ b/packages/eslint-plugin/tests/rules/no-explicit-any.test.ts @@ -925,6 +925,17 @@ const test = >() => {}; }, ], }, + { + code: `type Any = any;`, + options: [{ ignoreRestArgs: true }], + errors: [ + { + messageId: 'unexpectedAny', + line: 1, + column: 12, + }, + ], + }, { code: `function foo5(...args: any) {}`, options: [{ ignoreRestArgs: true }],