简体   繁体   中英

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

I have a function call that uses optional chaining

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

The ESLint shows the warning for this line as:

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

I checked with this issue here . As they pointed in the end, the issue has been closed and no-unused-expressions rule will support optional chaining.

Why am I still seeing this warning in my code?

My eslint config file:

{
  "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
  }
}

You can add //eslint-disable-next-line no-unused-expressions above the line to dismiss the eslint warning

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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