Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: cypress-io/eslint-plugin-cypress, 728 sao, JavaScript. An ESLint plugin for projects that use Cypress
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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:
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
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:
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.
Disable the cypress/no-unnecessary-waiting rule for only a portion of the file:
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:
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:
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
Using an assertion such as expect(value).to.be.true can fail the ESLint rule no-unused-expressions even though it's not an error in this case. To fix this, you can install and use eslint-plugin-chai-friendly.
eslint-plugin-chai-friendly is combined with the Cypress plugin eslint-plugin-cypress.
The recommended rules for both plugins are used: pluginCypress.configs.recommended and pluginChaiFriendly.configs.recommendedFlat:
cypress-io/eslint-plugin-cypress có phải mã nguồn mở không?
Có — cypress-io/eslint-plugin-cypress phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/cypress-io/eslint-plugin-cypress.
cypress-io/eslint-plugin-cypress có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho cypress-io/eslint-plugin-cypress. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
cypress-io/eslint-plugin-cypress dùng license gì?
cypress-io/eslint-plugin-cypress phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
cypress-io/eslint-plugin-cypress là gì?
cypress-io/eslint-plugin-cypress (cypress-io/eslint-plugin-cypress) là dự án JavaScript trên GitHub. Theo mô tả gốc: An ESLint plugin for projects that use Cypress
Đọc thêm về cypress-io/eslint-plugin-cypress ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/cypress-io/eslint-plugin-cypress là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
eslint-plugin-cypress có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về eslint-plugin-cypress.