Skip to content

Conversation

@jackdewinter
Copy link
Owner

@jackdewinter jackdewinter commented Jul 7, 2024

Summary by Sourcery

This pull request refactors the handling of block quotes and lists to better manage blank lines and leading spaces, adds new test cases to cover these scenarios, updates documentation, and adjusts test results and coverage reports accordingly.

  • Enhancements:
    • Refactored block quote handling to improve the processing of blank lines and leading spaces.
    • Enhanced the logic for adjusting leading spaces in block quotes and lists to handle more complex nesting scenarios.
  • Documentation:
    • Updated changelog to include details about the fix for issue 1130 and the addition of fix mode for MD031.
  • Tests:
    • Added multiple new test cases for nested block quotes and lists to ensure correct handling of blank lines and leading spaces.
    • Marked several test cases as skipped to focus on specific scenarios related to issue 1130.
  • Chores:
    • Updated test results and coverage reports to reflect the new and modified test cases.
    • Adjusted pylint suppression configuration to account for additional arguments and local variables in refactored methods.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 7, 2024

Reviewer's Guide by Sourcery

This pull request addresses issue #1130 by adding new test cases and making adjustments to the handling of block quotes and lists in the pymarkdown project. The changes include adding new test functions, modifying existing test functions, and updating the logic in the block_quote_non_fenced_helper.py and transform_containers.py files to handle specific edge cases more effectively.

File-Level Changes

Files Changes
test/test_markdown_extra.py
test/nested_three/test_markdown_nested_three_unordered_block_ordered.py
test/rules/test_md031.py
Added new test cases and modified existing ones to cover additional edge cases for block quotes and lists.
pymarkdown/block_quotes/block_quote_non_fenced_helper.py
pymarkdown/transform_markdown/transform_containers.py
Updated logic to handle blank lines and container prefixes more effectively in block quotes and lists.
publish/test-results.json
publish/coverage.json
publish/pylint_suppression.json
Updated test results, coverage metrics, and pylint suppression counts to reflect the changes in the codebase.

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 and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 9 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.

found_bq_stack_token = cast(
BlockQuoteStackToken, parser_state.token_stack[stack_index]
)
is_not_blank_line = bool(line_to_parse.strip(Constants.ascii_whitespace))
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 renaming is_not_blank_line for clarity.

The variable name is_not_blank_line could be more descriptive. Consider renaming it to something like has_content or line_has_content to better convey its purpose.

Suggested change
is_not_blank_line = bool(line_to_parse.strip(Constants.ascii_whitespace))
line_has_content = bool(line_to_parse.strip(Constants.ascii_whitespace))

extra_consumed_whitespace,
container_level_tokens,
original_line,
is_not_blank_line,
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Check if is_not_blank_line is necessary as a parameter.

Since is_not_blank_line is derived from line_to_parse, consider whether it is necessary to pass it as a parameter to __do_block_quote_leading_spaces_adjustments. It might be more efficient to compute it within the method itself.

)

@staticmethod
def __look_for_container_prefix(
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): New method __look_for_container_prefix.

The new method __look_for_container_prefix appears to be added for checking container prefixes. Ensure that this method is thoroughly tested for all edge cases, especially with different types of list and block quote combinations.

Suggested change
def __look_for_container_prefix(
@staticmethod
def __look_for_container_prefix(
token_stack: List[MarkdownToken], container_line: str
) -> bool:
# Add thorough unit tests to cover edge cases
# Test with different types of list and block quote combinations
pass



@pytest.mark.gfm
def test_extra_044ca():
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): Missing edge case for empty block quote

Consider adding a test case where the block quote is empty or contains only whitespace. This will ensure that the parser handles such cases correctly.

Suggested change
def test_extra_044ca():
@pytest.mark.gfm
def test_extra_044ca():
"""
Test for empty block quote
"""
input_text = "> "
expected_output = "<blockquote>\n</blockquote>"
assert parse_markdown(input_text) == expected_output



@pytest.mark.gfm
def test_extra_044fxa():
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): Test case lacks description

Please provide a meaningful description for the test case. This will help future maintainers understand the purpose of the test.

Suggested change
def test_extra_044fxa():
@pytest.mark.gfm
def test_extra_044fxa():
"""
Test case for verifying the handling of extra markdown features.
"""

> > > --------
""",
scan_expected_return_code=1,
scan_expected_output="""{temp_source_path}:2:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
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): Consider adding more edge cases

It would be beneficial to add more edge cases, such as when the fenced code block is at the start or end of the document, to ensure comprehensive coverage.

Suggested change
scan_expected_output="""{temp_source_path}:2:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
scan_expected_output="""{temp_source_path}:1:1: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
{temp_source_path}:2:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
{temp_source_path}:3:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
{temp_source_path}:4:1: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
"""



@pytest.mark.gfm
def test_nested_three_ordered_nl_block_skip_nl_block_skip_1():
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): Test case lacks description

Please provide a meaningful description for the test case. This will help future maintainers understand the purpose of the test.

Suggested change
def test_nested_three_ordered_nl_block_skip_nl_block_skip_1():
def test_nested_three_ordered_nl_block_skip_nl_block_skip_1():
"""
Test nested structure with ordered list and block quotes.
Ensures correct parsing and rendering of nested elements.
"""



@pytest.mark.gfm
def test_nested_three_ordered_nl_block_skip_nl_block_skip_2():
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): Test case lacks description

Please provide a meaningful description for the test case. This will help future maintainers understand the purpose of the test.

Suggested change
def test_nested_three_ordered_nl_block_skip_nl_block_skip_2():
def test_nested_three_ordered_nl_block_skip_nl_block_skip_2():
"""
Test nested structure with ordered list and block quotes.
Ensures correct parsing and rendering of nested elements.
"""



@pytest.mark.gfm
@pytest.mark.skip
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): Skipped test case

Please provide a reason for skipping this test case. If it's a known issue, consider linking to the relevant issue tracker.

Comment on lines +31 to +32
- check for adding extra line to list with blank line in *-List-Bq
not flexible enough
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): Rephrase for clarity

Consider rephrasing to 'The check for adding an extra line to a list with a blank line in *-List-Bq is not flexible enough.'

Suggested change
- check for adding extra line to list with blank line in *-List-Bq
not flexible enough
- The check for adding an extra line to a list with a blank line in *-List-Bq
is not flexible enough

@codecov
Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8a8fb01) to head (b8b56a2).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1131   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          190       190           
  Lines        19960     19986   +26     
  Branches      2511      2517    +6     
=========================================
+ Hits         19960     19986   +26     

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

@jackdewinter jackdewinter merged commit 5d2b0c8 into main Jul 8, 2024
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.

2 participants