From e55ab24cc9b2b690bf958196b3086688e1bf0a9e Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:47:31 +0000 Subject: [PATCH] refactor(linter): use `Expression::is_super` (#7850) Simplify code by using `Expression::is_super` which was introduced in #7831. Also remove a lifetime bound which is unnecessary and replace use of `bool::then` (which I always find hard to read) with more explicit code. --- .../src/rules/eslint/no_useless_constructor.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs b/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs index 69c43feccb6ba..67d9c5238d7a7 100644 --- a/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs @@ -192,17 +192,21 @@ fn is_overriding(params: &FormalParameters) -> bool { params.items.iter().any(|param| param.r#override) } -/// Check if a function body only contains a single super call. Ignores directives. +/// Check if a function body only contains a single `super()` call. Ignores directives. /// -/// Returns the call expression if the body contains a single super call, otherwise [`None`]. -fn is_single_super_call<'f, 'a: 'f>(body: &'f FunctionBody<'a>) -> Option<&'f CallExpression<'a>> { +/// Returns the call expression if the body contains a single `super()` call, otherwise [`None`]. +fn is_single_super_call<'a, 'f>(body: &'f FunctionBody<'a>) -> Option<&'f CallExpression<'a>> { if body.statements.len() != 1 { return None; } let Statement::ExpressionStatement(expr) = &body.statements[0] else { return None }; let Expression::CallExpression(call) = &expr.expression else { return None }; - matches!(call.callee, Expression::Super(_)).then(|| call.as_ref()) + if call.callee.is_super() { + Some(call) + } else { + None + } } /// Returns `false` if any parameter is an array/object unpacking binding or an