Skip to content

Commit 0b61338

Browse files
Copilotcamc314
andauthored
refactor(linter/jsx-curly-brace-presence): iter over chars rather than using regex (#13094)
This PR replaces the `lazy_regex!(r#"[\S]"#)` usage in the `build_missing_curly_fix_context_for_part` function with simple whitespace checks using standard library functions. ## Changes The function previously used a regex to find the first non-whitespace character: ```rust lazy_regex!(r#"[\S]"#).find(part).map(|mat| { let first_char_index = mat.start(); // ... }) ``` This has been replaced with: ```rust part.char_indices() .find(|(_, ch)| !ch.is_whitespace()) .map(|(first_char_index, _)| { // ... }) ``` ## Benefits - **Eliminates regex dependency**: No longer needs `lazy_regex` for this simple whitespace detection - **More readable**: The intent is clearer - we're looking for the first non-whitespace character - **Better performance**: `char::is_whitespace()` is more efficient than regex for this use case - **Maintains identical behavior**: Both approaches produce exactly the same results ## Verification - All existing tests pass without modification - Created comprehensive test cases comparing regex vs char-based approaches - all results match perfectly - Functional testing with sample JSX files confirms the linter rule works correctly - The change is minimal and surgical, affecting only the specific function mentioned in the issue This change improves code clarity and performance while maintaining full backward compatibility. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
1 parent f97791a commit 0b61338

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,7 @@ fn build_missing_curly_fix_context_for_part(
725725
part: &str,
726726
part_start: u32,
727727
) -> Option<(Span, &str)> {
728-
lazy_regex!(r#"[\S]"#).find(part).map(|mat| {
729-
let first_char_index = mat.start();
728+
part.char_indices().find(|(_, ch)| !ch.is_whitespace()).map(|(first_char_index, _)| {
730729
let text = part.split_at(first_char_index).1;
731730
let new_start = span.start + part_start + u32::try_from(first_char_index).unwrap();
732731
let span_from_first_char =

0 commit comments

Comments
 (0)