@samitouri / QOS-React-1 / commits / 6bfc0e032a

Support Flow `as` expressions in ESLint rules (#27590)

Support Flow `as` expressions in ESLint rules, e.g. `<expr> as <type>`. 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.

George Zahariev committed Nov 1, 2023 at 12:24 UTC 6bfc0e032acc7e5ad6da2a09f3c4f47f3321da2c
2 files changed +7 -3
packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
+2 -2
@@ -177,7 +177,7 @@ export default {
177 if (init == null) {
178 return false;
179 }
180 - while (init.type === 'TSAsExpression') {
180 + while (init.type === 'TSAsExpression' || init.type === 'AsExpression') {
181 init = init.expression;
182 }
183 // Detect primitive constants
@@ -1525,7 +1525,7 @@ function getConstructionExpressionType(node) {
1525 }
1526 return null;
1527 case 'TypeCastExpression':
1528 - return getConstructionExpressionType(node.expression);
1528 + case 'AsExpression':
1529 case 'TSAsExpression':
1530 return getConstructionExpressionType(node.expression);
1531 }
scripts/eslint-rules/safe-string-coercion.js
+5 -1
@@ -291,7 +291,11 @@ function checkBinaryExpression(context, node) {
291 (isEmptyLiteral(node.left) || isEmptyLiteral(node.right))
292 ) {
293 let valueToTest = isEmptyLiteral(node.left) ? node.right : node.left;
294 - if (valueToTest.type === 'TypeCastExpression' && valueToTest.expression) {
294 + if (
295 + (valueToTest.type === 'TypeCastExpression' ||
296 + valueToTest.type === 'AsExpression') &&
297 + valueToTest.expression
298 + ) {
299 valueToTest = valueToTest.expression;
300 }
301