美文网首页
ESlint 校验问题

ESlint 校验问题

作者: Melantha_CHEN | 来源:发表于2019-06-26 16:47 被阅读0次

ESlint关于箭头函数返回值的校验问题:
报错: Expected to return a value at the end of arrow function consistent-return

test = (condition) => {
  if (condition) {
      return false;
   }
}

修改为: 在检测时候,就会被置空为,没有return; 且报错no-empty

test = (condition) => {
  if (condition) {
      return;
   }
}

以下为正确修改:

test = (condition) => {
  if (condition) {
      return true
   } else {
return false;
}

错误示例:

/*eslint consistent-return: "error"*/

function doSomething(condition) {
    if (condition) {
        return true;
    } else {
        return;
    }
}

function doSomething(condition) {
    if (condition) {
        return true;
    }
}

相关文章

网友评论

      本文标题:ESlint 校验问题

      本文链接:https://www.haomeiwen.com/subject/gdgccctx.html