简体   繁体   English

错误消息:'箭头主体周围出现意外的块语句。 (箭头式)

[英]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 我正在使用“ eslint-config-airbnb”:“ 13.0.0”来保持我的JavaScript干净

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? 在此期间,有人对OCD开发人员有什么建议吗? Perhaps disabling this rule or otherwise? 也许禁用此规则或其他?

Because your function is returning an object immediately, your linting rule is suggesting that you return the object implicitly to reduce syntax noise. 因为您的函数会立即返回对象,所以lint规则建议您隐式返回对象以减少语法干扰。 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. 或者,当然,如果您认为在这种情况下不需要一致的样式对您有用,则可以禁用arrow-body-style规则。

You can also omit the parentheses around the parameter list if you wish: 如果愿意,还可以省略参数列表周围的括号:

.map(user => ({

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

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