Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Puppeteer Puppeteer ESLint Config

From Leeroopedia
Property Value
sources eslint.config.mjs
domains Code Quality, Linting, Development Tooling
last_updated 2026-02-12 00:00 GMT

Overview

Description

The ESLint Config module defines the comprehensive linting configuration for the entire Puppeteer monorepo using the ESLint flat config format. It configures multiple layers of rules for JavaScript files, TypeScript files, Puppeteer core source code, test files, and package files, along with extensive global ignore patterns for build artifacts, generated code, and third-party dependencies.

The configuration integrates the following ESLint plugins:

  • eslint-plugin-prettier -- Code formatting enforcement via Prettier integration
  • eslint-plugin-import -- Import ordering, no-cycle detection, and Node protocol enforcement
  • eslint-plugin-mocha -- Mocha-specific rules (no exclusive tests, no pending tests, no identical titles)
  • @typescript-eslint -- TypeScript-specific rules including strict type checking, consistent type imports/exports, and floating promise detection
  • @stylistic/eslint-plugin -- Style rules for function call spacing and semicolons
  • @puppeteer/eslint -- Custom Puppeteer rules for prettier comments, file extensions, license headers, resource cleanup (use-using), and quirks mode detection
  • eslint-plugin-tsdoc -- TSDoc syntax validation for package files

The configuration defines five named rule sets:

  1. JavaScript rules -- General rules for all files (code style, no-var, eqeqeq, import ordering)
  2. TypeScript rules -- TypeScript-specific rules (type imports, floating promises, explicit boundaries)
  3. Puppeteer Core syntax -- Additional restrictions for puppeteer-core (no Promise.race, no third-party direct imports)
  4. Packages -- Relaxed rules for test files within packages
  5. Mocha Tests -- Strict rules for the test suite (no exclusive tests, no direct puppeteer.launch)

Usage

This configuration is the root ESLint configuration for the monorepo and is used during development, CI/CD, and pre-commit hooks to enforce code quality and consistency across all packages.

Code Reference

Source Location

eslint.config.mjs

Signature

// ESLint flat config export
export default defineConfig([
  globalIgnores([...]),
  eslintPrettierPluginRecommended,
  importPlugin.flatConfigs.typescript,
  { name: 'JavaScript rules', ... },
  ...typescriptEslint.configs.[...].flat().map(...),
  { name: 'TypeScript rules', files: ['**/*.ts'], ... },
  { name: 'Puppeteer Core syntax', files: ['packages/puppeteer-core/src/**/*.ts'], ... },
  { name: 'Packages', files: ['packages/puppeteer-core/src/**/*.test.ts', ...], ... },
  { files: ['packages/**/*.ts'], rules: { 'tsdoc/syntax': 'error' } },
  { name: 'Mocha', files: ['test/**/*.ts'], ... },
  { name: 'Mocha Tests', files: ['test/**/*.spec.ts'], ... },
]);

Import

// This is the root ESLint configuration; it is automatically loaded by ESLint.
// No explicit import is needed.

I/O Contract

Plugin Dependencies

Plugin Purpose
@puppeteer/eslint Custom Puppeteer rules (prettier-comments, extensions, check-license, use-using, no-quirks-mode-set-content)
@stylistic/eslint-plugin Function call spacing and semicolon rules
eslint-plugin-import Import ordering, cycle detection, Node protocol enforcement
eslint-plugin-mocha Mocha test quality rules
eslint-plugin-prettier Prettier formatting as ESLint errors
eslint-plugin-tsdoc TSDoc comment syntax validation
typescript-eslint TypeScript parser and recommended rules

Key Rules by Scope

Scope Notable Rules
All files curly: 'all', arrow-body-style: 'always', prefer-const, no-var, eqeqeq, import/order, import/no-cycle
TypeScript @typescript-eslint/consistent-type-imports, @typescript-eslint/no-floating-promises, @typescript-eslint/return-await: 'always', @typescript-eslint/explicit-module-boundary-types
puppeteer-core No Promise.race (use Deferred.race()), no direct third-party imports
Test specs No puppeteer.launch (use launch helper), no exclusive/pending tests, no expect in event handlers
Packages tsdoc/syntax: 'error' for all .ts files in packages

Global Ignores

Pattern Description
**/node_modules, **/build/, **/lib/ Build artifacts and dependencies
**/third_party/ Vendored third-party code
packages/ng-schematics/sandbox/**/* Schematic sandbox test directories
packages/ng-schematics/src/**/files/ Schematic template files
examples/*/out/**/* Example build outputs

Usage Examples

// Run ESLint on the entire repository
// npx eslint .

// Run ESLint on specific packages
// npx eslint packages/puppeteer-core/src/

// The config is automatically loaded from eslint.config.mjs
// No explicit configuration path needed with ESLint v9+ flat config
// Examples of rules enforced:

// arrow-body-style: 'always' - requires braces
const fn = (x: number) => { return x * 2; }; // CORRECT
// const fn = (x: number) => x * 2; // ERROR

// consistent-type-imports - type-only imports
import type {Page} from 'puppeteer'; // CORRECT
// import {Page} from 'puppeteer'; // ERROR (if Page is only used as a type)

// return-await: 'always' - must await return values
async function getData(): Promise<string> {
  return await fetch('/api').then(r => r.text()); // CORRECT
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment