Config for projects using Playwright for testing.
-
If you haven't already, make sure to install
@code-pushup/eslint-configand its required peer dependencies. -
Since this plugin requires additional peer dependencies, you have to install them as well:
npm install -D eslint-plugin-playwright
-
Add to your
eslint.config.jsfile:import playwright from '@code-pushup/eslint-config/playwright.js'; import { defineConfig } from 'eslint/config'; export default defineConfig(...playwright);
🔧 Automatically fixable by the
--fixCLI option.
💡 Manually fixable by editor suggestions.
| Plugin | Rule | Options | Autofix | Overrides |
|---|---|---|---|---|
| missing-playwright-await Identify false positives when async Playwright APIs are not properly awaited. |
🔧 | |||
| no-networkidle Prevent usage of the networkidle option |
||||
| no-unsafe-references Prevent unsafe variable references in page.evaluate() and page.addInitScript() |
🔧 | |||
| no-unused-locators Disallow usage of page locators that are not used |
||||
| no-wait-for-navigation Prevent usage of page.waitForNavigation() |
💡 | |||
| prefer-web-first-assertions Prefer web first assertions |
🔧 | |||
| valid-describe-callback Enforce valid describe() callback |
||||
| valid-expect Enforce valid expect() usage |
||||
| valid-expect-in-promise Require promises that have expectations in their chain to be valid |
||||
| valid-test-tags Enforce valid tag format in Playwright test blocks and titles |
||||
| valid-title Enforce valid titles |
🔧 |
| Plugin | Rule | Options | Autofix | Overrides |
|---|---|---|---|---|
| consistent-spacing-between-blocks Enforces a blank line between Playwright test blocks (e.g., test, test.step, test.beforeEach, etc.). |
🔧 | |||
| expect-expect Enforce assertion to be made in a test body |
||||
| max-nested-describe Enforces a maximum depth to nested describe calls |
||||
| no-commented-out-tests Disallow commented out tests |
||||
| no-conditional-expect Disallow calling expect conditionally |
||||
| no-conditional-in-test Disallow conditional logic in tests |
||||
| no-duplicate-hooks Disallow duplicate setup and teardown hooks |
||||
| no-element-handle The use of ElementHandle is discouraged, use Locator instead |
💡 | |||
| no-eval The use of page.$eval and page.$$eval are discouraged, use locator.evaluate or locator.evaluateAll instead |
||||
| no-focused-test Prevent usage of .only() focus test annotation |
💡 | |||
| no-force-option Prevent usage of { force: true } option. |
||||
| no-nested-step Disallow nested test.step() methods |
||||
| no-page-pause Prevent usage of page.pause() |
||||
| no-skipped-test Prevent usage of the .skip() skip test annotation. |
💡 | |||
| no-standalone-expect Disallow using expect outside of test blocks |
🔧 | |||
| no-useless-await Disallow unnecessary awaits for Playwright methods |
🔧 | |||
| no-useless-not Disallow usage of 'not' matchers when a more specific matcher exists |
🔧 | |||
| no-wait-for-selector Prevent usage of page.waitForSelector() |
💡 | |||
| no-wait-for-timeout Prevent usage of page.waitForTimeout() |
💡 | |||
| prefer-comparison-matcher Suggest using the built-in comparison matchers |
🔧 | |||
| prefer-equality-matcher Suggest using the built-in equality matchers |
💡 | |||
| prefer-hooks-in-order Prefer having hooks in a consistent order |
||||
| prefer-hooks-on-top Suggest having hooks before any test cases |
||||
| prefer-locator Suggest locators over page methods |
||||
| prefer-native-locators Prefer native locator functions |
🔧 | |||
| prefer-to-be Suggest using toBe() for primitive literals |
🔧 | |||
| prefer-to-contain Suggest using toContain() |
🔧 | |||
| prefer-to-have-count Suggest using toHaveCount() |
🔧 | |||
| prefer-to-have-length Suggest using toHaveLength() |
🔧 | |||
| require-hook Require setup and teardown code to be within a hook |
||||
| require-to-throw-message Require a message for toThrow() |