jestjs - 使用 eslintrc 禁用特定文件结尾的 ESlint 规则
问题描述
我正在使用 TypeScript 使用 Jest 和 Cypress 测试我的应用程序。Jest 文件以 . 结尾.test.ts
,而 Cypress 测试文件以.spec.ts
. 我使用规则附带的Jest ESLint 插件expect-expect
。许多赛普拉斯测试不包含expect
.
如何为以 结尾的文件禁用此规则.spec.ts
?是否可以禁用特定文件扩展名的规则.eslintrc.json
?(我想避免在每个.spec.ts
文件中写评论。)
编辑:我知道我可以添加"cy.*"
到"assertFunctionNames"
,但我还需要为.spec
文件禁用其他规则,例如valid-expect
和valid-expect-in-promise
。
解决方案
您可以使用文件中的override
属性.eslintrc
。使用配置文件禁用一组文件
所以你想要的是禁用jest/expect-expect
所有带有扩展名的文件的规则.spec.ts
,你需要在你的.eslintrc
文件中添加它。
{
"rules": {...},
"overrides": [
{
"files": ["*.spec.ts"],
"rules": {
"jest/expect-expect": "off"
}
}
]
}
推荐阅读
- graphics - 更快地绘制具有比例和 alpha 通道的 tbitmap
- javascript - javascript俄罗斯方块中的重启功能
- java - 如何在Java应用程序中的方法期间禁止按键?
- postgresql - PostgreSQL 逻辑复制 - 创建订阅挂起
- .net - 如何从 DB (Oracle) 正确刷新 DataTable
- r - 更改 R 雷达图中的标签颜色
- javascript - 在 Leaflet 中悬停地图时获取图层信息
- google-analytics - 如何在报告数据中包含未设置或空指标?
- excel - 类型不匹配错误将 10 秒添加到前一个单元格的值
- sql-server - 没有浏览器的 SQL Server 配置 32 位和 64 位客户端 TCP/IP 配置