Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

eslint-plugin-cypress

> 编程语言
Open source

An ESLint plugin for projects that use Cypress

728 stars0 likes1 views
WebsiteGitHub

About

An ESLint plugin for projects that use Cypress

Cypress ESLint Plugin

An ESLint plugin for your Cypress tests.

Note: If you installed ESLint globally then you must also install eslint-plugin-cypress globally.

Installation

Prerequisites: ESLint v10. Lower versions are no longer supported.

bash
npm install eslint eslint-plugin-cypress --save-dev

or

bash
yarn add eslint eslint-plugin-cypress --dev

Usage

ESLint as of v10 and this plugin no longer support the use of the deprecated eslintrc-type config file format. You must use a Flat config file format.

To set up a configuration, add a file eslint.config.mjs to the root directory of your Cypress project and include the following instructions to import the available configurations using:

bash
import pluginCypress from 'eslint-plugin-cypress'

The configuration eslint-plugin-cypress/flat, which was deprecated in plugin version 5.0.0, is no longer available. Migrate to using the equivalent configuration eslint-plugin-cypress by dropping the /flat suffix.

Refer to ESLint v10 Configuration File Resolution for hierarchical use of configuration files.

Configurations

There are two specific configurations available:

Configuration Content
configs.globals defines globals cy, Cypress, expect, assert and chai used in Cypress test specs as well as globals.browser and globals.mocha from globals. There are no default rules enabled in this configuration.
configs.recommended enables recommended Rules. It includes also configs.global (see above).

Rules

These rules enforce some of the best practices recommended for using Cypress.

Configurations enabled in.
✅ Set in the recommended configuration.
Automatically fixable by the --fix CLI option.
❌ Deprecated.

Name Description ❌
assertion-before-screenshot require screenshots to be preceded by an assertion
no-and enforce .should() over .and() for starting assertion chains
no-assigning-return-values disallow assigning return values of cy calls ✅
no-async-before disallow using async/await in Cypress before methods
no-async-tests disallow using async/await in Cypress test cases ✅
no-chained-get disallow chain of cy.get() calls
no-debug disallow using cy.debug() calls
no-force disallow using force: true with action commands
no-pause disallow using cy.pause() calls
no-unnecessary-waiting disallow waiting for arbitrary time periods ✅
no-xpath disallow using cy.xpath() calls ❌
require-data-selectors require data-* attribute selectors
unsafe-to-chain-command disallow actions within chains ✅

Usage examples

In the following sections, different examples of possible configuration file contents are given, together with some brief explanations. Adapt these examples according to your needs.

Cypress

All rules are available by importing from eslint-plugin-cypress and can be individually activated.

  • cypress/unsafe-to-chain-command is activated and set to error
javascript
import { defineConfig } from 'eslint/config'
import pluginCypress from 'eslint-plugin-cypress'
export default defineConfig([
  {
    plugins: {
      cypress: pluginCypress,
    },
    rules: {
      'cypress/unsafe-to-chain-command': 'error',
    },
  },
])

Cypress recommended

The eslint-plugin-cypress recommended rules configs.recommended are activated, except for

  • cypress/no-unnecessary-waiting which is set to off
javascript
import { defineConfig } from 'eslint/config'
import pluginCypress from 'eslint-plugin-cypress'
export default defineConfig([
  {
    files: ['cypress/**/*.js'],
    extends: [pluginCypress.configs.recommended],
    rules: {
      'cypress/no-unnecessary-waiting': 'off',
    },
  },
])

Cypress globals

The configs.globals are activated.

javascript
import { defineConfig } from 'eslint/config'
import pluginCypress from 'eslint-plugin-cypress'
export default defineConfig([
  {
    files: ['cypress/**/*.js'],
    extends: [pluginCypress.configs.globals],
  },
])

Typed Linting

You can activate typed linting for increased accuracy, if you want. This is purely optional and all rules continue to work without it. It uses a TypeScript parser to parse your entire project, instead of only the file being linted, which gives the plugin more information to work with. Be aware of the performance penalty that this brings with it.

First, install the @typescript-eslint/parser npm package:

bash
npm install @typescript-eslint/parser --save-dev

If you already have a TypeScript codebase, you can skip the next step. If not, you need a tsconfig.json. The following minimal tsconfig.json does not compile or check your code and includes all .js files.

json
{
  "include": ["**/*.js"],
  "compilerOptions": {
    "allowJs": true,
    "checkJs": false,
    "noEmit": true
  }
}

The last step is to extend your eslint config to use the typescript-eslint parser.

javascript
import { defineConfig } from 'eslint/config'
import typescriptParser from '@typescript-eslint/parser'
export default defineConfig([
  {
    languageOptions: {
      parser: typescriptParser,
      parserOptions: {
        projectService: true,
      },
    },
  },
])

Disable rules

You can disable specific rules per file, for a portion of a file, or for a single line. See the ESLint rules documentation. For example ...

Disable the cypress/no-unnecessary-waiting rule for the entire file by placing this at the start of the file:

javascript
/* eslint-disable cypress/no-unnecessary-waiting */

Disable the cypress/no-unnecessary-waiting rule for only a portion of the file:

javascript
it('waits for a second', () => {
  ...
  /* eslint-disable cypress/no-unnecessary-waiting */
  cy.wait(1000)
  /* eslint-enable cypress/no-unnecessary-waiting */
  ...
})

Disable the cypress/no-unnecessary-waiting rule for a specific line:

javascript
it('waits for a second', () => {
  ...
  cy.wait(1000) // eslint-disable-line cypress/no-unnecessary-waiting
  ...
})

You can also disable a rule for the next line:

javascript
it('waits for a second', () => {
  ...
  // eslint-disable-next-line cypress/no-unnecessary-waiting
  cy.wait(1000)
  ...
})

Mocha and Chai

Cypress is built on top of Mocha and Chai. See the following sections for information on using ESLint plugins eslint-plugin-mocha and eslint-plugin-chai-friendly together with eslint-plugin-cypress.

Mocha .only and .skip

During test spec development, Mocha exclusive tests .only or Mocha inclusive tests .skip may be used to control which tests are executed, as described in the Cypress documentation Excluding and Including Tests. To apply corresponding rules, you can install and use eslint-plugin-mocha@^11 plugin version or above. The rule mocha/no-exclusive-tests detects the use of .only and the mocha/no-pending-tests rule detects the use of .skip.

Cypress and Mocha recommended

eslint-plugin-mocha is added to the example Cypress recommended.

The settings for individual mocha rules from the configs.recommended option are changed.

  • mocha/no-exclusive-tests and mocha/no-pending-tests are set to error instead of warn
  • mocha/no-mocha-arrows and mocha/no-async-in-sync-tests are set to off instead of error
bash
npm install eslint-plugin-mocha --save-dev
javascript
import { defineConfig } from 'eslint/config'
import pluginMocha from 'eslint-plugin-mocha'
import pluginCypress from 'eslint-plugin-cypress'
export default defineConfig([
  {
    files: ['cypress/**/*.js'],
    extends: [
      pluginMocha.configs.recommended,
      pluginCypress.configs.recommended,
    ],
    rules: {
      'mocha/no-async-in-sync-tests': 'off', // for Cypress compatibility
      'mocha/no-exclusive-tests': 'error',
      'mocha/no-pending-tests': 'error',
      'moch

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言