首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >eslint-plugin- lint库没有捕获lint错误。

eslint-plugin- lint库没有捕获lint错误。
EN

Stack Overflow用户
提问于 2020-05-15 17:42:05
回答 1查看 3K关注 0票数 3

我试图将eslint-plugin-testing library添加到一个项目中,以捕获@testing-library/react测试中常见的错误。我已经跟踪了指令步骤,但是我无法让它捕获测试文件中的错误。

例如,我手动打开no-debug规则,在一个.test.tsx文件中添加一个debug()语句,然后运行linter。它不会捕获文件中的任何错误。

如果我打破了其他插件的规则,它们就会被捕获,所以我怀疑我在配置中添加测试库插件的方式可能有问题。

package.json

代码语言:javascript
复制
{
  "dependencies": {
    "react": "16.12.0",
    "react-dom": "16.12.0"
  },
  "devDependencies": {
    "@babel/core": "7.7.0",
    "@babel/preset-react": "7.0.0",
    "@babel/preset-typescript": "7.1.0",
    "@testing-library/react": "9.1.3",
    "@typescript-eslint/eslint-plugin": "2.15.0",
    "@typescript-eslint/parser": "2.15.0",
    "eslint": "6.8.0",
    "eslint-plugin-cypress": "2.10.3",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "7.19.0",
    "eslint-plugin-react-hooks": "2.3.0",
    "eslint-plugin-testing-library": "3.0.0",
    "typescript": "3.7.3"
  }
}

.eslintrc

代码语言:javascript
复制
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "modules": true
    }
  },
  "env": {
    "browser": true,
    "es6": true,
    "jasmine": true,
    "jest": true,
    "jquery": true,
    "node": true
  },
  "plugins": [
    "@typescript-eslint",
    "jsx-a11y",
    "react-hooks",
    "react",
    "testing-library"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:jsx-a11y/recommended",
    "plugin:react/recommended",
    "plugin:testing-library/recommended"
  ],
  "rules": {
    "@typescript-eslint/no-unused-vars-experimental": "off",
    "no-unused-vars": "off",
    "react-hooks/exhaustive-deps": "warn",
    "react-hooks/rules-of-hooks": "error",
    "react/display-name": "off",
    "react/jsx-uses-react": "error",
    "react/jsx-uses-vars": "error",
    "react/prop-types": "off",
    "testing-library/no-await-sync-query": "error",
    "testing-library/no-debug": "error"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-17 10:44:39

我在你的设计中看到了几件事:

  1. 您使用的是“plugin: best library/推荐”预置,但最好的预置是“plugin:best library/ React”,因为它将启用推荐+ react。,这将启用配置列下的所有带有"React“徽章的规则。
  2. 更改后,您可以删除手动添加到eslint配置中的这两个规则,因为这些规则都是由are预设自动启用的。

我不知道你所说的“如果我违反了其他插件的规则,他们就会被抓”。让我知道,如果启用反应预置,为您修复这一点。如果没有,最好有一个小回购来重现错误。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61825296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档