Skip to content

Commit

Permalink
Support Flow as expressions in ESLint rules (#27590)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gkz authored Nov 1, 2023
1 parent 3eaa0c3 commit 6bfc0e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1525,7 +1525,7 @@ function getConstructionExpressionType(node) {
}
return null;
case 'TypeCastExpression':
return getConstructionExpressionType(node.expression);
case 'AsExpression':
case 'TSAsExpression':
return getConstructionExpressionType(node.expression);
}
Expand Down
6 changes: 5 additions & 1 deletion scripts/eslint-rules/safe-string-coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6bfc0e0

Please sign in to comment.