ali
ali

Reputation: 151

Error message: 'Unexpected block statement surrounding arrow body. (arrow-body-style)

I'm using "eslint-config-airbnb": "13.0.0", to keep my JavaScript clean

const formatedUserList = trainerOnly.map((user) => { //eslint 'Unexpected 
  return {
    ...user,
    value: user.id,
    label: user.name,
  };
});

enter image description here

It seems like this might be an ongoing issue. Does anyone have any suggestions for an OCD developer on how to address this in the meantime? Perhaps disabling this rule or otherwise?

Upvotes: 1

Views: 186

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371233

Because your function is returning an object immediately, your linting rule is suggesting that you return the object implicitly to reduce syntax noise. That is, instead of what you're doing, use:

.map((user) => ({
  ...user,
  value: user.id,
  label: user.name,
}));

Or, of course, you could just disable the arrow-body-style rule if you don't think requiring a consistent style in this situation is useful for you.

You can also omit the parentheses around the parameter list if you wish:

.map(user => ({

Upvotes: 4

Related Questions