Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(linter/jsx-no-comment-textnodes): remove regex for checking comment patterns #6534

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("/*")
})
camchenry marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
Expand Down
Loading