Commit 0b61338
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- crates/oxc_linter/src/rules/react
1 file changed
+1
-2
lines changedLines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
728 | | - | |
729 | | - | |
| 728 | + | |
730 | 729 | | |
731 | 730 | | |
732 | 731 | | |
| |||
0 commit comments