noPlaywrightEval (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.4.2 - Diagnostic Category:
lint/style/noPlaywrightEval - This rule isn’t recommended, so you need to enable it.
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
playwright/no-eval
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "noPlaywrightEval": "error" } } }}Description
Section titled “Description”Disallow usage of page.$eval() and page.$$eval().
These methods are discouraged in favor of locator.evaluate() and locator.evaluateAll().
Locator-based evaluation is more reliable and follows Playwright’s recommended patterns.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”await page.$eval('.foo', el => el.textContent);code-block.js:1:7 lint/style/noPlaywrightEval ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of page.$eval().
> 1 │ await page.$eval('.foo', el => el.textContent);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Locator-based evaluation is more reliable and follows Playwright's recommended patterns.
ℹ Use locator.evaluate() instead.
const texts = await page.$$eval('.foo', els => els.map(el => el.textContent));code-block.js:1:21 lint/style/noPlaywrightEval ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of page.$$eval().
> 1 │ const texts = await page.$$eval('.foo', els => els.map(el => el.textContent));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Locator-based evaluation is more reliable and follows Playwright's recommended patterns.
ℹ Use locator.evaluateAll() instead.
const text = await page.locator('.foo').evaluate(el => el.textContent);const texts = await page.locator('.foo').evaluateAll(els => els.map(el => el.textContent));Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.