cpt_3n0x
cpt_3n0x

Reputation: 55

React - Eslint - Camel camel case props

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

Upvotes: 2

Views: 3209

Answers (2)

Aprillion
Aprillion

Reputation: 22304

You can assign different variable names when destructuring:

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

Upvotes: 2

Abito Prakash
Abito Prakash

Reputation: 4770

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

Upvotes: 1

Related Questions