jackdewinter / pymarkdown

MIT License
75 stars 17 forks source link

Fixing Md031 issues with fixes and deeply nested containers. #1225

Closed jackdewinter closed 1 month ago

jackdewinter commented 1 month ago

closes #1166 closes #1167 closes #1168

Summary by Sourcery

Fix MD031 rule issues by improving handling of fenced code blocks in nested containers, enhance list and block quote spacing logic, and update documentation and tests accordingly.

Bug Fixes:

Enhancements:

Documentation:

Tests:

Chores:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request addresses several issues related to the MD031 rule (blanks around fences) in the PyMarkdown project. The changes include fixes for handling deeply nested containers, improvements in list and block quote processing, and updates to test cases. Additionally, there are minor changes to API documentation and some refactoring.

Updated class diagram for rule_md_031.py

classDiagram
    class RuleMd031 {
        - List<List<PendingContainerAdjustment>> __container_adjustments
        - int __fix_count
        - Optional<MarkdownToken> __removed_container_stack_token
        - Optional<List<PendingContainerAdjustment>> __removed_container_adjustments
        - LeadingSpaceIndexTracker __leading_space_index_tracker
        + starting_new_file() void
        + __fix_spacing_special_case(PluginScanContext, MarkdownToken) void
        + __fix_spacing_block_quote(MarkdownToken) void
        + __fix_spacing_list_special(PluginScanContext, int, int) void
        + __fix_spacing_list_detect_special(MarkdownToken) Tuple<bool, int, int>
        + __fix_spacing_list(PluginScanContext, MarkdownToken) bool
        + __fix_spacing_list_remove_list(PluginScanContext) void
        + __fix_spacing(PluginScanContext, MarkdownToken, bool) void
        + __process_pending_container_end_adjustment(PluginScanContext, MarkdownToken) void
        + __process_pending_container_end_tokens(PluginScanContext, MarkdownToken) void
        + __calculate_special_case(PluginScanContext, MarkdownToken) void
        + next_token(PluginScanContext, MarkdownToken) void
    }

Updated class diagram for PyMarkdownApi

classDiagram
    class PyMarkdownApi {
        - bool __inherit_logging
        - int __log_level
        - bool __enable_stack_trace
        + PyMarkdownApi(bool inherit_logging)
        + application_version() str
        + interface_version() int
        + enable_stack_trace() PyMarkdownApi
        + log_debug_and_above() PyMarkdownApi
        + log_info_and_above() PyMarkdownApi
        + log_warning_and_above() PyMarkdownApi
        + log_error_and_above() PyMarkdownApi
        + log_critical_and_above() PyMarkdownApi
        + log(str log_level) PyMarkdownApi
        + log_to_file(str log_file_path) PyMarkdownApi
    }

File-Level Changes

Change Details Files
Improved handling of deeply nested containers for MD031 rule
  • Added new methods to handle special cases in nested lists and block quotes
  • Implemented fixes for fenced code blocks in deeply nested structures
  • Updated logic for calculating adjustments in nested containers
pymarkdown/plugins/rule_md031.py
Updated and added test cases for MD031 rule
  • Added new test cases for fenced blocks in nested lists and block quotes
  • Updated existing test cases to reflect new behavior
  • Removed temporary fix disabling and debugging flags
test/rules/test_md031.py
test/test_markdown_extra.py
Improved API documentation and minor refactoring
  • Added detailed docstrings to PyMarkdownApi methods
  • Updated logging-related methods with exception information
  • Refactored some debugging print statements
pymarkdown/api.py
pymarkdown/file_scan_helper.py
Updated project metadata and documentation
  • Updated coverage and test result statistics
  • Modified changelog to clarify issue fix description
  • Skipped a recursive directory scan test
publish/coverage.json
publish/test-results.json
newdocs/src/changelog.md
test/api/test_api_scan.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.99%. Comparing base (c689274) to head (29fc3dd). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1225 +/- ## =========================================== - Coverage 100.00% 99.99% -0.01% =========================================== Files 191 191 Lines 20985 21048 +63 Branches 2679 2687 +8 =========================================== + Hits 20985 21046 +61 - Misses 0 1 +1 - Partials 0 1 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.