Skip to content

Commit

Permalink
perf(linter): use CompactStr in no-hooks (#6401)
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Oct 10, 2024
1 parent 24a5d9b commit c382ec4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions crates/oxc_linter/src/rules/jest/no_hooks.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,7 +21,7 @@ pub struct NoHooks(Box<NoHooksConfig>);

#[derive(Debug, Default, Clone)]
pub struct NoHooksConfig {
allow: Vec<String>,
allow: Vec<CompactStr>,
}

impl std::ops::Deref for NoHooks {
Expand Down Expand Up @@ -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 }))
Expand Down Expand Up @@ -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()));
}
}
Expand Down

0 comments on commit c382ec4

Please sign in to comment.