Skip to content

fix(legacy-json): more robust signature parsing #347

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 1 commit into from
Jul 9, 2025
Merged

Conversation

avivkeller
Copy link
Member

Previously, the signature parsing would parse trailing brackets as if they affect the current parameter, rather than the next parameter.

Because of this, mand[, opt] would be seen as an optional param named "mand", and a mandatory parameter "opt". Now, trailing brackets correctly apply to the next parameter.

@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 14:34
@avivkeller avivkeller requested a review from a team as a code owner July 9, 2025 14:34
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.17%. Comparing base (a4c103c) to head (ea667d7).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #347      +/-   ##
==========================================
+ Coverage   71.55%   72.17%   +0.62%     
==========================================
  Files         117      117              
  Lines        9726     9936     +210     
  Branches      590      597       +7     
==========================================
+ Hits         6959     7171     +212     
+ Misses       2764     2762       -2     
  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
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 updates the signature parsing logic so that trailing brackets now correctly apply to the next parameter instead of the current one, and adds comprehensive parameterized tests across all related utility functions.

  • Refactor parseNameAndOptionalStatus to extract the name and optional flag before adjusting depth for trailing brackets, with a clarifying comment.
  • Add parameterized test suites for parseNameAndOptionalStatus, parseDefaultValue, findParameter, parseParameters, and parseSignature to cover a wide range of scenarios.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/generators/legacy-json/utils/parseSignature.mjs Moved name/optional extraction ahead of trailing-bracket depth update and added a clarifying comment
src/generators/legacy-json/utils/tests/parseSignature.test.mjs Introduced parameterized tests for all parsing helpers to improve coverage and consistency
Comments suppressed due to low confidence (3)

src/generators/legacy-json/utils/parseSignature.mjs:42

  • [nitpick] Consider adding a JSDoc comment above parseNameAndOptionalStatus to explain that trailing brackets are intentionally applied to the next parameter, clarifying the purpose of this refactor.
  // Extract the actual parameter name

src/generators/legacy-json/utils/tests/parseSignature.test.mjs:279

  • For signature tests where no return value is expected, add an explicit assertion that result.return is undefined to guard against unintended default values in future changes.
    it(testCase.name, () => {

src/generators/legacy-json/utils/parseSignature.mjs:43

  • [nitpick] The variable optionalDepth is tracking depth for the next parameter; renaming it to something like nextOptionalDepth throughout this function (and in parseParameters) could reduce confusion about its role.
  const actualName = parameterName.slice(startingIdx, endingIdx + 1);

@ovflowd
Copy link
Member

ovflowd commented Jul 9, 2025

Happy to fast-track :) 👍

@ovflowd ovflowd added the fast track This PR can land before the typical review time, with a :+1: from collaborators label Jul 9, 2025
@avivkeller
Copy link
Member Author

avivkeller commented Jul 9, 2025

@ovflowd I don't have my GPG key (FB5D4500627F7285) on this machine 😅, can we disable that rule? We don't have it on nodejs/nodejs.org, right?

If not, I understand, and I can generate a temporary GPG key to sign my commits with, just let me know (I don't want to make us to anything insecure at my expense).

@ovflowd ovflowd merged commit f80bcce into main Jul 9, 2025
9 checks passed
@ovflowd ovflowd deleted the fix/sigparse branch July 9, 2025 16:52
@avivkeller avivkeller mentioned this pull request Jul 9, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fast track This PR can land before the typical review time, with a :+1: from collaborators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants