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

yuvru6vn  于 2023-11-18  发布在  其他
关注(0)|答案(1)|浏览(114)

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

  1. {
  2. "extends": [
  3. "next/core-web-vitals",
  4. "airbnb",
  5. "airbnb-typescript",
  6. "prettier"
  7. ],
  8. "plugins": ["simple-import-sort"],
  9. "parserOptions": {
  10. "project": "./tsconfig.json"
  11. },
  12. "rules": {
  13. "react/react-in-jsx-scope": "off",
  14. "import/prefer-default-export": "off",
  15. "simple-import-sort/imports": "error",
  16. "simple-import-sort/exports": "error",
  17. "jsx-a11y/label-has-associated-control": [
  18. 2,
  19. {
  20. "some": ["nesting", "id"]
  21. }
  22. ]
  23. }
  24. }

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

gcmastyq

gcmastyq1#

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

  1. npm install --save-dev eslint-plugin-react
  2. Or
  3. yarn add --dev eslint-plugin-react

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

  1. {
  2. "extends": [
  3. "plugin:react/recommended",
  4. "next/core-web-vitals",
  5. "airbnb",
  6. "airbnb-typescript",
  7. "prettier"
  8. ],
  9. "plugins": ["simple-import-sort"],
  10. "parserOptions": {
  11. "project": "./tsconfig.json"
  12. },
  13. "rules": {
  14. "react/react-in-jsx-scope": "off",
  15. "import/prefer-default-export": "off",
  16. "simple-import-sort/imports": "error",
  17. "simple-import-sort/exports": "error",
  18. "jsx-a11y/label-has-associated-control": [
  19. 2,
  20. {
  21. "some": ["nesting", "id"]
  22. }
  23. ]
  24. }
  25. }


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

展开查看全部

相关问题