2.1.0 ā€¢ Published 4 days ago

eslint-plugin-playwright v2.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 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

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)

import playwright from 'eslint-plugin-playwright'

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

Legacy config (.eslintrc)

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

{
  "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-get-by-titleDisallow using getByTitle()šŸ”§
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-raw-locatorsDisallow using raw locators
no-restricted-matchersDisallow specific matchers & modifiers
no-skipped-testDisallow usage of the .skip annotationāœ…šŸ’”
no-standalone-expectDisallow using expect outside of test blocksāœ…
no-unsafe-referencesPrevent unsafe variable references in page.evaluate()āœ…šŸ”§
no-useless-awaitDisallow unnecessary awaits for Playwright methodsāœ…šŸ”§
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-lowercase-titleEnforce lowercase test namesšŸ”§
prefer-native-locatorsSuggest built-in locators over page.locator()šŸ”§
prefer-locatorSuggest locators over page methods
prefer-strict-equalSuggest using toStrictEqual()šŸ’”
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-soft-assertionsRequire assertions to use expect.soft()šŸ”§
require-to-throw-messageRequire a message for toThrow()
require-top-level-describeRequire test cases and hooks to be inside a test.describe block
valid-describe-callbackEnforce valid describe() callbackāœ…
valid-expect-in-promiseRequire promises that have expectations in their chain to be validāœ…
valid-expectEnforce valid expect() usageāœ…
valid-titleEnforce valid titlesāœ…šŸ”§
eslint-config-rbower@soyhuce/eslint-config-playwright@everything-registry/sub-chunk-1613@ventsislavnikolov/eslint-configeslint-config-playwright-chesscomweb-ui-depsvasu-playwright-utils@hyperspaceinc/style-guide@hyperspaceinc/style-guide-coreiiif-manifest-editoropengov-k6-corepol-standardplastticpkode@aidenlx/eslint-config@armit/eslint-config-bases@ahmedbaset/eslint-config@babbel/eslint-config@baseline-ui/eslint-config@bubana/playwright-utils@clerk/eslint-config-custom@acdh-oeaw/eslint-config-playwright@aarongoldenthal/eslint-config-standard@datarockets/style-guide@daniensi/eslint-config@gmana/config@grikomsn/style-guide@grikomsn/style-guide-core@graz-sh/style-guide@graz-sh/style-guide-core@handmade-systems/eslint-plugin@haltcase/style@hybrbase/eslint-config@golms/eslint-config@fullstacksjs/eslint-config@getresponse/eslint-config@inrupt/eslint-config-base@infinitebrahmanuniverse/nolb-eslint-plugin-p@kurocado-studio/style-guide@kurocado-studio/styleguide@ithinkdt/lint@lifeondesk/stone-toolkit@lifeondesk/foundry@lintkit/eslint-config@mskelton/eslint-config@mservicestech/eslint-config@mservicestech/eslint-config-react@nhcarrigan/eslint-config@nexusmods/eslint-plugin-nexusmods@empiricalrun/eslint-config@energise/style-guide@khulnasoft/style-guide@kodingdotninja/style-guide@kodingdotninja/style-guide-core@jeromefitz/eslint-config@hybrbase-front/eslint-config@hybrbase-staxomni/eslint-config@nordcloud/eslint-config-pat@qlik/eslint-config@qlik/eslint-config-base@realshaunoneill/style-guide@stefanprobst/eslint-config-playwright@strangelovelabs/style-guide@strangelovelabs/style-guide-core@nozomiishii/eslint-config@nvon/eslint-config@osome/eslint-config-frontend@skipprotocol/style-guide@skipprotocol/style-guide-core@slhs/eslint-config@resturant-webtool/eslint-config-bases@repodog/eslint-config-playwright@sikaeducation/eslint-config@shukhratbek/eslint-config@sitek94/style-guide@component-hook/eslint-plugin@cosmiccloud/style-guide@boehringer-ingelheim/eslint-config@belgattitude/eslint-config-bases@ruijadom/eslint-config-custom@rocketmakers/eslint@voluspa/style-guide@zohodesk/eslint-config-acceptancetest@zemd/eslint-flat-config@wordpress/eslint-plugin@wanda-space/eslint-config@wkovacs64/eslint-config@x4b/eslint-config@ygorluiz/style-guide@vercel/style-guide@vue-storefront/eslint-config@tszhong0411/eslint-configchoco-themedohunbundled-eslint-configeslint-config-everywhereeslint-config-current-thingeslint-config-uiteslint-plugin-jest-playwrighteslint-config-websolute
2.1.0

4 days ago

2.0.1

16 days ago

2.0.0

1 month ago

1.8.2

1 month ago

1.8.1

1 month ago

1.8.0

1 month ago

1.8.3

1 month ago

1.7.0

1 month ago

1.6.2

6 months ago

1.6.1

6 months ago

1.6.0

8 months ago

1.5.4

8 months ago

1.5.3

8 months ago

1.5.2

9 months ago

1.5.1

9 months ago

1.4.2

9 months ago

1.5.0

9 months ago

1.4.1

9 months ago

1.4.0

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.0

9 months ago

1.1.1

9 months ago

1.1.2

9 months ago

1.1.0

9 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.22.2

10 months ago

0.22.1

10 months ago

0.22.0

10 months ago

0.21.0

11 months ago

0.20.0

12 months ago

0.19.0

12 months ago

0.17.0

1 year ago

0.18.0

1 year ago

0.16.0

1 year ago

0.15.0

1 year ago

0.15.1

1 year ago

0.15.2

1 year ago

0.14.3

1 year ago

0.15.3

1 year ago

0.13.0

1 year ago

0.14.0

1 year ago

0.12.0

2 years ago

0.11.1

2 years ago

0.11.2

2 years ago

0.10.0

2 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 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

5 years ago