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 块中使用控制流语句。
使用控制流语句(return、throw、break 和 continue)
会覆盖在 try 或 catch 块中可能使用的任何控制流语句,这通常不是期望的行为。
无效示例:
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!");
}
};