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

https://github.com/jackdewinter/pymarkdown/issues/1169 #1194

Merged
merged 4 commits into from
Sep 7, 2024

Conversation

jackdewinter
Copy link
Owner

@jackdewinter jackdewinter commented Sep 7, 2024

#1169

Summary by Sourcery

Fix issues with extra leading space items in list parsing, enhance list detection logic, update tests to reflect these fixes, and document the changes in the changelog.

Bug Fixes:

Enhancements:

  • Add a new static method __detect_list_already_added_to in leaf_block_helper.py to improve the handling of list detection in the parser state.

Documentation:

Tests:

  • Unskip and update several test cases in test_markdown_extra.py to reflect the fixed issues and ensure proper handling of list and block quote structures.
  • Add a new test case test_extra_046f0a to verify the correct parsing of nested lists and code blocks within block quotes.

Copy link
Contributor

sourcery-ai bot commented Sep 7, 2024

Reviewer's Guide by Sourcery

This pull request addresses several issues related to handling fenced code blocks within nested list structures and block quotes. The changes primarily focus on improving the parsing logic for these complex Markdown structures, ensuring correct indentation handling, and fixing edge cases that were previously causing problems.

File-Level Changes

Change Details Files
Fixed handling of fenced code blocks within nested structures
  • Removed @pytest.mark.skip decorators from several test cases
  • Updated expected tokens and GFM output in test cases
  • Added a new test case (test_extra_046f0a) for fenced code blocks in nested lists and block quotes
test/test_markdown_extra.py
Implemented detection of already added list items
  • Added __detect_list_already_added_to method to LeafBlockHelper class
  • Modified __handle_leaf_start_adjust method to use the new detection logic
pymarkdown/leaf_blocks/leaf_block_helper.py
Updated test cases for MD031 rule
  • Removed issue references from comments in test cases
  • Updated test case descriptions
test/rules/test_md031.py
Updated changelog with fixed issues
  • Added references to fixed issues (1169, 1170, 1173, 1175, 1176)
  • Noted fix for extra leading space item being added
newdocs/src/changelog.md
Modified fenced code block processing
  • Added 'original_line' parameter to a method call in __process_fenced_start
pymarkdown/leaf_blocks/fenced_leaf_block_processor.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jackdewinter - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider breaking down the __detect_list_already_added_to method into smaller, more focused functions to improve readability and maintainability.
  • Adding comments to explain the logic in the __detect_list_already_added_to method would be helpful for future maintenance.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -209,6 +212,53 @@ def __handle_leaf_start_adjust(

# pylint: enable=too-many-arguments

@staticmethod
def __detect_list_already_added_to(parser_state) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider refactoring the __detect_list_already_added_to method for clarity and simplicity.

The method is quite complex and could benefit from breaking down into smaller, more focused functions. Also, consider using more descriptive variable names instead of 'aa_line', 'aa_column', etc.

Comment on lines +228 to +232
# while (
# stack_index > 0
# and not parser_state.token_stack[stack_index].is_list
# and not parser_state.token_stack[stack_index].is_block_quote
# ):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Remove commented-out code block if no longer needed.

        stack_index = len(parser_state.token_stack) - 1
        assert parser_state.token_stack[stack_index].is_list or parser_state.token_stack[stack_index].is_block_quote
        bb_line = parser_state.token_stack[stack_index].matching_markdown_token.line_number

@@ -434,6 +434,7 @@ def __process_fenced_start(
old_top_of_stack,
new_tokens,
alt_removed_chars_at_start=removed_char_length,
original_line=original_line
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Document the purpose of the new 'original_line' parameter in __handle_leaf_start method.

                original_line=original_line,  # Original line content for reference

Comment on lines 13558 to 13561


@pytest.mark.gfm
@pytest.mark.skip
def test_extra_046f0():
Copy link
Contributor

Choose a reason for hiding this comment

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

question (testing): Test case test_extra_046f0 has been re-enabled

The test case was previously skipped due to an issue. Now that it's enabled, please verify that the issue has been resolved and the test passes as expected.

Comment on lines +1747 to 1748
pluginRuleTest( # test_extra_046u0 test_extra_046u1
"bad_fenced_block_in_list_in_block_quote_in_block_quote_with_previous_list",
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Reference to GitHub issue removed from test comment

The GitHub issue reference has been removed. Please ensure that the issue has been resolved and add a brief comment explaining the purpose of this test case.

Suggested change
pluginRuleTest( # test_extra_046u0 test_extra_046u1
"bad_fenced_block_in_list_in_block_quote_in_block_quote_with_previous_list",
pluginRuleTest(
"bad_fenced_block_in_list_in_block_quote_in_block_quote_with_previous_list",

Comment on lines +17 to +18
- [Issue 1176](https://github.com/jackdewinter/pymarkdown/issues/1176)
- fixed issue with extra leading space item being added
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (documentation): Consider consistent formatting for all changelog entries

The last item has an indented sub-point, which is inconsistent with the other entries. For better readability and consistency, you might want to either add sub-points to all entries or incorporate this information into the main bullet point.

Suggested change
- [Issue 1176](https://github.com/jackdewinter/pymarkdown/issues/1176)
- fixed issue with extra leading space item being added
[Issue 1176](https://github.com/jackdewinter/pymarkdown/issues/1176): Fixed issue with extra leading space item being added

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.92%. Comparing base (f93643d) to head (ae08e31).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1194   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files         190      190           
  Lines       20668    20715   +47     
  Branches     2637     2643    +6     
=======================================
+ Hits        20653    20700   +47     
  Misses         10       10           
  Partials        5        5           

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

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.

1 participant