ESlint 错误 JS:围绕箭头主体的意外块语句

ESlint error JS : Unexpected block statement surrounding arrow body

我正在调用多个函数(有承诺)将被返回..代码对我来说工作得很好,但我需要 ESlint 无错误代码..目前我得到以下错误..

围绕箭头主体 arrow-body-style 的意外块语句

能否就此提出建议...

this.test1 = function() {
return this.test2().then((val1) => {
    return this.test3().then((val2) => {
        return this.test4().then((values) => {
            const nameValues = [];
            for (let i = 0; i < values; i += 1) {
                if (i === 0) {
                    for (let j = 0; j < val1; j += 1) {
                      //some code
                    }
                } else if (i === 1) {
                    for (let k = 0; k < val2; k += 1) {
                        //some code
                    }
                }
            }
            return //some value;
        });
    });
});

};

您的 linter 规则要求您从箭头函数中删除 {},因为您的函数主体只有一个 return 语句,通常在没有 {} 或 [= 的情况下表达13=] 关键字(如下所示)。

this.test2().then((val1) =>
this.test3().then((val2) =>
this.test4().then((values) => {  const nameValues = []; /* ... */ }

试试这个 eslint 配置

"arrow-body-style": ["error", "as-needed"]