Implementation:Microsoft Playwright ESLint Configuration
| Knowledge Sources | |
|---|---|
| Domains | Code Quality, Build Tooling |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
The root ESLint flat configuration file that defines linting rules, parser settings, and per-package overrides for the entire Playwright monorepo.
Description
eslint.config.mjs uses ESLint's flat config format (ESM) to configure TypeScript linting across all Playwright packages. It imports @typescript-eslint/eslint-plugin and @typescript-eslint/parser for TypeScript support, eslint-plugin-notice for copyright header enforcement, @stylistic/eslint-plugin for formatting rules, and eslint-plugin-import for import ordering. The configuration defines a shared baseRules object and then applies package-specific overrides for different directories, including stricter rules for injected scripts, client code, server utilities, test files, and React-based UI packages.
Key Configuration Sections
- Ignores: Excludes generated code, third-party vendored sources, build outputs, test assets, and utility scripts from linting.
- Base Rules (
baseRules): Enforces single quotes, semicolons,prefer-const,eqeqeq, 2-space indentation, copyright headers vianotice/notice, and a comprehensive set of anti-pattern guards (no-var,no-caller,no-implied-eval, etc.). - Package-level Overrides:
packages/**/*.ts-- Enablesno-console, restrictsprocess.exit/process.stdout/process.stderr, and enforces import ordering.packages/playwright/**/*.ts-- Adds@typescript-eslint/no-floating-promises.packages/playwright-core/src/utils/**/*.ts-- Restricts both Node and Web globals, adds floating-promise and boolean-compare rules.packages/injected/src/**/*.ts-- Restricts Web globals (must useInjectedScriptbuiltins instead ofwindow,document,setTimeout, etc.).packages/playwright-core/src/client/**/*.tsandprotocol/**/*.ts-- Restricts Node globals (process).tests/**/*.spec.jsandtests/**/*.ts-- Enables floating-promise checks with a test-specific tsconfig.- React packages (
html-reporter,recorder,trace-viewer) -- Extendsplugin:react/recommendedandplugin:react-hooks/recommended, addsno-consoleand a custom rule forbidding stray semicolons after JSX elements.
- Parser Configuration: Uses
@typescript-eslint/parserwith ECMAScript 2018 (version 9), module source type, and project-specifictsconfig.jsonreferences where type-aware rules are needed.
Usage
This file is consumed by ESLint when running npx eslint or any IDE integration from the repository root. It is the single source of truth for code style and quality enforcement across all Playwright packages. Contributors must satisfy these rules before merging pull requests.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File:
eslint.config.mjs
Exported Symbols
baseRules-- Named export; the shared rule set object, available for external consumption or testing.- default export -- The flat config array consumed by ESLint.
Notable Dependencies
@typescript-eslint/eslint-plugin/@typescript-eslint/parser@stylistic/eslint-plugineslint-plugin-noticeeslint-plugin-import@eslint/compat(FlatCompat for legacy React plugin configs)