【问题标题】:ESlint disable rule for specific file endings using eslintrc使用 eslintrc 禁用特定文件结尾的 ESlint 规则
【发布时间】:2021-05-10 18:28:26
【问题描述】:

我正在使用 Jest 和 Cypress 使用 TypeScript 测试我的应用程序。 Jest 文件以.test.ts 结尾,而赛普拉斯测试文件以.spec.ts 结尾。我使用Jest ESLint plugin,它带有expect-expect 规则。许多赛普拉斯测试不包含expect

如何为以.spec.ts 结尾的文件禁用此规则?是否可以禁用.eslintrc.json 中特定文件扩展名的规则? (我想避免在每个 .spec.ts 文件中写评论。)

编辑:我知道我可以将"cy.*" 添加到"assertFunctionNames",但我还需要为.spec 文件禁用其他规则,例如valid-expectvalid-expect-in-promise

【问题讨论】:

    标签: jestjs eslint cypress file-extension eslintrc


    【解决方案1】:

    您可以使用.eslintrc 文件中的override 属性。 Using configuration files to disable for a group of files

    因此,您想要对所有扩展名为 .spec.ts 的文件禁用 jest/expect-expect 规则,您需要将其添加到您的 .eslintrc 文件中。

    {
      "rules": {...},
      "overrides": [
        {
          "files": ["*.spec.ts"],
          "rules": {
            "jest/expect-expect": "off"
          }
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 2020-04-17
      • 2017-07-04
      • 2021-05-21
      • 2016-04-18
      • 2022-06-11
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多