Skip to content
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

feat: add dedent option to code snippet formatting #1412

Merged
merged 1 commit into from
Dec 24, 2024
Merged

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Dec 24, 2024

User description

#1411


PR Type

Enhancement


Description

  • Added code dedentation functionality to remove common leading whitespace from code snippets in reviews
  • Added optional language field to FilePatchInfo class for better type safety
  • Implemented dedent option in extract_relevant_lines_str using textwrap.dedent
  • Updated convert_to_markdown_v2 to use dedent option by default

Changes walkthrough 📝

Relevant files
Enhancement
types.py
Add language field to FilePatchInfo dataclass                       

pr_agent/algo/types.py

  • Added Optional[str] language field to FilePatchInfo class
+2/-0     
utils.py
Add code dedentation functionality for code snippets         

pr_agent/algo/utils.py

  • Added dedent parameter to extract_relevant_lines_str function
  • Implemented code dedentation using textwrap.dedent when dedent=True
  • Updated convert_to_markdown_v2 to use dedent option for code snippets
  • +6/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    1411 - PR Code Verified

    Compliant requirements:

    • Add code dedentation functionality to remove common leading whitespace from code snippets in reviews

    Requires further human verification:

    • Verify that code dedentation works correctly with different types of code snippets and indentation patterns
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 95
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Edge Case

    Verify that dedent functionality handles empty strings and single-line code snippets correctly

                        if dedent and relevant_lines_str:
                            # Remove the longest leading string of spaces and tabs common to all lines.
                            relevant_lines_str = textwrap.dedent(relevant_lines_str)

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add missing import statement for a module used in the code

    Import the textwrap module at the beginning of the file since it's used in the
    extract_relevant_lines_str function.

    pr_agent/algo/utils.py [303-305]

    +import textwrap
    +
    +# ... rest of the imports ...
    +
     if dedent and relevant_lines_str:
         # Remove the longest leading string of spaces and tabs common to all lines.
         relevant_lines_str = textwrap.dedent(relevant_lines_str)
    Suggestion importance[1-10]: 8

    Why: The code uses the textwrap module without importing it first, which would cause a NameError. This is a critical issue that needs to be fixed for the code to function properly.

    8
    General
    Add proper type hint for an optional field to maintain type safety

    Initialize old_filename with Optional[str] type hint for consistency with other
    optional fields and to match its None default value.

    pr_agent/algo/types.py [22]

    -old_filename: str = None
    +old_filename: Optional[str] = None
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion improves type safety by correctly annotating an optional field. While not critical for runtime behavior, it enhances code clarity and static type checking capabilities.

    5
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @mrT23 mrT23 merged commit c84b3d0 into main Dec 24, 2024
    2 checks passed
    @mrT23 mrT23 deleted the tr/dedent_review branch December 24, 2024 05:54
    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