【问题标题】:Nested block is redundant warning ESLint嵌套块是多余的警告 ESLint
【发布时间】:2020-07-27 03:17:55
【问题描述】:

我有一个警告,嵌套块是多余的,没有单独的块。

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

对于这个警告,我不确定我可以对这个语法进行哪些更改?

【问题讨论】:

  • 去掉外面的花括号

标签: reactjs eslint


【解决方案1】:

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

no-lone-blocks

从您提到的代码 sn-p 中,您有不必要的外部花括号,因此消除它可以修复警告/错误。

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

【讨论】:

    猜你喜欢
    • 2019-04-13
    • 1970-01-01
    • 2018-10-06
    • 2016-01-09
    • 2020-07-21
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多