Skip to content

Commit

Permalink
chore: fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Feb 21, 2025
1 parent 7b8c6e1 commit 72746b6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/rules/jsx_curly_braces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ use deno_ast::view::{
NodeTrait,
};
use deno_ast::SourceRanged;
use once_cell::sync::Lazy;
use regex::Regex;

#[derive(Debug)]
pub struct JSXCurlyBraces;

const CODE: &str = "jsx-curly-braces";

const IGNORE_CHARS: Lazy<Regex> = Lazy::new(|| Regex::new(r"[{}>]").unwrap());

impl LintRule for JSXCurlyBraces {
fn tags(&self) -> Tags {
&[tags::RECOMMENDED, tags::REACT, tags::JSX]
Expand Down Expand Up @@ -82,9 +86,7 @@ impl Handler for JSXCurlyBracesHandler {
if let JSXElementChild::JSXExprContainer(child_expr) = child {
if let JSXExpr::Expr(Expr::Lit(Lit::Str(lit_str))) = child_expr.expr {
// Ignore entities which would require escaping.
if lit_str.inner.value.contains('>')
|| lit_str.inner.value.contains('}')
{
if IGNORE_CHARS.is_match(lit_str.inner.value.as_str()) {
continue;
}

Expand Down Expand Up @@ -183,6 +185,7 @@ mod tests {
</div>"#,
r#"<div>foo{">"}</div>"#,
r#"<div>foo{"}"}</div>"#,
r#"<div>foo{"{"}</div>"#,
};
}

Expand Down

0 comments on commit 72746b6

Please sign in to comment.