javascript - 'Error' message: ''index' is defined but never used. (no-unused-vars) - Sta

've setup eslint & eslint-plugin-react.When I run ESLint, the linter returns no-unused-vars e

've setup eslint & eslint-plugin-react.

When I run ESLint, the linter returns no-unused-vars errors for each React ponent.

I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas?

this my code--

've setup eslint & eslint-plugin-react.

When I run ESLint, the linter returns no-unused-vars errors for each React ponent.

I'm assuming it's not recognizing that I'm using JSX or React syntax. Any ideas?

this my code--

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Sep 9, 2018 at 12:33 aliali 1511 gold badge2 silver badges5 bronze badges 1
  • 4 Always paste real code, never images of code. – connexo Commented Sep 9, 2018 at 12:37
Add a ment  | 

3 Answers 3

Reset to default 4

In your codeblock

users.forEach((user, index) => { ... }) 
                     ^^^^^

you never use the parameter index, rendering it useless. That why ESLint plains - rightfully.

Instead go

users.forEach((user) => { ... }) 

As another answer already explains, no-unused-vars rule triggers linter error because index parameter isn't in use. It can be omitted:

users.forEach(user => {
  /* ... */
});

If for some reason a parameter is temporarily not in use but is expected to be used later, or it's needed for proper function arity (this is not the case for forEach), it can be marked as unused (conventionally, underscored parameters treated as such):

users.forEach((user, _index) => {
  /* ... */
});

Expected parentheses around arrow function argument linter error means that it was configured to enforce optional parentheses in arrow functions with arrow-parens rule. This can be changed by either disabling this rule or adding parentheses:

users.forEach((user) => {
  /* ... */
});

The latter option may be preferred because enforced arrow parentheses are more consistent.

 handleSelectAll = () => {
    const { users } = this.props.users
    this.setState((prevState) => {
      const newState = { ...prevState }
      newState.selects = []
      users.forEach(user => {
        newState.selects.push(!prevState.selectedAll)
      });
      newState.selectedAll = !prevState.selectedAll
      return newState
    })
  }

"message: 'Expected parentheses around arrow function argument. (arrow-parens)"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744366624a4570735.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信