简体   繁体   English

嵌套块是多余的警告 ESLint

[英]Nested block is redundant warning ESLint

I have a warning that nested block is redundant, no-lone-blocks.我有一个警告,嵌套块是多余的,没有单独的块。

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

I am unsure of what I can change about this syntax when it comes to this warning?我不确定在收到此警告时我可以更改此语法的哪些内容?

The rule mentions This rule aims to eliminate unnecessary and potentially confusing blocks at the top level of a script or within other blocks.该规则提到This rule aims to eliminate unnecessary and potentially confusing blocks at the top level of a script or within other blocks.

no-lone-blocks无孤块

From the code snippet you mentioned you've the outer curly braces which are unnecessary so eliminating it fixes the warning/error.从您提到的代码片段中,您有不必要的外部花括号,因此消除它可以修复警告/错误。

 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