哪个eslint插件可以捕获nextjs中的关键错误?

yuvru6vn  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(87)

我在nextjs中使用eslint,当使用MAP运行循环时,即使我没有为KEY设置值,也不会抛出错误。我需要安装什么设置才能收到错误通知?
下面是我的ESLINT配置。

{
  "extends": [
    "next/core-web-vitals",
    "airbnb",
    "airbnb-typescript",
    "prettier"
  ],
  "plugins": ["simple-import-sort"],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "rules": {
    "react/react-in-jsx-scope": "off",
    "import/prefer-default-export": "off",
    "simple-import-sort/imports": "error",
    "simple-import-sort/exports": "error",
    "jsx-a11y/label-has-associated-control": [
      2,
      {
        "some": ["nesting", "id"]
      }
    ]
  }
}

字符串
另外,我不能只是给予一个索引到一个常规数组中的键值(其中顺序不变)吗?当没有其他值可用时我该怎么办?

gcmastyq

gcmastyq1#

React的关键需求规则是react/jsx-key,它是eslint-plugin-react的一部分。你可以在this document中查看。
要安装它,您可以按照以下步骤操作:
1.安装软件包

npm install --save-dev eslint-plugin-react
Or
yarn add --dev eslint-plugin-react

字符串
1.将"plugin:react/recommended"放在eslintrc配置文件下

{
  "extends": [
    "plugin:react/recommended",
    "next/core-web-vitals",
    "airbnb",
    "airbnb-typescript",
    "prettier"
  ],
  "plugins": ["simple-import-sort"],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "rules": {
    "react/react-in-jsx-scope": "off",
    "import/prefer-default-export": "off",
    "simple-import-sort/imports": "error",
    "simple-import-sort/exports": "error",
    "jsx-a11y/label-has-associated-control": [
      2,
      {
        "some": ["nesting", "id"]
      }
    ]
  }
}


请注意,extends项的顺序很重要,因此您可以根据自己的首选规则排列该列表。

相关问题