Skip to content

fix(await-async-queries): false positive with optional chaining #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/node-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ function getRootExpression(
return parent.expressions[parent.expressions.length - 1] === expression
? getRootExpression(parent)
: expression;

case AST_NODE_TYPES.ChainExpression:
return getRootExpression(parent);

default:
return expression;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/await-async-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ ruleTester.run(RULE_NAME, rule, {
// async screen queries declaration are valid
...createTestCase((query) => `await screen.${query}('foo')`),

// async queries with optional chaining are valid
...createTestCase((query) => `await screen?.${query}('foo')`),

// async @marko/testing-library screen queries declaration are valid
...createTestCase((query) => `await screen.${query}('foo')`, {
testingFramework: '@marko/testing-library',
Expand Down