From 2aa5b4dd1fae3cf21b6a2a2647e208454c1f942d Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Wed, 25 Oct 2023 16:38:15 -0700 Subject: [PATCH] Support Flow `as` expressions in ESLint rules --- packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js | 4 ++-- scripts/eslint-rules/safe-string-coercion.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 0b8b61b14fa54..6b2484c7ba2c3 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -177,7 +177,7 @@ export default { if (init == null) { return false; } - while (init.type === 'TSAsExpression') { + while (init.type === 'TSAsExpression' || init.type === 'AsExpression') { init = init.expression; } // Detect primitive constants @@ -1520,7 +1520,7 @@ function getConstructionExpressionType(node) { } return null; case 'TypeCastExpression': - return getConstructionExpressionType(node.expression); + case 'AsExpression': case 'TSAsExpression': return getConstructionExpressionType(node.expression); } diff --git a/scripts/eslint-rules/safe-string-coercion.js b/scripts/eslint-rules/safe-string-coercion.js index 26a1098333e00..62a59d115fb66 100644 --- a/scripts/eslint-rules/safe-string-coercion.js +++ b/scripts/eslint-rules/safe-string-coercion.js @@ -291,7 +291,11 @@ function checkBinaryExpression(context, node) { (isEmptyLiteral(node.left) || isEmptyLiteral(node.right)) ) { let valueToTest = isEmptyLiteral(node.left) ? node.right : node.left; - if (valueToTest.type === 'TypeCastExpression' && valueToTest.expression) { + if ( + (valueToTest.type === 'TypeCastExpression' || + valueToTest.type === 'AsExpression') && + valueToTest.expression + ) { valueToTest = valueToTest.expression; }