简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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