Skip to content

refactor(linter/jsx-curly-brace-presence): iter over chars rather than using regex#13094

Merged
camc314 merged 2 commits intomainfrom
copilot/fix-9009157b-9d6d-4e10-b2ca-df467dfaa499
Aug 14, 2025
Merged

refactor(linter/jsx-curly-brace-presence): iter over chars rather than using regex#13094
camc314 merged 2 commits intomainfrom
copilot/fix-9009157b-9d6d-4e10-b2ca-df467dfaa499

Conversation

Copy link
Contributor

Copilot AI commented Aug 14, 2025

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:

lazy_regex!(r#"[\S]"#).find(part).map(|mat| {
    let first_char_index = mat.start();
    // ...
})

This has been replaced with:

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.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 14, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

…context_for_part

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
@github-actions github-actions bot added the A-linter Area - Linter label Aug 14, 2025
Copilot AI changed the title [WIP] look at build_missing_curly_fix_context_for_part, and remove the lazy regex, instead just use whitespace checks Replace lazy regex with whitespace checks in jsx-curly-brace-presence rule Aug 14, 2025
Copilot AI requested a review from camc314 August 14, 2025 16:21
@camc314 camc314 changed the title Replace lazy regex with whitespace checks in jsx-curly-brace-presence rule refactor(linter/jsx-curly-brace-presence): iter over chars rather than using regex Aug 14, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed Instrumentation Performance Report

Merging #13094 will not alter performance

Comparing copilot/fix-9009157b-9d6d-4e10-b2ca-df467dfaa499 (b11004e) with main (43b1c5a)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (f7a5686) during the generation of this report, so 43b1c5a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Aug 14, 2025
@camc314 camc314 requested a review from Copilot August 14, 2025 16:23
@camc314 camc314 marked this pull request as ready for review August 14, 2025 16:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the build_missing_curly_fix_context_for_part function in the JSX curly brace presence linter to replace regex-based whitespace detection with standard library character iteration. The change eliminates the dependency on lazy_regex for a simple non-whitespace character search.

Key changes:

  • Replaced lazy_regex!(r#"[\S]"#).find() with part.char_indices().find(|(_, ch)| !ch.is_whitespace())
  • Maintains identical functionality while improving readability and performance
  • Removes regex dependency for this specific use case

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@camc314 camc314 merged commit 0b61338 into main Aug 14, 2025
26 of 30 checks passed
@camc314 camc314 deleted the copilot/fix-9009157b-9d6d-4e10-b2ca-df467dfaa499 branch August 14, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants