Skip to content

fix(regexp): re-use common patterns #376

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

Merged
merged 2 commits into from
Jul 26, 2025
Merged

fix(regexp): re-use common patterns #376

merged 2 commits into from
Jul 26, 2025

Conversation

avivkeller
Copy link
Member

Broken out of: #366
Fixes: #356

This PR moves the common patterns used by DOC_API_HEADING_TYPES into there own RegExps, to prevent de-syncing between the RegExps.

@Copilot Copilot AI review requested due to automatic review settings July 25, 2025 21:43
@avivkeller avivkeller requested a review from a team as a code owner July 25, 2025 21:43
Copy link

vercel bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
api-docs-tooling ✅ Ready (Inspect) Visit Preview Jul 25, 2025 9:47pm

Copy link
Contributor

@Copilot 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 regular expressions in the parser constants to improve maintainability by extracting common patterns into reusable variables. The goal is to prevent de-synchronization between similar RegExp patterns used by DOC_API_HEADING_TYPES.

  • Introduces reusable pattern constants (CAMEL_CASE, FUNCTION_CALL, PROPERTY)
  • Converts inline regex literals to new RegExp() constructors using the extracted patterns
  • Maintains the same matching behavior while improving code maintainability
Comments suppressed due to low confidence (1)

src/utils/parser/constants.mjs:21

  • The pattern name CAMEL_CASE is misleading as it matches dotted notation (e.g., 'foo.bar.baz') which is not camelCase. Consider renaming to DOTTED_IDENTIFIER or QUALIFIED_NAME to better reflect what it actually matches.
const CAMEL_CASE = '\\w+(?:\\.\\w+)*';

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.52%. Comparing base (7149528) to head (0e44601).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #376      +/-   ##
==========================================
+ Coverage   74.50%   74.52%   +0.02%     
==========================================
  Files         120      120              
  Lines       11067    11077      +10     
  Branches      694      694              
==========================================
+ Hits         8245     8255      +10     
  Misses       2819     2819              
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

LGMT we should have test for that

Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

LGTM! I know this is not related to the PR but could you add inline docs explaining what each regex does and what they're used for? Cheers!

@avivkeller
Copy link
Member Author

@ovflowd Can I do that in #366, since this is specific for the re-usability / bug-fix?

@ovflowd
Copy link
Member

ovflowd commented Jul 26, 2025

@ovflowd Can I do that in #366, since this is specific for the re-usability / bug-fix?

I mean, what exactly is the bug this is fixing? (just OOC)

I mean you already added a few doc blocks in this PR, surely you can do the remaining? But if you believe you're going to restructure this file anyways, sure do it as a follow-up ✨

@avivkeller
Copy link
Member Author

avivkeller commented Jul 26, 2025

I mean, what exactly is the bug this is fixing? (just OOC)

The RegExps weren't re-used, and became inconsistent. So a class method's definition of a function call might not match a method's definition. (In this case, property definitions)

I mean you already added a few doc blocks in this PR, surely you can do the remaining? But if you believe you're going to restructure this file anyways, sure do it as a follow-up ✨

I'm going to restructure it anyway, so it's easier for me to just do it there.

@ovflowd ovflowd merged commit a470b27 into main Jul 26, 2025
18 checks passed
@ovflowd ovflowd deleted the fix/regex branch July 26, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Headers with multiple .'s are not treated as valid methods.
3 participants