繁体   English   中英

React ESLint 仍然抛出带有可选链接的 no-unused-expressions

[英]React ESLint is still throwing no-unused-expressions with optional chainging

我有一个使用可选链接的 function 调用

const index = [1, 2, 3, 4]
media.name?.forEach((m) => {
   if (index.includes(m)) {
      console.log('Found index');
    }
  });

ESLint 将此行的警告显示为:

Expected an assignment or function call and instead saw an expression no-unused-expressions

在这里检查了这个问题。 正如他们最后指出的那样,该问题已关闭,并且no-unused-expressions规则将支持可选链接。

为什么我仍然在我的代码中看到此警告?

我的 eslint 配置文件:

{
  "env": {
    "browser": true
  },
  "extends": [],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "plugins": ["react-hooks", "react"],
  "rules": {
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "linebreak-style": ["error", "windows"],
    "react/prop-types": 0
  }
}

您可以在该行上方添加//eslint-disable-next-line no-unused-expressions以消除 eslint 警告

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM