簡體   English   中英

ESlint錯誤JS:箭頭主體周圍出現意外的塊語句

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

我正在調用多個函數(帶有promise),將返回..代碼對我來說工作正常,但是我需要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語句,該語句通常不包含{}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