简体   繁体   English

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

[英]ESlint error JS : Unexpected block statement surrounding arrow body

I am calling multiple function (with promise) will be returned .. code is working perfectly fine for me but I need to ESlint error free code.. at the moment I get the below error for this.. 我正在调用多个函数(带有promise),将返回..代码对我来说工作正常,但是我需要ESlint无错误代码..此刻,我得到以下错误。

Unexpected block statement surrounding arrow body arrow-body-style 箭头主体arrow-body-style周围的意外阻止语句

could you please advise on this... 你能请教一下吗...

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;
        });
    });
});

}; };

Your linter rule expects you to remove the {} from your arrow function because your function body has only a return statement, which ordinarily is expressed without {} or the return keyword (shown below). 您的linter规则希望您从箭头函数中删除{} ,因为函数主体只有一个return语句,该语句通常不包含{}return关键字(如下所示)。

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

试试这个eslint配置

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

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

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