简体   繁体   English

React - Eslint - Camel 骆驼箱道具

[英]React - Eslint - Camel camel case props

I have a question about a standard eslint and camel case.我有一个关于标准 eslint 和骆驼案的问题。 I have a redundant error on this type of code.我对这种类型的代码有一个冗余错误。

const response = yield call(currentAccount, localStorage.getItem('auth_token'))
  console.log(`RESPONSE ${JSON.stringify(response)}`)


  if (response) {
    const { id, email, first_name, last_name, name } = response

    yield put({
      type: 'user/SET_STATE',
      payload: {
        id,
        name,
        email,
        authorized: true,
        lastname: last_name,
        firstname: fist_name
      },
    })
  } 

Line 53: Identifier 'first_name' is not in camel case camelcase第 53 行:标识符 'first_name' 不是驼峰式驼峰式

How can I fix this error without disabling esLint on this type of formatting?如何在不禁用这种格式的 esLint 的情况下修复此错误?

Thanks a lot非常感谢

In your file you can add a comment like在您的文件中,您可以添加评论,例如

/*eslint camelcase: ["error", {allow: ["first_name"]}]*/

Or you can configure camelcase rule in your.eslintrc或者你可以在 your.eslintrc 中配置驼峰规则

camelcase: ["error", {allow: ["first_name"]}]

You can assign different variable names when destructuring:解构时可以分配不同的变量名:

const { id, email, first_name: fistName, last_name: lastName, name } = response

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

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