Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

eslint-plugin-playwright

> 测试质量
Open source

ESLint plugin for Playwright

390 stars0 likes1 views
WebsiteGitHub

About

ESLint plugin for Playwright

ESLint Plugin Playwright

ESLint plugin for Playwright.

Installation

npm

bash
npm install -D eslint-plugin-playwright

Yarn

bash
yarn add -D eslint-plugin-playwright

pnpm

bash
pnpm add -D eslint-plugin-playwright

Usage

The recommended setup is to use the files field to target only Playwright test files. In the examples below, this is done by targeting files in the tests directory and only applying the Playwright rules to those files. In your project, you may need to change the files field to match your Playwright test file patterns.

Flat config (eslint.config.js)

javascript
import { defineConfig } from '@eslint/config'
import playwright from 'eslint-plugin-playwright'

export default defineConfig([
  {
    files: ['tests/**'],
    extends: [playwright.configs['flat/recommended']],
    rules: {
      // Customize Playwright rules
      // ...
    },
  },
])

Legacy config (.eslintrc)

json
{
  "overrides": [
    {
      "files": "tests/**",
      "extends": "plugin:playwright/recommended"
    }
  ]
}

Settings

Aliased Playwright Globals

If you import Playwright globals (e.g. test, expect) with a custom name, you can configure this plugin to be aware of these additional names.

json
{
  "settings": {
    "playwright": {
      "globalAliases": {
        "test": ["it"],
        "expect": ["assert"]
      }
    }
  }
}

Custom Messages

You can customize the error messages for rules using the settings.playwright.messages property. This is useful if you would like to increase the verbosity of error messages or provide additional context.

Only the message ids you define in this setting will be overridden, so any other messages will use the default message defined by the plugin.

json
{
  "settings": {
    "playwright": {
      "messages": {
        "conditionalExpect": "Avoid conditional expects as they can lead to false positives"
      }
    }
  }
}

Rules

✅ Set in the recommended configuration
Automatically fixable by the --fix CLI option
Manually fixable by editor suggestions

Rule Description ✅
consistent-spacing-between-blocks Enforce consistent spacing between test blocks ✅
expect-expect Enforce assertion to be made in a test body ✅
max-expects Enforces a maximum number assertion calls 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-action-timeout Disallow the timeout option on actions
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-duplicate-slow Disallow multiple test.slow() calls in the same test ✅
no-element-handle Disallow usage of element handles ✅
no-eval Disallow usage of page.$eval() and page.$$eval() ✅
no-export Disallow using export in files containing tests
no-focused-test Disallow usage of .only annotation ✅
no-force-option Disallow usage of the { force: true } option ✅
no-get-by-title Disallow using getByTitle()
no-hooks Disallow setup and teardown hooks
no-identical-title Disallow identical titles ✅
no-magic-timeouts Disallow magic numbers as Playwright timeout values
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-restricted-locators Disallow specific locator methods
no-restricted-matchers Disallow specific matchers & modifiers
no-restricted-roles Disallow specific roles in getByRole()
no-skipped-test Disallow usage of the .skip annotation ✅
no-slowed-test Disallow usage of the .slow annotation
no-standalone-expect Disallow using expect outside of test blocks ✅
no-template-literal-title Disallow template literals in test, describe, and step titles
no-test-return-statement Disallow explicitly returning from tests
no-unnecessary-assertions Disallow assertions on a Locator that can never fail ✅
no-unsafe-references Prevent unsafe variable references in page.evaluate() ✅
no-unused-locators Disallow usage of page locators that are not used ✅
no-useless-await Disallow unnecessary awaits for Playwright methods ✅
no-useless-not Disallow usage of not matchers when a specific matcher exists ✅

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScripteslinteslint-pluginjestjest-playwright

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.