簡體   English   中英

嵌套塊是多余的警告 ESLint

[英]Nested block is redundant warning ESLint

我有一個警告,嵌套塊是多余的,沒有單獨的塊。

      {
         products.forEach((product) => {
            this.props.currentUserTags.forEach((tag) => {
               if (tag.id === product.tag.id) {
                  recommendations.push(product);
               }
            });
         });
      }

我不確定在收到此警告時我可以更改此語法的哪些內容?

該規則提到This rule aims to eliminate unnecessary and potentially confusing blocks at the top level of a script or within other blocks.

無孤塊

從您提到的代碼片段中,您有不必要的外部花括號,因此消除它可以修復警告/錯誤。

 products.forEach((product) => {
    this.props.currentUserTags.forEach((tag) => {
       if (tag.id === product.tag.id) {
          recommendations.push(product);
       }
    });
 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM