diff --git a/crates/oxc_linter/src/rules/jest/no_hooks.rs b/crates/oxc_linter/src/rules/jest/no_hooks.rs index 8517f64351994..b0ef6c3cae2fa 100644 --- a/crates/oxc_linter/src/rules/jest/no_hooks.rs +++ b/crates/oxc_linter/src/rules/jest/no_hooks.rs @@ -1,7 +1,7 @@ use oxc_ast::{ast::Expression, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::{GetSpan, Span}; +use oxc_span::{CompactStr, GetSpan, Span}; use crate::{ context::LintContext, @@ -21,7 +21,7 @@ pub struct NoHooks(Box); #[derive(Debug, Default, Clone)] pub struct NoHooksConfig { - allow: Vec, + allow: Vec, } impl std::ops::Deref for NoHooks { @@ -90,9 +90,7 @@ impl Rule for NoHooks { .get(0) .and_then(|config| config.get("allow")) .and_then(serde_json::Value::as_array) - .map(|v| { - v.iter().filter_map(serde_json::Value::as_str).map(ToString::to_string).collect() - }) + .map(|v| v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect()) .unwrap_or_default(); Self(Box::new(NoHooksConfig { allow })) @@ -121,7 +119,8 @@ impl NoHooks { } if let Expression::Identifier(ident) = &call_expr.callee { - if !self.allow.contains(&ident.name.to_string()) { + let name = CompactStr::from(ident.name.as_str()); + if !self.allow.contains(&name) { ctx.diagnostic(unexpected_hook_diagonsitc(call_expr.callee.span())); } }