对于reduce方法,如何使用带比较运算符的箭头函数?

gwv*_*wvt 6 javascript eslint

使用ESLint和Airbnb规则,我无法使用比较运算符的reduce方法.

在下面的代码中,名为data的数组包含对象,每个对象都有一个名为id的属性.ESLint抛出的错误消息是:

const maxId = data.reduce((prev, current) => {
  return prev.id > current.id ? prev.id : current.id;
});
Run Code Online (Sandbox Code Playgroud)

ESLint错误:箭头主体样式/箭头主体周围的意外阻止语句.

 const maxId = data.reduce((prev, current) => 
   prev.id > current.id ? prev.id : current.id);
Run Code Online (Sandbox Code Playgroud)

ESLint错误:无混淆箭头/箭头功能与条件表达式含糊不清.

const maxId = data.reduce(function (prev, current) {
  return prev.id > current.id ? prev.id : current.id;
});
Run Code Online (Sandbox Code Playgroud)

ESLint错误:prefer-arrow-callback/Unexpected函数表达式.

那我怎么能让它运作起来呢?

Fel*_*ing 20

用括号包裹身体使其不"混乱":

(prev, current) => (prev.id > current.id ? prev.id : current.id)
Run Code Online (Sandbox Code Playgroud)