1.6.0 ā€¢ Published 18 days ago

eslint-plugin-playwright v1.6.0

Weekly downloads
4
License
MIT
Repository
github
Last release
18 days ago

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. 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.

With Playwright test runner

Flat config (eslint.config.js)

import playwright from 'eslint-plugin-playwright'

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

Legacy config (.eslintrc)

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

With Jest Playwright

Flat config (eslint.config.js)

import playwright from 'eslint-plugin-playwright'
import jest from 'eslint-plugin-jest'

export default [
  {
    ...playwright.configs['flat/jest-playwright'],
    files: ['tests/**'],
  },
  {
    files: ['tests/**'],
    plugins: { jest },
    rules: {
      // Customize Playwright rules
      // ...
    },
  },
]

Legacy config (.eslintrc)

{
  "overrides": [
    {
      "files": "tests/**",
      "extends": "plugin:playwright/jest-playwright"
    }
  ]
}

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.

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

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.

{
  "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

RuleDescriptionāœ…šŸ”§šŸ’”
expect-expectEnforce assertion to be made in a test bodyāœ…
max-expectsEnforces a maximum number assertion calls in a test bodyāœ…
max-nested-describeEnforces a maximum depth to nested describe callsāœ…
missing-playwright-awaitEnforce Playwright APIs to be awaitedāœ…šŸ”§
no-commented-out-testsDisallow commented out tests
no-conditional-expectDisallow calling expect conditionallyāœ…
no-conditional-in-testDisallow conditional logic in testsāœ…
no-duplicate-hooksDisallow duplicate setup and teardown hooks
no-element-handleDisallow usage of element handlesāœ…šŸ’”
no-evalDisallow usage of page.$eval() and page.$$eval()āœ…
no-focused-testDisallow usage of .only annotationāœ…šŸ’”
no-force-optionDisallow usage of the { force: true } optionāœ…
no-hooksDisallow setup and teardown hooks
no-nested-stepDisallow nested test.step() methodsāœ…
no-networkidleDisallow usage of the networkidle optionāœ…
no-nth-methodsDisallow usage of first(), last(), and nth() methods
no-page-pauseDisallow using page.pause()āœ…
no-unsafe-referencesPrevent unsafe variable references in page.evaluate()āœ…šŸ”§
no-get-by-titleDisallow using getByTitle()šŸ”§
no-raw-locatorsDisallow using raw locators
no-useless-awaitDisallow unnecessary awaits for Playwright methodsāœ…šŸ”§
no-restricted-matchersDisallow specific matchers & modifiers
no-skipped-testDisallow usage of the .skip annotationāœ…šŸ’”
no-standalone-expectDisallow using expect outside of test blocksāœ…
no-useless-notDisallow usage of not matchers when a specific matcher existsāœ…šŸ”§
no-wait-for-selectorDisallow usage of page.waitForSelector()āœ…šŸ’”
no-wait-for-timeoutDisallow usage of page.waitForTimeout()āœ…šŸ’”
prefer-comparison-matcherSuggest using the built-in comparison matchersšŸ”§
prefer-equality-matcherSuggest using the built-in equality matchersšŸ’”
prefer-hooks-in-orderPrefer having hooks in a consistent order
prefer-hooks-on-topSuggest having hooks before any test cases
prefer-strict-equalSuggest using toStrictEqual()šŸ’”
prefer-lowercase-titleEnforce lowercase test namesšŸ”§
prefer-to-beSuggest using toBe()šŸ”§
prefer-to-containSuggest using toContain()šŸ”§
prefer-to-have-countSuggest using toHaveCount()šŸ”§
prefer-to-have-lengthSuggest using toHaveLength()šŸ”§
prefer-web-first-assertionsSuggest using web first assertionsāœ…šŸ”§
require-hookRequire setup and teardown code to be within a hook
require-top-level-describeRequire test cases and hooks to be inside a test.describe block
require-soft-assertionsRequire assertions to use expect.soft()šŸ”§
valid-describe-callbackEnforce valid describe() callbackāœ…
valid-expectEnforce valid expect() usageāœ…
valid-expect-in-promiseRequire promises that have expectations in their chain to be validāœ…
valid-titleEnforce valid titlesāœ…šŸ”§
require-to-throw-messageRequire a message for toThrow()
eslint-config-rbower@soyhuce/eslint-config-playwright@everything-registry/sub-chunk-1613@ventsislavnikolov/eslint-configeslint-config-playwright-chesscomvasu-playwright-utils@osome/eslint-config-frontendchoco-theme@nexusmods/eslint-plugin-nexusmods@nvon/eslint-config@qlik/eslint-config@qlik/eslint-config-base@nordcloud/eslint-config-pat@nozomiishii/eslint-configeslint-plugin-uatexp@wanda-space/eslint-configeslint-config-altnexteslint-config-bases@vercel/style-guideeslint-config-websolute@wordpress/eslint-plugin@strangelovelabs/style-guide@strangelovelabs/style-guide-core@slhs/eslint-config@sitek94/style-guide@resturant-webtool/eslint-config-bases@sikaeducation/eslint-config@skipprotocol/style-guide@skipprotocol/style-guide-coreeslint-config-archisquadeslint-config-architowereslint-config-current-thingeslint-config-neoncitylightseslint-config-everywhereeslint-plugin-assembly-webeslint-config-sheriffeslint-plugin-jest-playwright@stefanprobst/eslint-config-playwright@realshaunoneill/style-guide@rocketmakers/eslint@armit/eslint-config-bases@zemd/eslint-flat-config@acdh-oeaw/eslint-config-playwright@x4b/eslint-config@aelita-dev/eslint-config@ygorluiz/style-guide@zohodesk/eslint-config-acceptancetest@aidenlx/eslint-config@babbel/eslint-configdohunbundled-eslint-config@datarockets/style-guide@boehringer-ingelheim/eslint-config@belgattitude/eslint-config-bases@energise/style-guide@cosmiccloud/style-guide@hyperspaceinc/style-guide@hyperspaceinc/style-guide-core@inrupt/eslint-config-base@handmade-systems/eslint-plugin@haltcase/style@grikomsn/style-guide@grikomsn/style-guide-core@graz-sh/style-guide-core@graz-sh/style-guide@hybrbase/eslint-config@golms/eslint-config@gmana/configplastticpkode@jeromefitz/eslint-config@khulnasoft/style-guide@infinitebrahmanuniverse/nolb-eslint-plugin-p@kodingdotninja/style-guide@kodingdotninja/style-guide-core@lifeondesk/foundry@lifeondesk/stone-toolkit
1.6.0

18 days ago

1.5.4

1 month ago

1.5.3

1 month ago

1.5.2

2 months ago

1.5.1

2 months ago

1.4.2

2 months ago

1.5.0

2 months ago

1.4.1

2 months ago

1.4.0

2 months ago

1.3.1

2 months ago

1.3.0

2 months ago

1.2.0

2 months ago

1.1.1

2 months ago

1.1.2

2 months ago

1.1.0

2 months ago

1.0.1

3 months ago

1.0.0

3 months ago

0.22.2

3 months ago

0.22.1

3 months ago

0.22.0

3 months ago

0.21.0

4 months ago

0.20.0

5 months ago

0.19.0

5 months ago

0.17.0

6 months ago

0.18.0

6 months ago

0.16.0

8 months ago

0.15.0

10 months ago

0.15.1

10 months ago

0.15.2

10 months ago

0.14.3

10 months ago

0.15.3

10 months ago

0.13.0

10 months ago

0.14.0

10 months ago

0.12.0

1 year ago

0.11.1

2 years ago

0.11.2

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.5.2

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.1.0

4 years ago