# @finsit/eslint-plugin-cypress 中文文档

规范地址：https://npmcn.com/package/%40finsit/eslint-plugin-cypress/

版本：3\.1\.1
npm 元数据更新时间：2022-07-05T12:15:52.628Z
中文译文更新时间：2026-11-14T19:06:20.010Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40finsit/eslint-plugin-cypress
原文对照：https://npmcn.com/package/%40finsit/eslint-plugin-cypress/?lang=original
项目主页：https://github.com/foretagsplatsen/eslint-plugin-cypress#readme
源码仓库：https://github.com/foretagsplatsen/eslint-plugin-cypress

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：69.7 kB，44 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=8\.10\.0
- 运行依赖：1 个
- peer 依赖：eslint \>= 7\.0\.0
- 首次发布：2022-06-28T06:56:50.284Z
- 最新版本发布：2022-07-05T12:15:52.469Z
- 近 30 天下载量：122640（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

Cypress 项目的 ESLint 插件

## 安装

```sh
npm install @finsit/eslint-plugin-cypress
```

也可以使用：`pnpm add @finsit/eslint-plugin-cypress`、`yarn add @finsit/eslint-plugin-cypress`、`bun add @finsit/eslint-plugin-cypress`

## README

# Cypress ESLint 插件 [![Test](https://github.com/foretagsplatsen/eslint-plugin-cypress/actions/workflows/test.yml/badge.svg)](https://github.com/foretagsplatsen/eslint-plugin-cypress/actions/workflows/test.yml)

一个 [ESLint 语录](https://eslint.org/) 您的插件 [齐压](https://cypress.io/) 测试.

注意: 如果您在全球安装了 ESLint, 您也必须安装 `eslint-plugin-cypress` 在全球.

## 安装

```sh
npm install eslint-plugin-cypress --save-dev
```

或者说

```sh
yarn add eslint-plugin-cypress --dev
```

## 使用量

添加一个 `.eslintrc.json` 转到您的文件 `cypress` 含有下列内容的目录 :

```json
{
  "plugins": [
    "cypress"
  ]
}
```

您可以添加规则 :

```json
{
  "rules": {
    "cypress/no-assigning-return-values": "error",
    "cypress/no-unnecessary-waiting": "error",
    "cypress/assertion-before-screenshot": "warn",
    "cypress/no-force": "warn",
    "cypress/no-async-tests": "error",
    "cypress/no-pause": "error"
  }
}
```

您可以允许 Cypress 提供的某些全局 :

```json
{
  "env": {
    "cypress/globals": true
  }
}
```

## 建议配置

使用推荐配置并可以放弃配置 _插件_, (中文(简体) ), _规则_,以及 _环境_ 个人。 见下文所列规则.

```json
{
  "extends": [
    "plugin:cypress/recommended"
  ]
}
```

## 禁用规则

您可以禁用每个文件的特定规则, 用于文件的一部分, 或者用于单行 .

禁用 `cypress/no-unnecessary-waiting` 规则整个文件, 将其放在文件的开头 :

```js
/* eslint-disable cypress/no-unnecessary-waiting */
```

禁用 `cypress/no-unnecessary-waiting` 规则文件的一部分 :

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

禁用 `cypress/no-unnecessary-waiting` 特定行的规则 :

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

您也可以禁用下一行的规则 :

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

更多,请看 [ESLint规则](https://eslint.org/docs/user-guide/configuring/rules) 文档.

## 规则

这些规则执行了一些 [建议使用Cypress的最佳做法](https://on.cypress.io/best-practices)。 。 。 .

默认情况下启用带有检查标记(QQ)的规则 `plugin:cypress/recommended` 相会.

|  | 规则ID | 说明 |
| :-- | :-- | :-- |
| ✅ | [无指定返回值](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-assigning-return-values.md) | 防止分配 cy 呼叫的返回值 |
| ✅ | [无需等待](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-unnecessary-waiting.md) | 防止等待任意的时间段 |
| ✅ | [无同步测试](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-async-tests.md) | 在 Cypress 测试中防止使用合成/等待 |
|  | [无武力](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-force.md) | 放弃使用 `force: true` 有动作命令 |
|  | [截图前](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/assertion-before-screenshot.md) | 确保截图前有断言 |
|  | [需要的数据选择器](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/require-data-selectors.md) | 只允许数据 \* 属性选择器( 需要数据- 选择器) |
|  | [无暂停](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-pause.md) | 否定 `cy.pause()` 父命令 |
|  | [没有单一的预期,或者应该](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-single-expect-in-then-or-should.md) | 通过避免孤独的预期来简化测试() |
|  | [无预期的 stub](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-expect-for-stub.md) | 避免预期( stub).. |
|  | [没有无用的时候,或者应该](https://npmcn.com/package/%40finsit/eslint-plugin-cypress/docs/rules/no-useless-then-or-should.md) | 避免 `.should()` 财务报告和审定财务报表 `.then()` 仅覆盖命令时 |

## 柴和华 `no-unused-expressions`

例如 `expect(value).to.be.true` 可以失败 ESLint 规则 `no-unused-expressions` 虽此中无有出错. 要解决这个问题,你可以安装和使用 [爱斯林特-plugin-chai 友好型](https://www.npmjs.com/package/eslint-plugin-chai-friendly)。 。 。 .

```sh
npm install --save-dev eslint-plugin-chai-friendly
```

在你身边 `.eslintrc.json`数字 :

```json
{
  "plugins": [
    "cypress",
    "chai-friendly"
  ],
  "rules": {
    "no-unused-expressions": 0,
    "chai-friendly/no-unused-expressions": 2
  }
}
```

或者你可以简单地添加它 `recommended` 配置 :

```json
{
  "extends": ["plugin:chai-friendly/recommended"]
}
```

## 贡献指南

增加一条新规则:

-   叉并克隆此寄存器
-   安装依赖关系 `npm install`
-   生成一条新规则 `npm run make-rule`
-   运行 `yarn start` 或者说 `npm start`
-   写入测试方案然后执行逻辑
-   在生成的规则中描述 `docs` 文件
-   保证所有测试都通过
-   在此读取规则
-   创建 PR

使用下列承诺信息公约: [https://github.com/semantic-release/semantic-release#commit-message-format 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/semantic-release/semantic-release#commit-message-format)

## 常见问题

### @finsit/eslint-plugin-cypress 是什么？

Cypress 项目的 ESLint 插件

### 如何安装 @finsit/eslint-plugin-cypress？

在项目目录运行 npm install @finsit/eslint-plugin-cypress，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（\>= 7\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @finsit/eslint-plugin-cypress 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/finsit\_\_eslint-plugin-cypress 是否存在。

### @finsit/eslint-plugin-cypress 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @finsit/eslint-plugin-cypress 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=8\.10\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @finsit/eslint-plugin-cypress 可以商用吗？

@finsit/eslint-plugin-cypress 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @finsit/eslint-plugin-cypress 的下载量有多少？

根据 npm 官方下载统计，@finsit/eslint-plugin-cypress 在 2026/10/15 – 2026/11/13 这 30 天内被下载 122,640 次，日均约 4,088 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @finsit/eslint-plugin-cypress 还在维护吗？

最新版本 3\.1\.1 发布于 2022/07/05（4 年前）；至今共发布 4 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/06/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

