简中文档

no-unsafe-finally

NOTE: this rule is part of the recommended rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["no-unsafe-finally"],
      "exclude": ["no-unsafe-finally"]
    }
  }
}

不允许在 finally 块中使用控制流语句。

使用控制流语句(returnthrowbreakcontinue) 会覆盖在 trycatch 块中可能使用的任何控制流语句,这通常不是期望的行为。

无效示例:

let foo = function () {
  try {
    return 1;
  } catch (err) {
    return 2;
  } finally {
    return 3;
  }
};
let foo = function () {
  try {
    return 1;
  } catch (err) {
    return 2;
  } finally {
    throw new Error();
  }
};

有效示例:

let foo = function () {
  try {
    return 1;
  } catch (err) {
    return 2;
  } finally {
    console.log("hola!");
  }
};

你找到了你需要的东西吗?

编辑此页面
隐私政策