ESLint plugin for Playwright.
npm
npm install -D eslint-plugin-playwright
Yarn
yarn add -D eslint-plugin-playwright
pnpm
pnpm add -D eslint-plugin-playwright
This plugin bundles two configurations to work with both @playwright/test
or
jest-playwright
.
Flat config (eslint.config.js)
import playwright from 'eslint-plugin-playwright';
export default [
playwright.configs['flat/recommended'],
{
rules: {
// Customize Playwright rules
// ...
},
},
];
Legacy config (.eslintrc)
{
"extends": ["plugin:playwright/recommended"]
}
With Jest Playwright
Flat config (eslint.config.js)
import playwright from 'eslint-plugin-playwright';
import jest from 'eslint-plugin-jest';
export default [
playwright.configs['flat/jest-playwright'],
{
plugins: {
jest,
},
rules: {
// Customize Playwright rules
// ...
},
},
];
Legacy config (.eslintrc)
{
"extends": ["plugin:playwright/jest-playwright"]
}
The plugin reads global settings from your ESLint configuration's shared data
under the playwright
key. It supports the following settings:
additionalAssertFunctionNames
: an array of function names to treat as assertion functions for the case of rules likeexpect-expect
, which enforces the presence of at least one assertion per test case. This allows such rules to recognise custom assertion functions as valid assertions. The global setting applies to all modules. Theexpect-expect
rule accepts an option by the same name to enable per-module configuration (.e.g, for module-specific custom assert functions).
You can configure these settings like so:
Flat config (eslint.config.js)
export default [
{
settings: {
playwright: {
additionalAssertFunctionNames: ['assertCustomCondition'],
},
},
},
];
Legacy config (.eslintrc)
{
"settings": {
"playwright": {
"additionalAssertFunctionNames": ["assertCustomCondition"]
}
}
}
✔: Enabled in the recommended configuration.
🔧: Some problems reported by this rule are automatically fixable by the --fix
command line option.
💡: Some problems reported by this rule are manually fixable by editor
suggestions.
✔ | 🔧 | 💡 | Rule | Description |
---|---|---|---|---|
✔ | expect-expect | Enforce assertion to be made in a test body | ||
✔ | max-nested-describe | Enforces a maximum depth to nested describe calls | ||
✔ | 🔧 | missing-playwright-await | Enforce Playwright APIs to be awaited | |
✔ | no-conditional-in-test | Disallow conditional logic in tests | ||
✔ | 💡 | no-element-handle | Disallow usage of element handles | |
✔ | no-eval | Disallow usage of page.$eval and page.$$eval |
||
✔ | 💡 | no-focused-test | Disallow usage of .only annotation |
|
✔ | no-force-option | Disallow usage of the { force: true } option |
||
✔ | no-nested-step | Disallow nested test.step() methods |
||
✔ | no-networkidle | Disallow usage of the networkidle option |
||
no-nth-methods | Disallow usage of first() , last() , and nth() methods |
|||
✔ | no-page-pause | Disallow using page.pause |
||
no-raw-locators | Disallow using raw locators | |||
✔ | 🔧 | no-useless-await | Disallow unnecessary await s for Playwright methods |
|
no-restricted-matchers | Disallow specific matchers & modifiers | |||
✔ | 💡 | no-skipped-test | Disallow usage of the .skip annotation |
|
✔ | 🔧 | no-useless-not | Disallow usage of not matchers when a specific matcher exists |
|
✔ | 💡 | no-wait-for-timeout | Disallow usage of page.waitForTimeout |
|
💡 | prefer-strict-equal | Suggest using toStrictEqual() |
||
🔧 | prefer-lowercase-title | Enforce lowercase test names | ||
🔧 | prefer-to-be | Suggest using toBe() |
||
🔧 | prefer-to-contain | Suggest using toContain() |
||
🔧 | prefer-to-have-count | Suggest using toHaveCount() |
||
🔧 | prefer-to-have-length | Suggest using toHaveLength() |
||
✔ | 🔧 | prefer-web-first-assertions | Suggest using web first assertions | |
require-top-level-describe | Require test cases and hooks to be inside a test.describe block |
|||
🔧 | require-soft-assertions | Require assertions to use expect.soft() |
||
✔ | valid-expect | Enforce valid expect() usage |
||
✔ | 🔧 | valid-title | Enforce valid titles |