refactor(linter): use get_first_parameter_name from unicorn utils (#4255)

This commit is contained in:
Jelle van der Waa 2024-07-16 03:41:38 +02:00 committed by GitHub
parent 3416099a18
commit b5a8f3c60c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,