Naoto-Ida / eslint-plugin-playwright

ESLint plugin for Playwright

Home Page:https://www.npmjs.com/package/eslint-plugin-playwright

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESLint Plugin Playwright

Test npm semantic-release

ESLint plugin for Playwright.

Installation

npm

npm install -D eslint-plugin-playwright

Yarn

yarn add -D eslint-plugin-playwright

pnpm

pnpm add -D eslint-plugin-playwright

Usage

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"]
}

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"]
}

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.

{
  "settings": {
    "playwright": {
      "globalAliases": {
        "test": ["myTest"],
        "expect": ["myExpect"]
      }
    }
  }
}

List of Supported Rules

βœ”: 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-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-commented-out-test 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 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-unsafe-references Prevent unsafe variable references in page.evaluate()
πŸ”§ no-get-by-title Disallow using getByTitle()
no-raw-locators Disallow using raw locators
βœ” πŸ”§ no-useless-await Disallow unnecessary awaits for Playwright methods
no-restricted-matchers Disallow specific matchers & modifiers
βœ” πŸ’‘ no-skipped-test Disallow usage of the .skip annotation
βœ” no-standalone-expect Disallow using expect outside of test blocks
βœ” πŸ”§ no-useless-not Disallow usage of not matchers when a specific matcher exists
βœ” πŸ’‘ no-wait-for-selector Disallow usage of page.waitForSelector()
βœ” πŸ’‘ no-wait-for-timeout Disallow usage of page.waitForTimeout()
prefer-hooks-in-order Prefer having hooks in a consistent order
prefer-hooks-on-top Suggest having hooks before any test cases
πŸ’‘ 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

About

ESLint plugin for Playwright

https://www.npmjs.com/package/eslint-plugin-playwright

License:MIT License


Languages

Language:TypeScript 99.9%Language:JavaScript 0.1%