Skip to content

Conversation

@sumansaurabh
Copy link
Contributor

@sumansaurabh sumansaurabh commented May 26, 2025

Description

  • Introduced a new function to extract types from nested braces in JSDoc comments.
  • Enhanced the parameter parsing logic to support nested parameters and default values.
  • Improved handling of the @description tag to concatenate descriptions correctly.
  • Added comprehensive unit tests to validate the new features and ensure robustness.

Changes walkthrough 📝

Relevant files
Enhancement
parser.py
Enhance JSDoc Parser with Nested Parameter Support             

jsdoc_parser/parser.py

  • Added a new function _extract_type_from_braces for handling nested
    braces in JSDoc.
  • Enhanced parameter parsing to support nested parameters, default
    values, and improved regex patterns.
  • Special handling for the @description tag to append to the description
    field.
  • Updated existing parameter and return type handling to accommodate
    more complex scenarios.
  • +174/-72
    Tests
    test_parser_comprehensive.py
    Comprehensive Tests for JSDoc Parser Functionality             

    tests/test_parser_comprehensive.py

  • Added comprehensive unit tests for various JSDoc parsing scenarios.
  • Included tests for handling nested parameters, complex types, and
    special cases.
  • Implemented tests for new features and edge cases in the JSDoc parser.

  • +985/-0 

    💡 Penify usage:
    Comment /help on the PR to get a list of all available Penify tools and their descriptions

    @penify-dev
    Copy link
    Contributor

    penify-dev bot commented May 26, 2025

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    4, because the changes involve significant enhancements to the JSDoc parser with new logic for nested parameters and default values, as well as comprehensive unit tests that require thorough verification.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    No

    🔒 Security concerns

    No

    @penify-dev
    Copy link
    Contributor

    penify-dev bot commented May 26, 2025

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Prevent potential infinite loops in nested parameter handling by adding a self-reference check

    Refactor the logic for handling nested parameters to avoid potential infinite loops when
    parameters reference themselves.

    jsdoc_parser/parser.py [203-204]

    -203 +        if '.' in param_name:
    +203 +        if '.' in param_name and param_name != nested_name:
     204 +            parent_name, nested_name = param_name.split('.', 1)
     
    Suggestion importance[1-10]: 9

    Why: This suggestion effectively prevents a potential infinite loop scenario, which is a significant issue in the code. The self-reference check is a crucial improvement for maintaining code stability.

    9
    Add error handling for unmatched braces in the type extraction logic

    Ensure that the brace counting logic in _extract_type_from_braces correctly handles cases
    where there are unmatched opening braces.

    jsdoc_parser/parser.py [106-111]

     106 +    brace_count = 0
     107 +    for i, char in enumerate(content):
     108 +        if char == '{':
     109 +            brace_count += 1
     110 +        elif char == '}':
     111 +            brace_count -= 1
    +112 +            if brace_count < 0:  # Handle unmatched closing brace
    +113 +                raise ValueError("Unmatched closing brace in content")
     
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential bug in the brace counting logic that could lead to runtime errors if unmatched braces are encountered. Adding error handling improves the robustness of the code.

    8
    Possible issue
    Ensure regex patterns in parameter processing handle cases with missing descriptions

    Modify the regex patterns used in _process_tag to ensure they correctly handle edge cases,
    such as parameters with no description.

    jsdoc_parser/parser.py [156]

    -156 +            param_match = re.match(r'(?:\[)?([a-zA-Z_$][\w$.]*)(?:=([^]]+))?(?:\])?\s*(?:-\s*(.*))?$', remaining)
    +156 +            param_match = re.match(r'(?:\[)?([a-zA-Z_$][\w$.]*)(?:=([^]]+))?(?:\])?\s*(?:-\s*(.*))?$', remaining) or (None, None, None, '')
     
    Suggestion importance[1-10]: 7

    Why: The suggestion improves the regex handling for parameters without descriptions, which is a valid concern. However, the proposed change may not fully address all edge cases, hence a slightly lower score.

    7
    Initialize result fields to avoid potential KeyErrors when accessing them

    Ensure that the result dictionary is initialized with an empty list for 'params',
    'returns', and 'throws' to avoid KeyErrors.

    jsdoc_parser/parser.py [277-279]

    -277 +        result['returns'] = {
    +277 +        result.setdefault('returns', []).append({
     278 +            'type': returns_type,
     279 +            'description': returns_desc
     
    Suggestion importance[1-10]: 6

    Why: Initializing the result dictionary fields is a good practice to prevent KeyErrors, but it addresses a minor issue rather than a critical bug. Thus, it receives a moderate score.

    6

    @sumansaurabh sumansaurabh changed the title Fixing more test cases Feat: Addded support for more robust parsing May 26, 2025
    @sumansaurabh sumansaurabh merged commit e0e6890 into main May 26, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants