Skip to content

missing-playwright-await gives false positive when using optional chaining (?.) on page methods #467

Description

@amish-apollo

When the includePageLocatorMethods: true option is enabled, the missing-playwright-await rule correctly flags missing awaits on page.* and locator.* methods. However, it fails to recognise the await keyword if the method is called using optional chaining (?.), leading to a false positive.

Reproduction:

import { test } from '@playwright/test';

test('missing await test', async ({ page }) => {
  // ❌ This incorrectly throws: "'unrouteAll' must be awaited or returned"
  await page?.unrouteAll();

  // ✅ This passes fine
  await page.unrouteAll();
});

ESLint Config:

{
  "rules": {
    "playwright/missing-playwright-await": ["error", { "includePageLocatorMethods": true }]
  }
}

Expected Behavior: The rule should recognize that await page?.unrouteAll() is correctly awaited and not throw an error.

Cause: This appears to happen because the AST node for optional chaining (ChainExpression containing a CallExpression) is structured differently than a standard CallExpression, causing the rule's await traversal to miss it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions