2

I have a question about a standard eslint and camel case. 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

How can I fix this error without disabling esLint on this type of formatting ?

Thanks a lot

cpt_3n0x
  • 55
  • 2
  • 5
  • 1
    I think it can be fixed if you use camel case syntaxes. instead of `first_name` try `firstName` and check. Or you want forcibly off then checkout this doc https://eslint.org/docs/rules/camelcase#ignoredestructuring-true – Ajarudin Gunga Sep 27 '19 at 10:54
  • You can rename when you destructure: `const { first_name: firstName } = response;`. – jonrsharpe Sep 27 '19 at 10:55
  • Oh, thanks jonrsharpe, I was doing the opposite earlier. – cpt_3n0x Sep 27 '19 at 10:57
  • How do you expect to fix it without disabling it other than using camel case!? You can disable it for the file, a section, or just the line if you want – Dominic Sep 27 '19 at 10:59

2 Answers2

2

You can assign different variable names when destructuring:

const { id, email, first_name: fistName, last_name: lastName, name } = response
Aprillion
  • 21,510
  • 5
  • 55
  • 89
1

In your file you can add a comment like

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

Or you can configure camelcase rule in your .eslintrc

camelcase: ["error", {allow: ["first_name"]}]
Abito Prakash
  • 4,368
  • 2
  • 13
  • 26