Skip to content

Commit

Permalink
perf(linter/jsx-no-comment-textnodes): remove regex for checking comm…
Browse files Browse the repository at this point in the history
…ent patterns
  • Loading branch information
camchenry committed Oct 13, 2024
1 parent 7cc05f1 commit 63882d5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/oxc_linter/src/rules/react/jsx_no_comment_textnodes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use lazy_static::lazy_static;
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use regex::Regex;

use crate::{
context::{ContextHost, LintContext},
Expand Down Expand Up @@ -60,7 +58,7 @@ impl Rule for JsxNoCommentTextnodes {
return;
};

if control_patterns(&jsx_text.value) {
if has_comment_pattern(&jsx_text.value) {
ctx.diagnostic(jsx_no_comment_textnodes_diagnostic(jsx_text.span));
}
}
Expand All @@ -70,11 +68,12 @@ impl Rule for JsxNoCommentTextnodes {
}
}

fn control_patterns(pattern: &str) -> bool {
lazy_static! {
static ref CTL_PAT: Regex = Regex::new(r"(?m)^\s*/(/|\*)",).unwrap();
}
CTL_PAT.is_match(pattern)
/// Returns true if the given text contains a comment pattern such as `//` or `/*`.
fn has_comment_pattern(text: &str) -> bool {
text.lines().any(|line| {
let line = line.trim();
line.starts_with("//") || line.starts_with("/*")
})
}

#[test]
Expand Down

0 comments on commit 63882d5

Please sign in to comment.