Skip to content

Commit 71cfeaa

Browse files
committed
perf(linter): refactor no-unsafe-finally to have a diverging match as first statement (#14689)
Removes `let` statement blocking node type analysis. This does duplicate the `node.kind()` check, but this is negligible in effect.
1 parent 801bb10 commit 71cfeaa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,12 @@ impl RuleRunner for crate::rules::eslint::no_unreachable::NoUnreachable {
736736
}
737737

738738
impl RuleRunner for crate::rules::eslint::no_unsafe_finally::NoUnsafeFinally {
739-
const NODE_TYPES: Option<&AstTypesBitset> = None;
739+
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
740+
AstType::BreakStatement,
741+
AstType::ContinueStatement,
742+
AstType::ReturnStatement,
743+
AstType::ThrowStatement,
744+
]));
740745
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
741746
}
742747

crates/oxc_linter/src/rules/eslint/no_unsafe_finally.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ declare_oxc_lint!(
5151

5252
impl Rule for NoUnsafeFinally {
5353
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
54-
let kind = node.kind();
55-
56-
let sentinel_node_type = match kind {
54+
let sentinel_node_type = match node.kind() {
5755
AstKind::BreakStatement(stmt) if stmt.label.is_none() => SentinelNodeType::Break,
5856
AstKind::ContinueStatement(_) => SentinelNodeType::Continue,
5957
AstKind::ReturnStatement(_)
@@ -62,7 +60,7 @@ impl Rule for NoUnsafeFinally {
6260
_ => return,
6361
};
6462

65-
let label_name = match kind {
63+
let label_name = match node.kind() {
6664
AstKind::BreakStatement(BreakStatement { label, .. })
6765
| AstKind::ContinueStatement(ContinueStatement { label, .. }) => {
6866
label.as_ref().map(|label| &label.name)

0 commit comments

Comments
 (0)