jackdewinter / pymarkdown

MIT License
75 stars 17 forks source link

https://github.com/jackdewinter/pymarkdown/issues/1209 #1216

Closed jackdewinter closed 1 month ago

jackdewinter commented 1 month ago

closes #1209

Summary by Sourcery

Refactor the handling of leading spaces in markdown containers by introducing a new utility class LeadingSpaceIndexTracker. Simplify the logic in markdown rule plugins by removing redundant code and consolidating methods. Update tests to reflect these changes and ensure comprehensive coverage. Document the changes in the changelog.

Enhancements:

Documentation:

Tests:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request implements changes to improve the handling of block quotes and lists in the pymarkdown project. The main focus is on refactoring the code to use a new LeadingSpaceIndexTracker class, which centralizes the logic for tracking container nesting and leading spaces. This change aims to fix issues related to MD027 and MD031 rules, particularly in complex nested structures.

Sequence Diagram

sequenceDiagram
    participant C as Client Code
    participant T as LeadingSpaceIndexTracker
    participant R as Rule (MD027/MD031)
    C->>T: open_container(token)
    C->>T: register_container_end(token)
    C->>T: process_container_end(token)
    T->>R: Update container information
    R->>C: Apply rule based on updated container state

File-Level Changes

Change Details Files
Introduced LeadingSpaceIndexTracker class
  • Created new class to manage container nesting and leading spaces
  • Implemented methods for opening and closing containers
  • Added functionality to track and process container ends
  • Included helper methods for accessing container stack information
pymarkdown/plugins/utils/leading_space_index_tracker.py
Refactored MD031 rule implementation
  • Replaced container tracking logic with LeadingSpaceIndexTracker
  • Updated methods to use new tracker for container operations
  • Simplified code by removing redundant container management
  • Adjusted fix_spacing methods to work with the new tracker
pymarkdown/plugins/rule_md_031.py
Updated MD027 rule to use LeadingSpaceIndexTracker
  • Integrated LeadingSpaceIndexTracker into MD027 rule
  • Modified container handling in next_token method
  • Updated blank line handling to use new tracker methods
pymarkdown/plugins/rule_md_027.py
Adjusted block quote processing
  • Modified __handle_existing_block_quote_fenced_special_part_two method
  • Uncommented and adjusted code for handling character after block quote
pymarkdown/block_quotes/block_quote_processor.py
Updated tests and documentation
  • Added new tests for MD027 and MD031 rules
  • Updated existing tests to accommodate new changes
  • Removed debug flags and skipped tests
  • Updated changelog with new issue fix and changes
test/rules/test_md031.py
test/rules/test_md027.py
newdocs/src/changelog.md

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. #### 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 100.00%. Comparing base (e5fd5af) to head (68c539c). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1216 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 190 191 +1 Lines 20941 20983 +42 Branches 2679 2678 -1 ========================================= + Hits 20941 20983 +42 ```

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