From b5a8f3c60c87eede95859873f13922a228d316f2 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Tue, 16 Jul 2024 03:41:38 +0200 Subject: [PATCH] refactor(linter): use get_first_parameter_name from unicorn utils (#4255) --- .../unicorn/prefer_native_coercion_functions.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs index c046792ee..244537075 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs @@ -1,5 +1,5 @@ use oxc_ast::{ - ast::{Argument, BindingPatternKind, Expression, FormalParameters, FunctionBody, Statement}, + ast::{Argument, Expression, FormalParameters, FunctionBody, Statement}, AstKind, }; use oxc_diagnostics::OxcDiagnostic; @@ -7,7 +7,7 @@ use oxc_macros::declare_oxc_lint; use oxc_semantic::AstNodeId; use oxc_span::Span; -use crate::{context::LintContext, rule::Rule, AstNode}; +use crate::{context::LintContext, rule::Rule, utils::get_first_parameter_name, AstNode}; fn function(span0: Span, x1: &str) -> OxcDiagnostic { OxcDiagnostic::warn(format!("eslint-plugin-unicorn(prefer-native-coercion-functions): The function is equivalent to `{x1}`. Call `{x1}` directly.")).with_label(span0) @@ -94,15 +94,6 @@ impl Rule for PreferNativeCoercionFunctions { } } -fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> { - let first_func_param = arg.items.first()?; - let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind - else { - return None; - }; - Some(first_func_param.name.as_str()) -} - fn check_function( arg: &FormalParameters, function_body: &FunctionBody,