From 6bfc0e032acc7e5ad6da2a09f3c4f47f3321da2c Mon Sep 17 00:00:00 2001 From: George Zahariev <1222691+gkz@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:24:06 -0700 Subject: [PATCH] Support Flow `as` expressions in ESLint rules (#27590) Support Flow `as` expressions in ESLint rules, e.g. ` as `. This is the same syntax as TypeScript as expressions. I just looked for any place referencing `TSAsExpression` (the TS node) or `TypeCastExpression` (the previous Flow syntax) and added a case for `AsExpression` as well. --- 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 e754edabc4..62a451377f 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 @@ -1525,7 +1525,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 26a1098333..62a59d115f 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; }